2007-04-13 07:33:24 +00:00
// $Id$
2009-02-18 13:46:55 +00:00
( function ( $ ) {
2007-04-13 07:33:24 +00:00
2007-02-13 07:41:51 +00:00
/ * *
* Internal function to check using Ajax if clean URLs can be enabled on the
* settings page .
*
* This function is not used to verify whether or not clean URLs
* are currently enabled .
* /
2008-10-29 10:01:28 +00:00
Drupal . behaviors . cleanURLsSettingsCheck = {
2009-03-13 23:15:09 +00:00
attach : function ( context , settings ) {
2008-10-29 10:01:28 +00:00
// This behavior attaches by ID, so is only valid once on a page.
// Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle
// the processing.
2009-04-04 00:35:46 +00:00
if ( $ ( ".clean-url-processed, #edit-clean-url.install" ) . size ( ) ) {
2008-10-29 10:01:28 +00:00
return ;
2007-02-13 07:41:51 +00:00
}
2009-03-13 23:15:09 +00:00
var url = settings . basePath + "admin/settings/clean-urls/check" ;
2008-10-29 10:01:28 +00:00
$ ( "#clean-url .description span" ) . html ( '<div id="testing">' + Drupal . t ( 'Testing clean URLs...' ) + "</div>" ) ;
$ ( "#clean-url p" ) . hide ( ) ;
$ . ajax ( {
url : location . protocol + "//" + location . host + url ,
dataType : 'json' ,
success : function ( ) {
// Check was successful.
$ ( "#clean-url input.form-radio" ) . attr ( "disabled" , false ) ;
$ ( "#clean-url .description span" ) . append ( '<div class="ok">' + Drupal . t ( 'Your server has been successfully tested to support this feature.' ) + "</div>" ) ;
$ ( "#testing" ) . hide ( ) ;
} ,
error : function ( ) {
// Check failed.
$ ( "#clean-url .description span" ) . append ( '<div class="warning">' + Drupal . t ( 'Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.' ) + "</div>" ) ;
$ ( "#testing" ) . hide ( ) ;
}
} ) ;
$ ( "#clean-url" ) . addClass ( 'clean-url-processed' ) ;
}
2007-06-01 09:05:45 +00:00
} ;
2007-05-10 19:55:24 +00:00
/ * *
* Internal function to check using Ajax if clean URLs can be enabled on the
* install page .
*
* This function is not used to verify whether or not clean URLs
* are currently enabled .
* /
Drupal . cleanURLsInstallCheck = function ( ) {
2007-12-17 23:43:43 +00:00
var url = location . protocol + "//" + location . host + Drupal . settings . basePath + "admin/settings/clean-urls/check" ;
2008-11-20 06:56:17 +00:00
// Submit a synchronous request to avoid database errors associated with
// concurrent requests during install.
2007-10-27 11:32:05 +00:00
$ . ajax ( {
2008-11-20 06:56:17 +00:00
async : false ,
2007-10-27 11:32:05 +00:00
url : url ,
dataType : 'json' ,
success : function ( ) {
2007-05-10 19:55:24 +00:00
// Check was successful.
2009-04-04 00:35:46 +00:00
$ ( "#edit-clean-url" ) . attr ( "value" , 1 ) ;
2007-10-27 11:32:05 +00:00
} ,
} ) ;
2009-04-04 00:35:46 +00:00
$ ( "#edit-clean-url" ) . addClass ( 'clean-url-processed' ) ;
2007-06-01 09:05:45 +00:00
} ;
2007-05-10 19:55:24 +00:00
2007-10-22 15:48:26 +00:00
/ * *
* When a field is filled out , apply its value to other fields that will likely
* use the same value . In the installer this is used to populate the
* administrator e - mail address with the same value as the site e - mail address .
* /
2008-10-29 10:01:28 +00:00
Drupal . behaviors . copyFieldValue = {
2009-03-13 23:15:09 +00:00
attach : function ( context , settings ) {
for ( var sourceId in settings . copyFieldValue ) {
2008-10-29 10:01:28 +00:00
// Get the list of target fields.
2009-03-13 23:15:09 +00:00
targetIds = settings . copyFieldValue [ sourceId ] ;
2009-02-18 13:46:55 +00:00
if ( ! $ ( '#' + sourceId + '.copy-field-values-processed' , context ) . size ( ) ) {
2008-10-29 10:01:28 +00:00
// Add the behavior to update target fields on blur of the primary field.
sourceField = $ ( '#' + sourceId ) ;
sourceField . bind ( 'blur' , function ( ) {
for ( var delta in targetIds ) {
var targetField = $ ( '#' + targetIds [ delta ] ) ;
if ( targetField . val ( ) == '' ) {
targetField . val ( this . value ) ;
}
2007-10-22 15:48:26 +00:00
}
2008-10-29 10:01:28 +00:00
} ) ;
sourceField . addClass ( 'copy-field-values-processed' ) ;
}
2007-10-22 15:48:26 +00:00
}
}
2007-12-17 23:43:43 +00:00
} ;
2007-10-22 15:48:26 +00:00
2007-05-14 16:22:26 +00:00
/ * *
2009-03-17 15:26:29 +00:00
* Show / hide custom format sections on the regional settings page .
2007-05-14 16:22:26 +00:00
* /
2008-10-29 10:01:28 +00:00
Drupal . behaviors . dateTime = {
2009-03-13 23:15:09 +00:00
attach : function ( context , settings ) {
2008-10-29 10:01:28 +00:00
// Show/hide custom format depending on the select's value.
$ ( 'select.date-format:not(.date-time-processed)' , context ) . change ( function ( ) {
$ ( this ) . addClass ( 'date-time-processed' ) . parents ( "div.date-container" ) . children ( "div.custom-container" ) [ $ ( this ) . val ( ) == "custom" ? "show" : "hide" ] ( ) ;
} ) ;
2007-05-14 16:22:26 +00:00
2008-10-29 10:01:28 +00:00
// Attach keyup handler to custom format inputs.
$ ( 'input.custom-format:not(.date-time-processed)' , context ) . addClass ( 'date-time-processed' ) . keyup ( function ( ) {
var input = $ ( this ) ;
2009-03-13 23:15:09 +00:00
var url = settings . dateTime . lookup + ( settings . dateTime . lookup . match ( /\?q=/ ) ? "&format=" : "?format=" ) + Drupal . encodeURIComponent ( input . val ( ) ) ;
2008-10-29 10:01:28 +00:00
$ . getJSON ( url , function ( data ) {
$ ( "div.description span" , input . parent ( ) ) . html ( data ) ;
} ) ;
2007-05-14 16:22:26 +00:00
} ) ;
2008-10-29 10:01:28 +00:00
// Trigger the event handler to show the form input if necessary.
$ ( 'select.date-format' , context ) . trigger ( 'change' ) ;
}
2007-07-25 17:35:47 +00:00
} ;
2008-11-22 11:54:40 +00:00
/ * *
* Show the powered by Drupal image preview
* /
Drupal . behaviors . poweredByPreview = {
2009-03-13 23:15:09 +00:00
attach : function ( context , settings ) {
2008-11-22 11:54:40 +00:00
$ ( '#edit-color, #edit-size' ) . change ( function ( ) {
2009-03-13 23:15:09 +00:00
var path = settings . basePath + 'misc/' + $ ( '#edit-color' ) . val ( ) + '-' + $ ( '#edit-size' ) . val ( ) + '.png' ;
2008-11-22 11:54:40 +00:00
$ ( 'img.powered-by-preview' ) . attr ( 'src' , path ) ;
} ) ;
}
2009-02-18 13:46:55 +00:00
} ;
2009-04-04 00:35:46 +00:00
} ) ( jQuery ) ;