| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* $Id: filefield_sources.js,v 1.5 2010/08/11 00:19:20 quicksketch Exp $ */ 2 3 Drupal.behaviors.fileFieldSources = function(context) { 4 $('div.filefield-sources-list a', context).click(function() { 5 $fileFieldElement = $(this).parents('div.form-item:first').find('div.filefield-element:first'); 6 7 // Remove the active class. 8 $(this).parents('div.filefield-sources-list').find('a.active').removeClass('active'); 9 10 // Find the unique FileField Source class name. 11 var fileFieldSourceClass = this.className.match(/filefield-source-[0-9a-z]+/i)[0]; 12 13 // The default upload element is a special case. 14 if ($(this).is('.filefield-source-upload')) { 15 $fileFieldElement.find('div.filefield-upload').parent().css('display', ''); 16 $fileFieldElement.find('div.filefield-source').css('display', 'none'); 17 } 18 else { 19 $fileFieldElement.find('div.filefield-upload').parent().css('display', 'none'); 20 $fileFieldElement.find('div.filefield-source').not('div.' + fileFieldSourceClass).css('display', 'none'); 21 $fileFieldElement.find('div.' + fileFieldSourceClass).css('display', ''); 22 } 23 24 // Add the active class. 25 $(this).addClass('active'); 26 Drupal.fileFieldSources.updateHintText($fileFieldElement.get(0)); 27 }); 28 29 // Hide all the other upload mechanisms on page load. 30 $('div.filefield-source', context).css('display', 'none'); 31 $('div.filefield-sources-list', context).each(function() { 32 $(this).find('a:first').addClass('active'); 33 }); 34 $('form#node-form', context).submit(function() { 35 Drupal.fileFieldSources.removeHintText(); 36 }); 37 }; 38 39 /** 40 * Helper functions used by FileField Sources. 41 */ 42 Drupal.fileFieldSources = { 43 /** 44 * Update the hint text when clicking between source types. 45 */ 46 updateHintText: function(fileFieldElement) { 47 // Add default value hint text to text fields. 48 $(fileFieldElement).find('div.filefield-source').each(function() { 49 var matches = this.className.match(/filefield-source-([a-z]+)/); 50 var sourceType = matches[1]; 51 var defaultText = ''; 52 var textfield = $(this).find('input.form-text:first').get(0); 53 var defaultText = (Drupal.settings.fileFieldSources && Drupal.settings.fileFieldSources[sourceType]) ? Drupal.settings.fileFieldSources[sourceType].hintText : ''; 54 55 // If the field doesn't exist, just return. 56 if (!textfield) { 57 return; 58 } 59 60 // If this field is not shown, remove its value and be done. 61 if (!$(this).is(':visible') && textfield.value == defaultText) { 62 textfield.value = ''; 63 return; 64 } 65 66 // Set a default value: 67 if (textfield.value == '') { 68 textfield.value = defaultText; 69 } 70 71 // Set a default class. 72 if (textfield.value == defaultText) { 73 $(textfield).addClass('hint'); 74 } 75 76 $(textfield).click(hideHintText); 77 $(textfield).blur(showHintText); 78 79 function showHintText() { 80 if (this.value == '') { 81 this.value = defaultText; 82 $(this).addClass('hint'); 83 } 84 } 85 86 function hideHintText() { 87 if (this.value == defaultText) { 88 this.value = ''; 89 $(this).removeClass('hint'); 90 } 91 } 92 }); 93 }, 94 95 /** 96 * Delete all hint text from a form before submit. 97 */ 98 removeHintText: function() { 99 $('div.filefield-element input.hint').val('').removeClass('hint'); 100 } 101 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |