| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 2 /** 3 * Auto-attach for teaser behavior. 4 * 5 * Note: depends on resizable textareas. 6 */ 7 Drupal.behaviors.teaser = function(context) { 8 $('textarea.teaser:not(.teaser-processed)', context).each(function() { 9 var teaser = $(this).addClass('teaser-processed'); 10 11 // Move teaser textarea before body, and remove its form-item wrapper. 12 var body = $('#'+ Drupal.settings.teaser[this.id]); 13 var checkbox = $('#'+ Drupal.settings.teaserCheckbox[this.id]).parent(); 14 var checked = $(checkbox).children('input').attr('checked') ? true : false; 15 var parent = teaser[0].parentNode; 16 $(body).before(teaser); 17 $(parent).remove(); 18 19 function trim(text) { 20 return text.replace(/^\s+/g, '').replace(/\s+$/g, ''); 21 } 22 23 // Join the teaser back to the body. 24 function join_teaser() { 25 if (teaser.val()) { 26 body.val(trim(teaser.val()) +'\r\n\r\n'+ trim(body.val())); 27 } 28 // Empty, hide and disable teaser. 29 teaser[0].value = ''; 30 $(teaser).attr('disabled', 'disabled'); 31 $(teaser).parent().slideUp('fast'); 32 // Change label. 33 $(this).val(Drupal.t('Split summary at cursor')); 34 // Hide separate teaser checkbox. 35 $(checkbox).hide(); 36 // Force a hidden checkbox to be checked (to ensure that the body is 37 // correctly processed on form submit when teaser/body are in joined 38 // state), and remember the current checked status. 39 checked = $(checkbox).children('input').attr('checked') ? true : false; 40 $(checkbox).children('input').attr('checked', true); 41 } 42 43 // Split the teaser from the body. 44 function split_teaser() { 45 body[0].focus(); 46 var selection = Drupal.getSelection(body[0]); 47 var split = selection.start; 48 var text = body.val(); 49 50 // Note: using val() fails sometimes. jQuery bug? 51 teaser[0].value = trim(text.slice(0, split)); 52 body[0].value = trim(text.slice(split)); 53 // Reveal and enable teaser 54 $(teaser).attr('disabled', ''); 55 $(teaser).parent().slideDown('fast'); 56 // Change label 57 $(this).val(Drupal.t('Join summary')); 58 // Show separate teaser checkbox, restore checked value. 59 $(checkbox).show().children('input').attr('checked', checked); 60 } 61 62 // Add split/join button. 63 var button = $('<div class="teaser-button-wrapper"><input type="button" class="teaser-button" /></div>'); 64 var include = $('#'+ this.id.substring(0, this.id.length - 2) +'include'); 65 $(include).parent().parent().before(button); 66 67 // Extract the teaser from the body, if set. Otherwise, stay in joined mode. 68 var text = body.val().split('<!--break-->', 2); 69 if (text.length == 2) { 70 teaser[0].value = trim(text[0]); 71 body[0].value = trim(text[1]); 72 $(teaser).attr('disabled', ''); 73 $('input', button).val(Drupal.t('Join summary')).toggle(join_teaser, split_teaser); 74 } 75 else { 76 $('input', button).val(Drupal.t('Split summary at cursor')).toggle(split_teaser, join_teaser); 77 $(checkbox).hide().children('input').attr('checked', true); 78 } 79 80 // Make sure that textarea.js has done its magic to ensure proper visibility state. 81 if (Drupal.behaviors.textarea && teaser.is(('.form-textarea:not(.textarea-processed)'))) { 82 Drupal.behaviors.textarea(teaser.parentNode); 83 } 84 // Set initial visibility 85 if (teaser[0].disabled) { 86 teaser.parent().hide(); 87 } 88 89 }); 90 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |