Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Eliminated custom JavaScript loader.

AuthorDave Jarvis <email>
Date2015-01-15 16:43:53 GMT-0800
Commitc248e11a64fe991d1828ecb20f314217c2c5367c
Parent03d8ea7
source/js/common.js
-/**
- * MIT License
- *
- * Copyright 2014 White Magic Software, Inc.
- */
-
-/*jslint browser: true, devel: true, white: true, unparam: true */
-/*global $, jQuery, ActiveXObject */
-
-"use strict";
-
-var REQ_OBJECTS = [
- function () { return new XMLHttpRequest(); },
- function () { return new ActiveXObject('Msxml2.XMLHTTP'); },
- function () { return new ActiveXObject('Msxml3.XMLHTTP'); },
- function () { return new ActiveXObject('Microsoft.XMLHTTP'); }
-];
-
-/**
- * Provides a cross-browser mechanism to retrieve the XMLHttpRequest object
- * used for performing Ajax requests.
- */
-function get_request_object() {
- var i;
-
- for( i = 0; i < REQ_OBJECTS.length; i += 1 ) {
- try {
- return REQ_OBJECTS[ i ]();
- }
- catch( ignore ) { }
- }
-}
-
-/**
- * This is used to perform an asynchronous injection of a code resource
- * (JavaScript or CSS) into a web page element.
- */
-function inject( path, parent, element, callback ) {
- var req = get_request_object();
-
- req.open( 'GET', path, true );
-
- req.onreadystatechange = function() {
- if( req.readyState === 4 && req.status === 200 ) {
- element.appendChild( document.createTextNode( req.responseText ) );
- parent.appendChild( element );
-
- if( typeof callback === "function" ) {
- callback();
- }
- }
- };
-
- req.send( null );
-}
-
-/**
- * Downloads the contents of a resource (specified by src) and inserts
- * those contents directly into a corresponding tag.
- *
- * @param src - Filname or URL.
- * @param type - 'css' or 'js' to denote style or JavaScript, respectively.
- * @param callback - Function to call after the code is downloaded.
- */
-function include( src, type, callback ) {
- var parent, element;
-
- switch( type ) {
- case 'css':
- parent = document.head || document.getElementsByTagName('head')[0];
- element = document.createElement( 'style' );
- element.type = 'text/' + type;
- element.media = 'all';
- break;
- case 'js':
- parent = document.body || document.getElementsByTagName('body')[0];
- element = document.createElement( 'script' );
- element.type = 'text/javascript';
- break;
- }
-
- inject( src, parent, element, callback );
-}
-
-/**
- * Includes a file local to the web server.
- */
-function include_file( file, type, callback ) {
- var src = type + '/' + file.substr( 0, file.lastIndexOf( '.' ) ) + '.' + type;
- include( src, type, callback );
-}
-
Delta0 lines added, 92 lines removed, 92-line decrease