Sha256: f5230d80b45eb1c6452ae739cbbc4dabab9e948e368595f2e7a573b032d40208

Contents?: true

Size: 1.74 KB

Versions: 39

Compression:

Stored size: 1.74 KB

Contents

/*!
 * docReady v1.0.4
 * Cross browser DOMContentLoaded event emitter
 * MIT license
 */

/*jshint browser: true, strict: true, undef: true, unused: true*/
/*global define: false, require: false, module: false */

( function( window ) {

'use strict';

var document = window.document;
// collection of functions to be triggered on ready
var queue = [];

function docReady( fn ) {
  // throw out non-functions
  if ( typeof fn !== 'function' ) {
    return;
  }

  if ( docReady.isReady ) {
    // ready now, hit it
    fn();
  } else {
    // queue function when ready
    queue.push( fn );
  }
}

docReady.isReady = false;

// triggered on various doc ready events
function onReady( event ) {
  // bail if already triggered or IE8 document is not ready just yet
  var isIE8NotReady = event.type === 'readystatechange' && document.readyState !== 'complete';
  if ( docReady.isReady || isIE8NotReady ) {
    return;
  }

  trigger();
}

function trigger() {
  docReady.isReady = true;
  // process queue
  for ( var i=0, len = queue.length; i < len; i++ ) {
    var fn = queue[i];
    fn();
  }
}

function defineDocReady( eventie ) {
  // trigger ready if page is ready
  if ( document.readyState === 'complete' ) {
    trigger();
  } else {
    // listen for events
    eventie.bind( document, 'DOMContentLoaded', onReady );
    eventie.bind( document, 'readystatechange', onReady );
    eventie.bind( window, 'load', onReady );
  }

  return docReady;
}

// transport
if ( typeof define === 'function' && define.amd ) {
  // AMD
  define( [ 'eventie/eventie' ], defineDocReady );
} else if ( typeof exports === 'object' ) {
  module.exports = defineDocReady( require('eventie') );
} else {
  // browser global
  window.docReady = defineDocReady( window.eventie );
}

})( window );

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wbase-0.3.20 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.19 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.18 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.17 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.16 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.15 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.14 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.13 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.12 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.11 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.10 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.9 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.8 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.7 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.6 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.5 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.4 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.3 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.2 lib/vendor/admin/doc-ready/doc-ready.js
wbase-0.3.1 lib/vendor/admin/doc-ready/doc-ready.js