[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 var CSS, 2 FORMAUTOSUBMITNAME = 'core-formautosubmit', 3 FORMAUTOSUBMIT, 4 INITIALIZED = false; 5 6 // The CSS selectors we use 7 CSS = { 8 AUTOSUBMIT: 'autosubmit' 9 }; 10 11 FORMAUTOSUBMIT = function() { 12 FORMAUTOSUBMIT.superclass.constructor.apply(this, arguments); 13 }; 14 15 Y.extend(FORMAUTOSUBMIT, Y.Base, { 16 17 /* 18 * Initialize the module 19 */ 20 initializer: function() { 21 // Set up local variables 22 var applyto, 23 thisselect; 24 // We only apply the delegation once 25 if (!INITIALIZED) { 26 INITIALIZED = true; 27 applyto = Y.one('body'); 28 29 // We don't listen for change events by default as using the keyboard triggers these too. 30 applyto.delegate('key', this.process_changes, 'press:13', 'select.' + CSS.AUTOSUBMIT, this); 31 applyto.delegate('click', this.process_changes, 'select.' + CSS.AUTOSUBMIT, this); 32 33 if (Y.UA.os === 'macintosh' && Y.UA.webkit) { 34 // Macintosh webkit browsers like change events, but non-macintosh webkit browsers don't. 35 applyto.delegate('change', this.process_changes, 'select.' + CSS.AUTOSUBMIT, this); 36 } 37 if (Y.UA.touchEnabled) { 38 // IOS and Android trigger touch events. 39 applyto.delegate('change', this.process_changes, 'select.' + CSS.AUTOSUBMIT, this); 40 } 41 } 42 43 // Assign this select items 'nothing' value and lastindex (current value) 44 if (this.get('selectid')) { 45 thisselect = Y.one('select#' + this.get('selectid')); 46 if (thisselect) { 47 if (this.get('nothing')) { 48 thisselect.setData('nothing', this.get('nothing')); 49 } 50 thisselect.setData('startindex', thisselect.get('selectedIndex')); 51 } else { 52 Y.log("Warning: A single_select element was renderered, but the output is not displayed on the page."); 53 } 54 } 55 }, 56 57 /* 58 * Check whether the select element was changed 59 */ 60 check_changed: function(e) { 61 var select, 62 nothing, 63 startindex, 64 currentindex, 65 previousindex; 66 select = e.target.ancestor('select.' + CSS.AUTOSUBMIT, true); 67 if (!select) { 68 return false; 69 } 70 71 nothing = select.getData('nothing'); 72 startindex = select.getData('startindex'); 73 currentindex = select.get('selectedIndex'); 74 75 previousindex = parseInt(select.getData('previousindex'), 10); 76 select.setData('previousindex', currentindex); 77 if (!previousindex) { 78 previousindex = startindex; 79 } 80 81 // Check whether the field has changed, and is not the 'nothing' value 82 if ((nothing === false || select.get('value') !== nothing) 83 && startindex !== select.get('selectedIndex') && currentindex !== previousindex) { 84 return select; 85 } 86 return false; 87 }, 88 89 /* 90 * Process any changes 91 */ 92 process_changes: function(e) { 93 var select = this.check_changed(e), 94 form; 95 if (select) { 96 form = select.ancestor('form', true); 97 form.submit(); 98 } 99 } 100 }, 101 { 102 NAME: FORMAUTOSUBMITNAME, 103 ATTRS: { 104 selectid: { 105 'value': '' 106 }, 107 nothing: { 108 'value': '' 109 }, 110 ignorechangeevent: { 111 'value': false 112 } 113 } 114 }); 115 116 M.core = M.core || {}; 117 M.core.init_formautosubmit = M.core.init_formautosubmit || function(config) { 118 return new FORMAUTOSUBMIT(config); 119 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |