diff options
Diffstat (limited to 'misc')
-rw-r--r-- | misc/ahah.js | 24 | ||||
-rw-r--r-- | misc/autocomplete.js | 28 | ||||
-rw-r--r-- | misc/batch.js | 60 | ||||
-rw-r--r-- | misc/collapse.js | 48 | ||||
-rw-r--r-- | misc/drupal.js | 44 | ||||
-rw-r--r-- | misc/form.js | 16 | ||||
-rw-r--r-- | misc/tabledrag.js | 24 | ||||
-rw-r--r-- | misc/tableheader.js | 180 | ||||
-rw-r--r-- | misc/tableselect.js | 6 | ||||
-rw-r--r-- | misc/teaser.js | 156 | ||||
-rw-r--r-- | misc/textarea.js | 58 |
11 files changed, 350 insertions, 294 deletions
diff --git a/misc/ahah.js b/misc/ahah.js index a098addb9..ca5580a46 100644 --- a/misc/ahah.js +++ b/misc/ahah.js @@ -15,17 +15,19 @@ /** * Attaches the ahah behavior to each ahah form element. */ -Drupal.behaviors.ahah = function(context) { - for (var base in Drupal.settings.ahah) { - if (!$('#'+ base + '.ahah-processed').size()) { - var element_settings = Drupal.settings.ahah[base]; - - $(element_settings.selector).each(function() { - element_settings.element = this; - var ahah = new Drupal.ahah(base, element_settings); - }); - - $('#'+ base).addClass('ahah-processed'); +Drupal.behaviors.ahah = { + attach: function(context) { + for (var base in Drupal.settings.ahah) { + if (!$('#'+ base + '.ahah-processed').size()) { + var element_settings = Drupal.settings.ahah[base]; + + $(element_settings.selector).each(function() { + element_settings.element = this; + var ahah = new Drupal.ahah(base, element_settings); + }); + + $('#'+ base).addClass('ahah-processed'); + } } } }; diff --git a/misc/autocomplete.js b/misc/autocomplete.js index 6efcf1e26..da76380c4 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -3,19 +3,21 @@ /** * Attaches the autocomplete behavior to all required fields. */ -Drupal.behaviors.autocomplete = function (context) { - var acdb = []; - $('input.autocomplete:not(.autocomplete-processed)', context).each(function () { - var uri = this.value; - if (!acdb[uri]) { - acdb[uri] = new Drupal.ACDB(uri); - } - var input = $('#' + this.id.substr(0, this.id.length - 13)) - .attr('autocomplete', 'OFF')[0]; - $(input.form).submit(Drupal.autocompleteSubmit); - new Drupal.jsAC(input, acdb[uri]); - $(this).addClass('autocomplete-processed'); - }); +Drupal.behaviors.autocomplete = { + attach: function(context) { + var acdb = []; + $('input.autocomplete:not(.autocomplete-processed)', context).each(function () { + var uri = this.value; + if (!acdb[uri]) { + acdb[uri] = new Drupal.ACDB(uri); + } + var input = $('#' + this.id.substr(0, this.id.length - 13)) + .attr('autocomplete', 'OFF')[0]; + $(input.form).submit(Drupal.autocompleteSubmit); + new Drupal.jsAC(input, acdb[uri]); + $(this).addClass('autocomplete-processed'); + }); + } }; /** diff --git a/misc/batch.js b/misc/batch.js index 5a5587ad8..4d1a4d551 100644 --- a/misc/batch.js +++ b/misc/batch.js @@ -3,36 +3,38 @@ /** * Attaches the batch behavior to progress bars. */ -Drupal.behaviors.batch = function (context) { - // This behavior attaches by ID, so is only valid once on a page. - if ($('#progress.batch-processed').size()) { - return; - } - $('#progress', context).addClass('batch-processed').each(function () { - var holder = this; - var uri = Drupal.settings.batch.uri; - var initMessage = Drupal.settings.batch.initMessage; - var errorMessage = Drupal.settings.batch.errorMessage; +Drupal.behaviors.batch = { + attach: function(context) { + // This behavior attaches by ID, so is only valid once on a page. + if ($('#progress.batch-processed').size()) { + return; + } + $('#progress', context).addClass('batch-processed').each(function () { + var holder = this; + var uri = Drupal.settings.batch.uri; + var initMessage = Drupal.settings.batch.initMessage; + var errorMessage = Drupal.settings.batch.errorMessage; - // Success: redirect to the summary. - var updateCallback = function (progress, status, pb) { - if (progress == 100) { - pb.stopMonitoring(); - window.location = uri+'&op=finished'; - } - }; + // Success: redirect to the summary. + var updateCallback = function (progress, status, pb) { + if (progress == 100) { + pb.stopMonitoring(); + window.location = uri+'&op=finished'; + } + }; - var errorCallback = function (pb) { - var div = document.createElement('p'); - div.className = 'error'; - $(div).html(errorMessage); - $(holder).prepend(div); - $('#wait').hide(); - }; + var errorCallback = function (pb) { + var div = document.createElement('p'); + div.className = 'error'; + $(div).html(errorMessage); + $(holder).prepend(div); + $('#wait').hide(); + }; - var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback); - progress.setProgress(-1, initMessage); - $(holder).append(progress.element); - progress.startMonitoring(uri+'&op=do', 10); - }); + var progress = new Drupal.progressBar('updateprogress', updateCallback, "POST", errorCallback); + progress.setProgress(-1, initMessage); + $(holder).append(progress.element); + progress.startMonitoring(uri+'&op=do', 10); + }); + } }; diff --git a/misc/collapse.js b/misc/collapse.js index 5628c4b9a..4626b4519 100644 --- a/misc/collapse.js +++ b/misc/collapse.js @@ -50,28 +50,30 @@ Drupal.collapseScrollIntoView = function (node) { } }; -Drupal.behaviors.collapse = function (context) { - $('fieldset.collapsible > legend:not(.collapse-processed)', context).each(function() { - var fieldset = $(this.parentNode); - // Expand if there are errors inside - if ($('input.error, textarea.error, select.error', fieldset).size() > 0) { - fieldset.removeClass('collapsed'); - } +Drupal.behaviors.collapse = { + attach: function(context) { + $('fieldset.collapsible > legend:not(.collapse-processed)', context).each(function() { + var fieldset = $(this.parentNode); + // Expand if there are errors inside + if ($('input.error, textarea.error, select.error', fieldset).size() > 0) { + fieldset.removeClass('collapsed'); + } - // Turn the legend into a clickable link and wrap the contents of the fieldset - // in a div for easier animation - var text = this.innerHTML; - $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() { - var fieldset = $(this).parents('fieldset:first')[0]; - // Don't animate multiple times - if (!fieldset.animating) { - fieldset.animating = true; - Drupal.toggleFieldset(fieldset); - } - return false; - })) - .after($('<div class="fieldset-wrapper"></div>') - .append(fieldset.children(':not(legend):not(.action)'))) - .addClass('collapse-processed'); - }); + // Turn the legend into a clickable link and wrap the contents of the fieldset + // in a div for easier animation + var text = this.innerHTML; + $(this).empty().append($('<a href="#">'+ text +'</a>').click(function() { + var fieldset = $(this).parents('fieldset:first')[0]; + // Don't animate multiple times + if (!fieldset.animating) { + fieldset.animating = true; + Drupal.toggleFieldset(fieldset); + } + return false; + })) + .after($('<div class="fieldset-wrapper"></div>') + .append(fieldset.children(':not(legend):not(.action)'))) + .addClass('collapse-processed'); + }); + } }; diff --git a/misc/drupal.js b/misc/drupal.js index 4cb99bd99..157a20fea 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -12,10 +12,15 @@ Drupal.jsEnabled = document.getElementsByTagName && document.createElement && do * * Behaviors are event-triggered actions that attach to page elements, enhancing * default non-Javascript UIs. Behaviors are registered in the Drupal.behaviors - * object as follows: + * object using the method 'attach' and optionally also 'detach' as follows: * @code - * Drupal.behaviors.behaviorName = function () { - * ... + * Drupal.behaviors.behaviorName = { + * attach: function(context) { + * ... + * }, + * detach: function(context) { + * ... + * } * }; * @endcode * @@ -38,7 +43,38 @@ Drupal.attachBehaviors = function(context) { context = context || document; // Execute all of them. jQuery.each(Drupal.behaviors, function() { - this(context); + if (jQuery.isFunction(this.attach)) { + this.attach(context); + } + }); +}; + +/** + * Detach registered behaviors from a page element. + * + * Developers implementing AHAH/AJAX in their solutions should call this + * function before page content is about to be removed, feeding in an element + * to be processed, in order to allow special behaviors to detach from the + * content. + * + * Such implementations should look for the class name that was added in their + * corresponding Drupal.behaviors.behaviorName.attach implementation, i.e. + * behaviorName-processed, to ensure the behavior is detached only from + * previously processed elements. + * + * @param context + * An element to detach behaviors from. If none is given, the document element + * is used. + * + * @see Drupal.attachBehaviors + */ +Drupal.detachBehaviors = function(context) { + context = context || document; + // Execute all of them. + jQuery.each(Drupal.behaviors, function() { + if (jQuery.isFunction(this.detach)) { + this.detach(context); + } }); }; diff --git a/misc/form.js b/misc/form.js index f5e3e6846..d3a9f692f 100644 --- a/misc/form.js +++ b/misc/form.js @@ -1,10 +1,12 @@ // $Id$ -Drupal.behaviors.multiselectSelector = function() { - // Automatically selects the right radio button in a multiselect control. - $('.multiselect select:not(.multiselectSelector-processed)') - .addClass('multiselectSelector-processed').change(function() { - $('.multiselect input:radio[value="'+ this.id.substr(5) +'"]') - .attr('checked', true); - }); +Drupal.behaviors.multiselectSelector = { + attach: function(context) { + // Automatically selects the right radio button in a multiselect control. + $('.multiselect select:not(.multiselectSelector-processed)', context) + .addClass('multiselectSelector-processed').change(function() { + $('.multiselect input:radio[value="'+ this.id.substr(5) +'"]') + .attr('checked', true); + }); + } }; diff --git a/misc/tabledrag.js b/misc/tabledrag.js index d8c1e6e9a..7d11cd39e 100644 --- a/misc/tabledrag.js +++ b/misc/tabledrag.js @@ -11,18 +11,20 @@ * overriding the .onDrag, .onDrop, .row.onSwap, and .row.onIndent methods. * See blocks.js for an example of adding additional functionality to tableDrag. */ -Drupal.behaviors.tableDrag = function(context) { - for (var base in Drupal.settings.tableDrag) { - if (!$('#' + base + '.tabledrag-processed', context).size()) { - var tableSettings = Drupal.settings.tableDrag[base]; - - $('#' + base).filter(':not(.tabledrag-processed)').each(function() { - // Create the new tableDrag instance. Save in the Drupal variable - // to allow other scripts access to the object. - Drupal.tableDrag[base] = new Drupal.tableDrag(this, tableSettings); - }); +Drupal.behaviors.tableDrag = { + attach: function(context) { + for (var base in Drupal.settings.tableDrag) { + if (!$('#' + base + '.tabledrag-processed', context).size()) { + var tableSettings = Drupal.settings.tableDrag[base]; + + $('#' + base).filter(':not(.tabledrag-processed)').each(function() { + // Create the new tableDrag instance. Save in the Drupal variable + // to allow other scripts access to the object. + Drupal.tableDrag[base] = new Drupal.tableDrag(this, tableSettings); + }); - $('#' + base).addClass('tabledrag-processed'); + $('#' + base).addClass('tabledrag-processed'); + } } } }; diff --git a/misc/tableheader.js b/misc/tableheader.js index 3127464d8..9fa58ce5d 100644 --- a/misc/tableheader.js +++ b/misc/tableheader.js @@ -6,108 +6,110 @@ Drupal.tableHeaderDoScroll = function() { } }; -Drupal.behaviors.tableHeader = function (context) { - // This breaks in anything less than IE 7. Prevent it from running. - if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) { - return; - } +Drupal.behaviors.tableHeader = { + attach: function(context) { + // This breaks in anything less than IE 7. Prevent it from running. + if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7) { + return; + } - // Keep track of all cloned table headers. - var headers = []; + // Keep track of all cloned table headers. + var headers = []; - $('table.sticky-enabled thead:not(.tableHeader-processed)', context).each(function () { - // Clone thead so it inherits original jQuery properties. - var headerClone = $(this).clone(true).insertBefore(this.parentNode).wrap('<table class="sticky-header"></table>').parent().css({ - position: 'fixed', - top: '0px' - }); + $('table.sticky-enabled thead:not(.tableHeader-processed)', context).each(function () { + // Clone thead so it inherits original jQuery properties. + var headerClone = $(this).clone(true).insertBefore(this.parentNode).wrap('<table class="sticky-header"></table>').parent().css({ + position: 'fixed', + top: '0px' + }); - headerClone = $(headerClone)[0]; - headers.push(headerClone); + headerClone = $(headerClone)[0]; + headers.push(headerClone); - // Store parent table. - var table = $(this).parent('table')[0]; - headerClone.table = table; - // Finish initialzing header positioning. - tracker(headerClone); + // Store parent table. + var table = $(this).parent('table')[0]; + headerClone.table = table; + // Finish initialzing header positioning. + tracker(headerClone); - $(table).addClass('sticky-table'); - $(this).addClass('tableHeader-processed'); - }); + $(table).addClass('sticky-table'); + $(this).addClass('tableHeader-processed'); + }); - // Define the anchor holding var. - var prevAnchor = ''; + // Define the anchor holding var. + var prevAnchor = ''; - // Track positioning and visibility. - function tracker(e) { - // Save positioning data. - var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight; - if (e.viewHeight != viewHeight) { - e.viewHeight = viewHeight; - e.vPosition = $(e.table).offset().top - 4; - e.hPosition = $(e.table).offset().left; - e.vLength = e.table.clientHeight - 100; - // Resize header and its cell widths. - var parentCell = $('th', e.table); - $('th', e).each(function(index) { - var cellWidth = parentCell.eq(index).css('width'); - // Exception for IE7. - if (cellWidth == 'auto') { - cellWidth = parentCell.get(index).clientWidth +'px'; - } - $(this).css('width', cellWidth); - }); - $(e).css('width', $(e.table).css('width')); - } + // Track positioning and visibility. + function tracker(e) { + // Save positioning data. + var viewHeight = document.documentElement.scrollHeight || document.body.scrollHeight; + if (e.viewHeight != viewHeight) { + e.viewHeight = viewHeight; + e.vPosition = $(e.table).offset().top - 4; + e.hPosition = $(e.table).offset().left; + e.vLength = e.table.clientHeight - 100; + // Resize header and its cell widths. + var parentCell = $('th', e.table); + $('th', e).each(function(index) { + var cellWidth = parentCell.eq(index).css('width'); + // Exception for IE7. + if (cellWidth == 'auto') { + cellWidth = parentCell.get(index).clientWidth +'px'; + } + $(this).css('width', cellWidth); + }); + $(e).css('width', $(e.table).css('width')); + } - // Track horizontal positioning relative to the viewport and set visibility. - var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft; - var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition; - var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden'; - $(e).css({left: -hScroll + e.hPosition +'px', visibility: visState}); + // Track horizontal positioning relative to the viewport and set visibility. + var hScroll = document.documentElement.scrollLeft || document.body.scrollLeft; + var vOffset = (document.documentElement.scrollTop || document.body.scrollTop) - e.vPosition; + var visState = (vOffset > 0 && vOffset < e.vLength) ? 'visible' : 'hidden'; + $(e).css({left: -hScroll + e.hPosition +'px', visibility: visState}); - // Check the previous anchor to see if we need to scroll to make room for the header. - // Get the height of the header table and scroll up that amount. - if (prevAnchor != location.hash) { - if (location.hash != '') { - var scrollLocation = $('td' + location.hash).offset().top - $(e).height(); - $('body, html').scrollTop(scrollLocation); + // Check the previous anchor to see if we need to scroll to make room for the header. + // Get the height of the header table and scroll up that amount. + if (prevAnchor != location.hash) { + if (location.hash != '') { + var scrollLocation = $('td' + location.hash).offset().top - $(e).height(); + $('body, html').scrollTop(scrollLocation); + } + prevAnchor = location.hash; } - prevAnchor = location.hash; } - } - - // Only attach to scrollbars once, even if Drupal.attachBehaviors is called - // multiple times. - if (!$('body').hasClass('tableHeader-processed')) { - $('body').addClass('tableHeader-processed'); - $(window).scroll(Drupal.tableHeaderDoScroll); - $(document.documentElement).scroll(Drupal.tableHeaderDoScroll); - } - - // Track scrolling. - Drupal.tableHeaderOnScroll = function() { - $(headers).each(function () { - tracker(this); - }); - }; - // Track resizing. - var time = null; - var resize = function () { - // Ensure minimum time between adjustments. - if (time) { - return; + // Only attach to scrollbars once, even if Drupal.attachBehaviors is called + // multiple times. + if (!$('body').hasClass('tableHeader-processed')) { + $('body').addClass('tableHeader-processed'); + $(window).scroll(Drupal.tableHeaderDoScroll); + $(document.documentElement).scroll(Drupal.tableHeaderDoScroll); } - time = setTimeout(function () { - $('table.sticky-header').each(function () { - // Force cell width calculation. - this.viewHeight = 0; + + // Track scrolling. + Drupal.tableHeaderOnScroll = function() { + $(headers).each(function () { tracker(this); }); - // Reset timer. - time = null; - }, 250); - }; - $(window).resize(resize); + }; + + // Track resizing. + var time = null; + var resize = function () { + // Ensure minimum time between adjustments. + if (time) { + return; + } + time = setTimeout(function () { + $('table.sticky-header').each(function () { + // Force cell width calculation. + this.viewHeight = 0; + tracker(this); + }); + // Reset timer. + time = null; + }, 250); + }; + $(window).resize(resize); + } }; diff --git a/misc/tableselect.js b/misc/tableselect.js index 65eb7efbc..36a209f3c 100644 --- a/misc/tableselect.js +++ b/misc/tableselect.js @@ -1,7 +1,9 @@ // $Id$ -Drupal.behaviors.tableSelect = function (context) { - $('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect); +Drupal.behaviors.tableSelect = { + attach: function(context) { + $('form table:has(th.select-all):not(.tableSelect-processed)', context).each(Drupal.tableSelect); + } }; Drupal.tableSelect = function() { diff --git a/misc/teaser.js b/misc/teaser.js index 590dad582..e303aa963 100644 --- a/misc/teaser.js +++ b/misc/teaser.js @@ -5,92 +5,94 @@ * * Note: depends on resizable textareas. */ -Drupal.behaviors.teaser = function(context) { - // This breaks in Konqueror. Prevent it from running. - if (/KDE/.test(navigator.vendor)) { - return; - } +Drupal.behaviors.teaser = { + attach: function(context) { + // This breaks in Konqueror. Prevent it from running. + if (/KDE/.test(navigator.vendor)) { + return; + } - $('textarea.teaser:not(.teaser-processed)', context).each(function() { - var teaser = $(this).addClass('teaser-processed'); + $('textarea.teaser:not(.teaser-processed)', context).each(function() { + var teaser = $(this).addClass('teaser-processed'); - // Move teaser textarea before body, and remove its form-item wrapper. - var body = $('#'+ Drupal.settings.teaser[this.id]); - var checkbox = $('#'+ Drupal.settings.teaserCheckbox[this.id]).parent(); - var checked = $(checkbox).children('input').attr('checked') ? true : false; - var parent = teaser[0].parentNode; - $(body).before(teaser); - $(parent).remove(); + // Move teaser textarea before body, and remove its form-item wrapper. + var body = $('#'+ Drupal.settings.teaser[this.id]); + var checkbox = $('#'+ Drupal.settings.teaserCheckbox[this.id]).parent(); + var checked = $(checkbox).children('input').attr('checked') ? true : false; + var parent = teaser[0].parentNode; + $(body).before(teaser); + $(parent).remove(); - function trim(text) { - return text.replace(/^\s+/g, '').replace(/\s+$/g, ''); - } + function trim(text) { + return text.replace(/^\s+/g, '').replace(/\s+$/g, ''); + } - // Join the teaser back to the body. - function join_teaser() { - if (teaser.val()) { - body.val(trim(teaser.val()) +'\r\n\r\n'+ trim(body.val())); + // Join the teaser back to the body. + function join_teaser() { + if (teaser.val()) { + body.val(trim(teaser.val()) +'\r\n\r\n'+ trim(body.val())); + } + // Empty, hide and disable teaser. + teaser[0].value = ''; + $(teaser).attr('disabled', 'disabled'); + $(teaser).parent().slideUp('fast'); + // Change label. + $(this).val(Drupal.t('Split summary at cursor')); + // Hide separate teaser checkbox. + $(checkbox).hide(); + // Force a hidden checkbox to be checked (to ensure that the body is + // correctly processed on form submit when teaser/body are in joined + // state), and remember the current checked status. + checked = $(checkbox).children('input').attr('checked') ? true : false; + $(checkbox).children('input').attr('checked', true); } - // Empty, hide and disable teaser. - teaser[0].value = ''; - $(teaser).attr('disabled', 'disabled'); - $(teaser).parent().slideUp('fast'); - // Change label. - $(this).val(Drupal.t('Split summary at cursor')); - // Hide separate teaser checkbox. - $(checkbox).hide(); - // Force a hidden checkbox to be checked (to ensure that the body is - // correctly processed on form submit when teaser/body are in joined - // state), and remember the current checked status. - checked = $(checkbox).children('input').attr('checked') ? true : false; - $(checkbox).children('input').attr('checked', true); - } - // Split the teaser from the body. - function split_teaser() { - body[0].focus(); - var selection = Drupal.getSelection(body[0]); - var split = selection.start; - var text = body.val(); + // Split the teaser from the body. + function split_teaser() { + body[0].focus(); + var selection = Drupal.getSelection(body[0]); + var split = selection.start; + var text = body.val(); - // Note: using val() fails sometimes. jQuery bug? - teaser[0].value = trim(text.slice(0, split)); - body[0].value = trim(text.slice(split)); - // Reveal and enable teaser. - $(teaser).attr('disabled', ''); - $(teaser).parent().slideDown('fast'); - // Change label. - $(this).val(Drupal.t('Join summary')); - // Show separate teaser checkbox, restore checked value. - $(checkbox).show().children('input').attr('checked', checked); - } + // Note: using val() fails sometimes. jQuery bug? + teaser[0].value = trim(text.slice(0, split)); + body[0].value = trim(text.slice(split)); + // Reveal and enable teaser. + $(teaser).attr('disabled', ''); + $(teaser).parent().slideDown('fast'); + // Change label. + $(this).val(Drupal.t('Join summary')); + // Show separate teaser checkbox, restore checked value. + $(checkbox).show().children('input').attr('checked', checked); + } - // Add split/join button. - var button = $('<div class="teaser-button-wrapper"><input type="button" class="teaser-button" /></div>'); - var include = $('#'+ this.id.substring(0, this.id.length - 2) +'include'); - $(include).parent().parent().before(button); + // Add split/join button. + var button = $('<div class="teaser-button-wrapper"><input type="button" class="teaser-button" /></div>'); + var include = $('#'+ this.id.substring(0, this.id.length - 2) +'include'); + $(include).parent().parent().before(button); - // Extract the teaser from the body, if set. Otherwise, stay in joined mode. - var text = body.val().split('<!--break-->', 2); - if (text.length == 2) { - teaser[0].value = trim(text[0]); - body[0].value = trim(text[1]); - $(teaser).attr('disabled', ''); - $('input', button).val(Drupal.t('Join summary')).toggle(join_teaser, split_teaser); - } - else { - $('input', button).val(Drupal.t('Split summary at cursor')).toggle(split_teaser, join_teaser); - $(checkbox).hide().children('input').attr('checked', true); - } + // Extract the teaser from the body, if set. Otherwise, stay in joined mode. + var text = body.val().split('<!--break-->', 2); + if (text.length == 2) { + teaser[0].value = trim(text[0]); + body[0].value = trim(text[1]); + $(teaser).attr('disabled', ''); + $('input', button).val(Drupal.t('Join summary')).toggle(join_teaser, split_teaser); + } + else { + $('input', button).val(Drupal.t('Split summary at cursor')).toggle(split_teaser, join_teaser); + $(checkbox).hide().children('input').attr('checked', true); + } - // Make sure that textarea.js has done its magic to ensure proper visibility state. - if (Drupal.behaviors.textarea && teaser.is(('.form-textarea:not(.textarea-processed)'))) { - Drupal.behaviors.textarea(teaser.parentNode); - } - // Set initial visibility. - if ($(teaser).is('[@disabled]')) { - $(teaser).parent().hide(); - } + // Make sure that textarea.js has done its magic to ensure proper visibility state. + if (Drupal.behaviors.textarea && teaser.is(('.form-textarea:not(.textarea-processed)'))) { + Drupal.behaviors.textarea.attach(teaser.parentNode); + } + // Set initial visibility. + if ($(teaser).is('[@disabled]')) { + $(teaser).parent().hide(); + } - }); + }); + } }; diff --git a/misc/textarea.js b/misc/textarea.js index 75fb3f520..a1860c6c8 100644 --- a/misc/textarea.js +++ b/misc/textarea.js @@ -1,36 +1,38 @@ // $Id$ -Drupal.behaviors.textarea = function(context) { - $('textarea.resizable:not(.textarea-processed)', context).each(function() { - // Avoid non-processed teasers. - if ($(this).is(('textarea.teaser:not(.teaser-processed)'))) { - return false; - } - var textarea = $(this).addClass('textarea-processed'), staticOffset = null; +Drupal.behaviors.textarea = { + attach: function(context) { + $('textarea.resizable:not(.textarea-processed)', context).each(function() { + // Avoid non-processed teasers. + if ($(this).is(('textarea.teaser:not(.teaser-processed)'))) { + return false; + } + var textarea = $(this).addClass('textarea-processed'), staticOffset = null; - // When wrapping the text area, work around an IE margin bug. See: - // http://jaspan.com/ie-inherited-margin-bug-form-elements-and-haslayout - $(this).wrap('<div class="resizable-textarea"><span></span></div>') - .parent().append($('<div class="grippie"></div>').mousedown(startDrag)); + // When wrapping the text area, work around an IE margin bug. See: + // http://jaspan.com/ie-inherited-margin-bug-form-elements-and-haslayout + $(this).wrap('<div class="resizable-textarea"><span></span></div>') + .parent().append($('<div class="grippie"></div>').mousedown(startDrag)); - var grippie = $('div.grippie', $(this).parent())[0]; - grippie.style.marginRight = (grippie.offsetWidth - $(this)[0].offsetWidth) +'px'; + var grippie = $('div.grippie', $(this).parent())[0]; + grippie.style.marginRight = (grippie.offsetWidth - $(this)[0].offsetWidth) +'px'; - function startDrag(e) { - staticOffset = textarea.height() - e.pageY; - textarea.css('opacity', 0.25); - $(document).mousemove(performDrag).mouseup(endDrag); - return false; - } + function startDrag(e) { + staticOffset = textarea.height() - e.pageY; + textarea.css('opacity', 0.25); + $(document).mousemove(performDrag).mouseup(endDrag); + return false; + } - function performDrag(e) { - textarea.height(Math.max(32, staticOffset + e.pageY) + 'px'); - return false; - } + function performDrag(e) { + textarea.height(Math.max(32, staticOffset + e.pageY) + 'px'); + return false; + } - function endDrag(e) { - $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag); - textarea.css('opacity', 1); - } - }); + function endDrag(e) { + $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag); + textarea.css('opacity', 1); + } + }); + } }; |