src/pyams_skin/resources/js/myams-ajax.js
changeset 500 f08f5a2ffaa6
parent 489 63ea9a94bd47
equal deleted inserted replaced
499:24e2893a9630 500:f08f5a2ffaa6
    41 				}
    41 				}
    42 			}
    42 			}
    43 			var defaults = {
    43 			var defaults = {
    44 				async: typeof(callback) === 'function'
    44 				async: typeof(callback) === 'function'
    45 			};
    45 			};
    46 			var settings = $.extend({}, defaults, options);
    46 			var settings = $.extend({}, defaults, options),
       
    47 				deferred = [],
       
    48 				index;
    47 			if (checker instanceof Array) {
    49 			if (checker instanceof Array) {
    48 				var deferred = [];
    50 				for (index = 0; index < checker.length; index++) {
    49 				for (var index = 0; index < checker.length; index++) {
       
    50 					if (checker[index] === undefined) {
    51 					if (checker[index] === undefined) {
    51 						deferred.push(ams.getScript(source[index], {async: true}));
    52 						deferred.push(ams.getScript(source[index], {async: true}));
    52 					}
    53 					}
    53 				}
    54 				}
    54 				if (deferred.length > 0) {
    55 				if (deferred.length > 0) {
    57 					});
    58 					});
    58 				} else {
    59 				} else {
    59 					callCallbacks(false, options);
    60 					callCallbacks(false, options);
    60 				}
    61 				}
    61 			} else if (checker === undefined) {
    62 			} else if (checker === undefined) {
    62 				if (typeof(source) === 'string') {
    63 				if (source instanceof Array) {
       
    64 					for (index = 0; index < source.length; index++) {
       
    65 						deferred.push(ams.getScript(source[index], {async: true}));
       
    66 					}
       
    67 					if (deferred.length > 0) {
       
    68 						$.when.apply($, deferred).then(function () {
       
    69 							callCallbacks(true, options);
       
    70 						});
       
    71 					} else {
       
    72 						callCallbacks(false, options);
       
    73 					}
       
    74 				} else if (typeof(source) === 'string') {
    63 					ams.getScript(source, function () {
    75 					ams.getScript(source, function () {
    64 						callCallbacks(true, options);
    76 						callCallbacks(true, options);
    65 					}, settings);
    77 					}, settings);
    66 				}
    78 				}
    67 			} else {
    79 			} else {