1
0
mirror of synced 2025-12-09 07:08:17 +08:00

Fix: Observe script

This commit is contained in:
surunzi
2017-11-13 19:46:06 +08:00
parent 03df2f2584
commit fe0a5b4857
2 changed files with 52 additions and 2 deletions

View File

@@ -28,7 +28,8 @@ export default class Resources extends Tool
this.refresh();
this._bindEvent();
this._initCfg();
this._observeScript();
util.ready(() => this._observeScript());
}
refresh()
{

View File

@@ -1364,7 +1364,7 @@ module.exports = (function ()
var each = _.each = (function ()
{
/* Iterates over elements of collection and invokes iteratee for each element.
/* Iterate over elements of collection and invokes iteratee for each element.
*
* |Name |Type |Desc |
* |--------|------------|------------------------------|
@@ -5329,6 +5329,55 @@ module.exports = (function ()
return exports;
})();
/* ------------------------------ ready ------------------------------ */
_.ready = (function ()
{
/* Invoke callback when dom is ready, similar to jQuery ready.
*
* |Name|Type |Desc |
* |----|--------|-----------------|
* |fn |function|Callback function|
*
* ```javascript
* ready(function ()
* {
* // It's safe to manipulate dom here.
* });
* ```
*/
/* module
* env: browser
* test: browser
*/
var fns = [],
listener,
doc = document,
hack = doc.documentElement.doScroll,
domContentLoaded = 'DOMContentLoaded',
loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState);
if (!loaded)
{
doc.addEventListener(domContentLoaded, listener = function ()
{
doc.removeEventListener(domContentLoaded, listener);
loaded = 1;
/* eslint-disable no-cond-assign */
while (listener = fns.shift()) listener();
});
}
function exports(fn)
{
loaded ? setTimeout(fn, 0) : fns.push(fn)
}
return exports;
})();
/* ------------------------------ rtrim ------------------------------ */
var rtrim = _.rtrim = (function ()