[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-core-lockscroll', function (Y, NAME) { 2 3 /** 4 * Provides the ability to lock the scroll for a page, allowing nested 5 * locking. 6 * 7 * @module moodle-core-lockscroll 8 */ 9 10 /** 11 * Provides the ability to lock the scroll for a page. 12 * 13 * This is achieved by applying the class 'lockscroll' to the body Node. 14 * 15 * Nested widgets are also supported and the scroll lock is only removed 16 * when the final plugin instance is disabled. 17 * 18 * @class M.core.LockScroll 19 * @extends Plugin.Base 20 */ 21 Y.namespace('M.core').LockScroll = Y.Base.create('lockScroll', Y.Plugin.Base, [], { 22 23 /** 24 * Whether the LockScroll has been activated. 25 * 26 * @property _enabled 27 * @type Boolean 28 * @protected 29 */ 30 _enabled: false, 31 32 /** 33 * Handle destruction of the lockScroll instance, including disabling 34 * of the current instance. 35 * 36 * @method destructor 37 */ 38 destructor: function() { 39 this.disableScrollLock(); 40 }, 41 42 /** 43 * Start locking the page scroll. 44 * 45 * This is achieved by applying the lockscroll class to the body Node. 46 * 47 * A count of the total number of active, and enabled, lockscroll instances is also kept on 48 * the body to ensure that premature disabling does not occur. 49 * 50 * @method enableScrollLock 51 * @param {Boolean} forceOnSmallWindow Whether to enable the scroll lock, even for small window sizes. 52 * @chainable 53 */ 54 enableScrollLock: function(forceOnSmallWindow) { 55 if (this.isActive()) { 56 Y.log('LockScroll already active. Ignoring enable request', 'warn', 'moodle-core-lockscroll'); 57 return; 58 } 59 60 var dialogueHeight = this.get('host').get('boundingBox').get('region').height, 61 // Most modern browsers use win.innerHeight, but some older versions of IE use documentElement.clientHeight. 62 // We fall back to 0 if neither can be found which has the effect of disabling scroll locking. 63 windowHeight = Y.config.win.innerHeight || Y.config.doc.documentElement.clientHeight || 0; 64 65 if (!forceOnSmallWindow && dialogueHeight > (windowHeight - 10)) { 66 Y.log('Dialogue height greater than window height. Ignoring enable request.', 'warn', 'moodle-core-lockscroll'); 67 return; 68 } 69 70 Y.log('Enabling LockScroll.', 'debug', 'moodle-core-lockscroll'); 71 this._enabled = true; 72 var body = Y.one(Y.config.doc.body); 73 74 // We use a CSS class on the body to handle the actual locking. 75 body.addClass('lockscroll'); 76 77 // Increase the count of active instances - this is used to ensure that we do not 78 // remove the locking when parent windows are still open. 79 // Note: We cannot use getData here because data attributes are sandboxed to the instance that created them. 80 var currentCount = parseInt(body.getAttribute('data-activeScrollLocks'), 10) || 0, 81 newCount = currentCount + 1; 82 body.setAttribute('data-activeScrollLocks', newCount); 83 Y.log("Setting the activeScrollLocks count from " + currentCount + " to " + newCount, 84 'debug', 'moodle-core-lockscroll'); 85 86 return this; 87 }, 88 89 /** 90 * Stop locking the page scroll. 91 * 92 * The instance may be disabled but the scroll lock not removed if other instances of the 93 * plugin are also active. 94 * 95 * @method disableScrollLock 96 * @chainable 97 */ 98 disableScrollLock: function() { 99 if (this.isActive()) { 100 Y.log('Disabling LockScroll.', 'debug', 'moodle-core-lockscroll'); 101 this._enabled = false; 102 103 var body = Y.one(Y.config.doc.body); 104 105 // Decrease the count of active instances. 106 // Note: We cannot use getData here because data attributes are sandboxed to the instance that created them. 107 var currentCount = parseInt(body.getAttribute('data-activeScrollLocks'), 10) || 1, 108 newCount = currentCount - 1; 109 110 if (currentCount === 1) { 111 body.removeClass('lockscroll'); 112 } 113 114 body.setAttribute('data-activeScrollLocks', currentCount - 1); 115 Y.log("Setting the activeScrollLocks count from " + currentCount + " to " + newCount, 116 'debug', 'moodle-core-lockscroll'); 117 } 118 119 return this; 120 }, 121 122 /** 123 * Return whether scroll locking is active. 124 * 125 * @method isActive 126 * @return Boolean 127 */ 128 isActive: function() { 129 return this._enabled; 130 } 131 132 }, { 133 NS: 'lockScroll', 134 ATTRS: { 135 } 136 }); 137 138 139 }, '@VERSION@', {"requires": ["plugin", "base-build"]});
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 |