[ 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 return; 57 } 58 59 var dialogueHeight = this.get('host').get('boundingBox').get('region').height, 60 // Most modern browsers use win.innerHeight, but some older versions of IE use documentElement.clientHeight. 61 // We fall back to 0 if neither can be found which has the effect of disabling scroll locking. 62 windowHeight = Y.config.win.innerHeight || Y.config.doc.documentElement.clientHeight || 0; 63 64 if (!forceOnSmallWindow && dialogueHeight > (windowHeight - 10)) { 65 return; 66 } 67 68 this._enabled = true; 69 var body = Y.one(Y.config.doc.body); 70 71 // We use a CSS class on the body to handle the actual locking. 72 body.addClass('lockscroll'); 73 74 // Increase the count of active instances - this is used to ensure that we do not 75 // remove the locking when parent windows are still open. 76 // Note: We cannot use getData here because data attributes are sandboxed to the instance that created them. 77 var currentCount = parseInt(body.getAttribute('data-activeScrollLocks'), 10) || 0, 78 newCount = currentCount + 1; 79 body.setAttribute('data-activeScrollLocks', newCount); 80 81 return this; 82 }, 83 84 /** 85 * Stop locking the page scroll. 86 * 87 * The instance may be disabled but the scroll lock not removed if other instances of the 88 * plugin are also active. 89 * 90 * @method disableScrollLock 91 * @chainable 92 */ 93 disableScrollLock: function() { 94 if (this.isActive()) { 95 this._enabled = false; 96 97 var body = Y.one(Y.config.doc.body); 98 99 // Decrease the count of active instances. 100 // Note: We cannot use getData here because data attributes are sandboxed to the instance that created them. 101 var currentCount = parseInt(body.getAttribute('data-activeScrollLocks'), 10) || 1, 102 newCount = currentCount - 1; 103 104 if (currentCount === 1) { 105 body.removeClass('lockscroll'); 106 } 107 108 body.setAttribute('data-activeScrollLocks', currentCount - 1); 109 } 110 111 return this; 112 }, 113 114 /** 115 * Return whether scroll locking is active. 116 * 117 * @method isActive 118 * @return Boolean 119 */ 120 isActive: function() { 121 return this._enabled; 122 } 123 124 }, { 125 NS: 'lockScroll', 126 ATTRS: { 127 } 128 }); 129 130 131 }, '@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 |