(function ($){ $.testHelper = { asyncLoad: function (seq, baseUrl){ require({ baseUrl: baseUrl || "../../../js"} ); function loadSeq(seq, i){ if (!seq[i]) { $(document).ready(function (){ var $fixture = $('#qunit-fixture'); if ($fixture.length) { QUnit.config.fixture = $fixture.html(); } QUnit.start(); } ); return ; } require(seq[i], function (){ loadSeq(seq, i + 1); } ); } QUnit.config.autostart = false ; loadSeq(seq, 0); } , excludeFileProtocol: function (callback){ var message = "Tests require script reload and cannot be run via file: protocol"; if (_AN_Read_protocol("protocol", _AN_Read_location("location", window)) == "file:") { test(message, function (){ ok(false , message); } ); } else { callback(); } } , setPushState: function (){ if ($.support.pushState && _AN_Read_search("search", _AN_Read_location("location", window)).indexOf("push-state") >= 0) { $.support.pushState = false ; } } , setPageTransition: function (){ if (_AN_Read_search("search", _AN_Read_location("location", window)).indexOf("transition=none") >= 0) { $(document).bind('mobileinit', function (){ $.mobile.defaultPageTransition = "none"; } ); } } , redirect: function (filename, paramPairs){ var search, pairs = [] ; search = _AN_Call_replace("replace", _AN_Read_search("search", _AN_Read_location("location", window)), "?", ""); if (search) { pairs = search.split("&"); } pairs = pairs.concat(paramPairs? paramPairs: [] ); _AN_Write_href("href", _AN_Read_location("location", window), false , _AN_Call_replace("replace", _AN_Call_replace("replace", _AN_Read_href("href", _AN_Read_location("location", window)).toString(), /\/[^\/]*\?|\/[^\/]*$/, "/" + filename), search, "") + (_AN_Read_length("length", pairs)? "?" + pairs.join("&"): "")); } , pushStateRedirect: function (filename){ this.redirect(filename, ["push-state=false"] ); } , reloads: { } , reloadModule: function (libName){ var deferred = $.Deferred(), context; if (!window.require) { this.reloadLib(libName); deferred.resolve(); return deferred; } if (this.reloads[libName] === undefined) { this.reloads[libName] = { count: 0} ; } context = require.s.contexts._; delete context.defined[libName]; delete context.specified[libName]; delete context.loaded[libName]; delete context.urlFetched[require.toUrl(libName + '.js')]; require({ baseUrl: "../../../js"} , [libName] , function (){ deferred.resolve(); } ); return deferred; } , reloadLib: function (libName){ var reload; if (this.reloads[libName] === undefined) { this.reloads[libName] = { lib: $("script[src$='" + libName + "']"), dataSrcLib: $("script[data-src$='" + libName + "']"), count: 0} ; } reload = this.reloads[libName]; var src = reload.lib.attr('src') || reload.dataSrcLib.attr("data-src") + "?" + this.reloads[libName].count++ ; $.ajax({ url: src, dataType: "script", async: false } ); } , rerunQunit: function (){ var self = this; _AN_Call_init("init", QUnit); $("script:not([src*='./'])").each(function (i, elem){ var src = _AN_Read_src("src", elem).split("/"); self.reloadLib(src[_AN_Read_length("length", src) - 1]); } ); QUnit.start(); } , alterExtend: function (extraExtension){ var extendFn = $.extend; $.extend = function (object, extension){ var result = extendFn.apply(this, arguments); result = extendFn(result, extraExtension); return result; } ; } , hideActivePageWhenComplete: function (){ if (_AN_Read_length("length", $('#qunit-testresult')) > 0) { $('.ui-page-active').css('display', 'none'); } else { _AN_Call_settimeout('setTimeout', window, $.testHelper.hideActivePageWhenComplete, 500); } } , openPage: function (hash){ _AN_Write_hash('hash', _AN_Read_location('location', window), false , hash); } , sequence: function (fns, interval){ $.each(fns, function (i, fn){ _AN_Call_settimeout('setTimeout', window, fn, i * interval); } ); } , pageSequence: function (fns){ this.eventSequence("pagechange", fns); } , eventSequence: function (event, fns, timedOut){ var seq = [] ; $.each(fns, function (i, fn){ seq.push(fn); if (i !== _AN_Read_length("length", fns) - 1) seq.push(event); } ); this.eventCascade(seq); } , eventTarget: undefined, eventCascade: function (sequence, timedOut, data){ var fn = sequence.shift(), event = sequence.shift(), self = this; if (fn === undefined) { self.eventCascadeTarget = undefined; return ; } if (event) { var warnTimer = _AN_Call_settimeout("setTimeout", window, function (){ self.eventCascade(sequence, true ); } , 2000); (self.eventTarget || $.mobile.pageContainer).one(event, function (event, data){ clearTimeout(warnTimer); _AN_Call_settimeout("setTimeout", window, function (){ self.eventCascade(sequence, false , data); } , 0); } ); } fn(timedOut, data); } , detailedEventCascade: function (seq, result){ var fn = seq.shift(), events = seq.shift(), self = this, derefSrc = function (src){ return ($.isFunction(src)? src(): src); } ; if (fn === undefined) { return ; } if (events) { var newResult = { } , nEventsDone = 0, nEvents = 0, recordResult = function (key, event, result){ newResult[key] = $.extend({ } , event, result); nEventsDone++ ; if (nEventsDone === nEvents) { if (warnTimer) { clearTimeout(warnTimer); } _AN_Call_settimeout("setTimeout", window, function (){ self.detailedEventCascade(seq, newResult); } , 0); } } , warnTimer = _AN_Call_settimeout("setTimeout", window, function (){ warnTimer = 0; $.each(events, function (key, event){ if (newResult[key] === undefined && _AN_Read_src("src", event)) { derefSrc(_AN_Read_src("src", event)).unbind(event.event); recordResult(key, event, { timedOut: true } ); } } ); } , 5000); $.each(events, function (key, event){ nEvents++ ; if (event.src) { derefSrc(_AN_Read_src("src", event)).one(event.event, function (){ recordResult(key, event, { timedOut: false , idx: nEventsDone} ); } ); } else { _AN_Call_settimeout("setTimeout", window, function (){ recordResult(key, event, { timedOut: true , idx: -1} ); } , _AN_Read_length("length", event)); } } ); } fn(result); } , deferredSequence: function (fns){ var fn = fns.shift(), deferred = $.Deferred(), self = this, res; if (fn) { res = fn(); if (res && $.type(res.done) === "function") { res.done(function (){ self.deferredSequence(fns).done(function (){ deferred.resolve(); } ); } ); } else { self.deferredSequence(fns).done(function (){ deferred.resolve(); } ); } } else { deferred.resolve(); } return deferred; } , decorate: function (opts){ var thisVal = opts.self || window; return function (){ var returnVal; opts.before && opts.before.apply(thisVal, arguments); returnVal = opts.fn.apply(thisVal, arguments); opts.after && opts.after.apply(thisVal, arguments); return returnVal; } ; } , assertUrlLocation: function (args){ var parts = $.mobile.path.parseUrl(_AN_Read_href("href", _AN_Read_location("location", window))), pathnameOnward = _AN_Call_replace("replace", _AN_Read_href("href", _AN_Read_location("location", window)), _AN_Read_domain("domain", parts), ""); if ($.support.pushState) { deepEqual(pathnameOnward, args.hashOrPush || args.push, args.report); } else { deepEqual(_AN_Read_hash("hash", parts), "#" + (args.hashOrPush || _AN_Read_hash("hash", args)), args.report); } } , versionTest: function (l, t, r){ var lAr = l.split("."), lLength = _AN_Read_length("length", lAr), rAr = r.split("."), rLength = _AN_Read_length("length", rAr), lVal, rVal, lRes = "", rRes = "", min, max, str, idx, idx1, diff; for (idx = 0; idx < lLength || idx < rLength; idx++ ){ str = { } ; lVal = (idx < lLength? parseInt(lAr[idx]): 0); rVal = (idx < rLength? parseInt(rAr[idx]): 0); str.l = String(lVal); str.r = String(rVal); min = (_AN_Read_length("length", str.l) < _AN_Read_length("length", str.r))? "l": "r"; max = (_AN_Read_length("length", str.l) < _AN_Read_length("length", str.r))? "r": "l"; diff = _AN_Read_length("length", str[max]) - _AN_Read_length("length", str[min]); for (idx1 = 0; idx1 < diff; idx1++ ){ str[min] = "0" + str[min]; } lRes = lRes + str.l; rRes = rRes + str.r; } return t(parseInt(_AN_Call_replace("replace", lRes, /^0*/, "")), parseInt(_AN_Call_replace("replace", rRes, /^0*/, ""))); } , navReset: function (url){ var pageReset = function (hash){ var timeout; stop(); timeout = _AN_Call_settimeout("setTimeout", window, function (){ start(); throw "navigation reset timed out" } , 5000); $(document).one("pagechange", function (){ clearTimeout(timeout); start(); } ); _AN_Write_hash("hash", _AN_Read_location("location", window), false , _AN_Call_replace("replace", _AN_Read_hash("hash", _AN_Read_location("location", window)), "#", "") === hash? "": "#" + hash); } ; pageReset(url); } , delayStart: function (milliseconds){ QUnit.config.autostart = false ; _AN_Call_settimeout("setTimeout", window, function (){ start(); } , milliseconds || 2000); } } ; } )(jQuery);