[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 /** 2 * Add some custom methods to the node class to make our lives a little 3 * easier within this module. 4 */ 5 Y.mix(Y.Node.prototype, { 6 /** 7 * Gets the value of the first option in the select box 8 */ 9 firstOptionValue: function() { 10 if (this.get('nodeName').toLowerCase() !== 'select') { 11 return false; 12 } 13 return this.one('option').get('value'); 14 }, 15 /** 16 * Gets the value of the last option in the select box 17 */ 18 lastOptionValue: function() { 19 if (this.get('nodeName').toLowerCase() !== 'select') { 20 return false; 21 } 22 return this.all('option').item(this.optionSize()-1).get('value'); 23 }, 24 /** 25 * Gets the number of options in the select box 26 */ 27 optionSize: function() { 28 if (this.get('nodeName').toLowerCase() !== 'select') { 29 return false; 30 } 31 return parseInt(this.all('option').size(), 10); 32 }, 33 /** 34 * Gets the value of the selected option in the select box 35 */ 36 selectedOptionValue: function() { 37 if (this.get('nodeName').toLowerCase() !== 'select') { 38 return false; 39 } 40 return this.all('option').item(this.get('selectedIndex')).get('value'); 41 } 42 }); 43 44 M.form = M.form || {}; 45 M.form.dateselector = { 46 panel: null, 47 calendar: null, 48 currentowner: null, 49 hidetimeout: null, 50 repositiontimeout: null, 51 init_date_selectors: function(config) { 52 if (this.panel === null) { 53 this.initPanel(config); 54 } 55 Y.all('.fdate_time_selector').each(function() { 56 config.node = this; 57 new CALENDAR(config); 58 }); 59 Y.all('.fdate_selector').each(function() { 60 config.node = this; 61 new CALENDAR(config); 62 }); 63 }, 64 initPanel: function(config) { 65 this.panel = new Y.Overlay({ 66 visible: false, 67 bodyContent: Y.Node.create('<div id="dateselector-calendar-content"></div>'), 68 id: 'dateselector-calendar-panel' 69 }); 70 this.panel.render(document.body); 71 // zIndex is added by panel.render() and is set to 0. 72 // Remove zIndex from panel, as this should be set by CSS. This can be done by removeAttr but 73 // ie8 fails and there is know issue for it. 74 Y.one('#dateselector-calendar-panel').setStyle('zIndex', null); 75 this.panel.on('heightChange', this.fix_position, this); 76 77 Y.one('#dateselector-calendar-panel').on('click', function(e){e.halt();}); 78 Y.one(document.body).on('click', this.document_click, this); 79 80 this.calendar = new MOODLECALENDAR({ 81 contentBox: "#dateselector-calendar-content", 82 width: "300px", 83 showPrevMonth: true, 84 showNextMonth: true, 85 firstdayofweek: config.firstdayofweek, 86 WEEKDAYS_MEDIUM: [ 87 config.sun, 88 config.mon, 89 config.tue, 90 config.wed, 91 config.thu, 92 config.fri, 93 config.sat ] 94 }); 95 }, 96 cancel_any_timeout: function() { 97 if (this.hidetimeout) { 98 clearTimeout(this.hidetimeout); 99 this.hidetimeout = null; 100 } 101 if (this.repositiontimeout) { 102 clearTimeout(this.repositiontimeout); 103 this.repositiontimeout = null; 104 } 105 }, 106 delayed_reposition: function() { 107 if (this.repositiontimeout) { 108 clearTimeout(this.repositiontimeout); 109 this.repositiontimeout = null; 110 } 111 this.repositiontimeout = setTimeout(this.fix_position, 500); 112 }, 113 fix_position: function() { 114 if (this.currentowner) { 115 var alignpoints = [ 116 Y.WidgetPositionAlign.BL, 117 Y.WidgetPositionAlign.TL 118 ]; 119 120 // Change the alignment if this is an RTL language. 121 if (right_to_left()) { 122 alignpoints = [ 123 Y.WidgetPositionAlign.BR, 124 Y.WidgetPositionAlign.TR 125 ]; 126 } 127 128 129 this.panel.set('align', { 130 node: this.currentowner.get('node').one('select'), 131 points: alignpoints 132 }); 133 } 134 }, 135 document_click: function(e) { 136 if (this.currentowner) { 137 if (this.currentowner.get('node').ancestor('div').contains(e.target)) { 138 setTimeout(function() { 139 M.form.dateselector.cancel_any_timeout(); 140 }, 100); 141 } else { 142 this.currentowner.release_calendar(e); 143 } 144 } 145 } 146 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |