@qbix/q.js 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/Q.js +195 -177
- package/dist/Q.min.js +242 -242
- package/dist/Q.minimal.js +194 -176
- package/dist/Q.minimal.min.js +111 -111
- package/package.json +1 -1
package/dist/Q.minimal.js
CHANGED
|
@@ -2714,8 +2714,12 @@ Q.currentScript = function (stackLevels) {
|
|
|
2714
2714
|
console.warn("parseSrc: could not parse src", src);
|
|
2715
2715
|
return null;
|
|
2716
2716
|
}
|
|
2717
|
+
var src = parts[1] + parts[2].split(/[?#]/)[0];
|
|
2718
|
+
if (!root._Q_currentScript_src) {
|
|
2719
|
+
root._Q_currentScript_src = src;
|
|
2720
|
+
}
|
|
2717
2721
|
return {
|
|
2718
|
-
src:
|
|
2722
|
+
src: src, // clean URL (no query/hash)
|
|
2719
2723
|
srcWithQuerystring: parts[1] + parts[2], // keep full URL
|
|
2720
2724
|
path: parts[1], // directory path
|
|
2721
2725
|
file: parts[2].split(/[?#]/)[0] // filename only
|
|
@@ -2733,8 +2737,22 @@ Q.currentScript = function (stackLevels) {
|
|
|
2733
2737
|
* @return {Object} object with properties "src", "path" and "file"
|
|
2734
2738
|
*/
|
|
2735
2739
|
Q.currentScriptPath = function (subpath, stackLevels) {
|
|
2736
|
-
|
|
2737
|
-
|
|
2740
|
+
var cs = Q.currentScript(stackLevels);
|
|
2741
|
+
var src = (cs && cs.src)
|
|
2742
|
+
|| root._Q_currentScript_src
|
|
2743
|
+
|| (document.currentScript && document.currentScript.src);
|
|
2744
|
+
if (!src) {
|
|
2745
|
+
// last resort: most recently added script with a src
|
|
2746
|
+
var scripts = document.getElementsByTagName('script');
|
|
2747
|
+
for (var i = scripts.length - 1; i >= 0; --i) {
|
|
2748
|
+
if (scripts[i].src) { src = scripts[i].src; break; }
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
if (!src) {
|
|
2752
|
+
return Q.info && Q.info.baseUrl ? Q.info.baseUrl : '';
|
|
2753
|
+
}
|
|
2754
|
+
return src.split('/').slice(0, -1).join('/')
|
|
2755
|
+
+ (subpath ? '/' + subpath : '');
|
|
2738
2756
|
};
|
|
2739
2757
|
var currentScriptPath = Q.currentScriptPath();
|
|
2740
2758
|
|
|
@@ -3505,6 +3523,179 @@ Q.getter.REQUESTING = 1;
|
|
|
3505
3523
|
Q.getter.WAITING = 2;
|
|
3506
3524
|
Q.getter.THROTTLING = 3;
|
|
3507
3525
|
|
|
3526
|
+
/**
|
|
3527
|
+
* Used for handling callbacks, whether they come as functions,
|
|
3528
|
+
* strings referring to functions (if evaluated), arrays or hashes.
|
|
3529
|
+
* @static
|
|
3530
|
+
* @method handle
|
|
3531
|
+
* @param {Mixed} callables
|
|
3532
|
+
* The callables to call
|
|
3533
|
+
* Can be a function, array of functions, object of functions, Q.Event or URL
|
|
3534
|
+
* If it is a url, simply follow it with options, callback
|
|
3535
|
+
* @param {Function} callback
|
|
3536
|
+
* You can pass a function here if callables is a URL
|
|
3537
|
+
* @param {Object} context
|
|
3538
|
+
* The context in which to call them
|
|
3539
|
+
* @param {Array} args
|
|
3540
|
+
* An array of arguments to pass to them
|
|
3541
|
+
* @param {Object} options
|
|
3542
|
+
* If callables is a url, these are the options to pass to Q.loadUrl, if any. Also can include:
|
|
3543
|
+
* @param {boolean} [options.dontReload=false] if this is true and callback is a url matching current url, it is not reloaded
|
|
3544
|
+
* @param {boolean} [options.loadUsingAjax=true] if this is true and callback is a url, it is loaded using Q.loadUrl
|
|
3545
|
+
* @param {Function} [options.externalLoader] when using loadUsingAjax, you can set this to a function to suppress loading of external websites with Q.handle.
|
|
3546
|
+
* Note: this will still not supress loading of external websites done with other means, such as window.location
|
|
3547
|
+
* @param {Object} [options.fields] optional fields to pass with any method other than "get"
|
|
3548
|
+
* @param {String|Function} [options.callback] if a string, adds a '&Q.callback='+encodeURIComponent(callback) to the querystring. If a function, this is the callback.
|
|
3549
|
+
* @param {String} [options.loadExtras="session"] if "all", asks the server to load the extra scripts, stylesheets, etc. that are loaded on first page load, can also be "response", "initial", "session" or "initial,session"
|
|
3550
|
+
* @param {String} [options.target] the name of a window or iframe to use as the target. In this case callables is treated as a url.
|
|
3551
|
+
* @param {String|Array} [options.slotNames] a comma-separated list of slot names, or an array of slot names
|
|
3552
|
+
* @param {boolean} [options.quiet] defaults to false. If true, allows visual indications that the request is going to take place.
|
|
3553
|
+
* @param {Function} [options.handleException] pass a function here to handle thrown exceptions instead of rethrowing them
|
|
3554
|
+
* @return {number}
|
|
3555
|
+
* The number of handlers executed
|
|
3556
|
+
*/
|
|
3557
|
+
Q.handle = function _Q_handle(callables, /* callback, */ context, args, options) {
|
|
3558
|
+
try {
|
|
3559
|
+
if (!callables) {
|
|
3560
|
+
return 0;
|
|
3561
|
+
}
|
|
3562
|
+
if (!context) context = root;
|
|
3563
|
+
if (!args) args = [];
|
|
3564
|
+
var i=0, count=0, k, result;
|
|
3565
|
+
if (callables === location) callables = location.href;
|
|
3566
|
+
switch (Q.typeOf(callables)) {
|
|
3567
|
+
case 'function':
|
|
3568
|
+
result = callables.apply(context, args);
|
|
3569
|
+
if (result === false) return false;
|
|
3570
|
+
return 1;
|
|
3571
|
+
case 'array':
|
|
3572
|
+
for (i=0; i<callables.length; ++i) {
|
|
3573
|
+
result = Q.handle(callables[i], context, args);
|
|
3574
|
+
if (result === false) return false;
|
|
3575
|
+
count += result;
|
|
3576
|
+
}
|
|
3577
|
+
return count;
|
|
3578
|
+
case 'Q.Event':
|
|
3579
|
+
return callables.handle.apply(context, args);
|
|
3580
|
+
case 'object':
|
|
3581
|
+
for (k in callables) {
|
|
3582
|
+
result = Q.handle(callables[k], context, args);
|
|
3583
|
+
if (result === false) return false;
|
|
3584
|
+
count += result;
|
|
3585
|
+
}
|
|
3586
|
+
return count;
|
|
3587
|
+
case 'string':
|
|
3588
|
+
var o = Q.extend({}, Q.handle.options, options);
|
|
3589
|
+
if (!callables.isUrl()
|
|
3590
|
+
&& (callables[0] != '#')
|
|
3591
|
+
&& (!o.target || o.target.toLowerCase() === '_self')) {
|
|
3592
|
+
// Assume this is not a URL.
|
|
3593
|
+
// Try to evaluate the expression, and execute the resulting function
|
|
3594
|
+
var c = Q.getObject(callables, context) || Q.getObject(callables);
|
|
3595
|
+
return Q.handle(c, context, args);
|
|
3596
|
+
}
|
|
3597
|
+
// Assume callables is a URL
|
|
3598
|
+
if (o.dontReload && Q.info && Q.info.url === callables) {
|
|
3599
|
+
return 0;
|
|
3600
|
+
}
|
|
3601
|
+
var callback = null;
|
|
3602
|
+
if (typeof arguments[1] === 'function') {
|
|
3603
|
+
// Some syntactic sugar: (url, callback) omitting context, args, options
|
|
3604
|
+
callback = arguments[1];
|
|
3605
|
+
o = Q.handle.options;
|
|
3606
|
+
} else if (arguments[1] && (arguments[3] === undefined)) {
|
|
3607
|
+
// Some more syntactic sugar: (url, options, callback) omitting context, args, options
|
|
3608
|
+
o = Q.extend({}, Q.handle.options, arguments[1]);
|
|
3609
|
+
if (typeof arguments[2] === 'function') {
|
|
3610
|
+
callback = arguments[2];
|
|
3611
|
+
}
|
|
3612
|
+
} else {
|
|
3613
|
+
o = Q.extend({}, Q.handle.options, options);
|
|
3614
|
+
if (o.callback) {
|
|
3615
|
+
callback = o.callback;
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
var baseUrl = Q.baseUrl();
|
|
3619
|
+
var sameDomain = callables.sameDomain(baseUrl);
|
|
3620
|
+
if (callables[0] === '#') {
|
|
3621
|
+
root.location.hash = callables;
|
|
3622
|
+
} else if (o.loadUsingAjax && sameDomain
|
|
3623
|
+
&& (!o.target || o.target === true || o.target === '_self')) {
|
|
3624
|
+
if (callables.search(baseUrl) === 0) {
|
|
3625
|
+
// Use AJAX to refresh the page whenever the request is for a local page
|
|
3626
|
+
Q.loadUrl(callables, Q.extend({
|
|
3627
|
+
// shouldn't need to re-load responseExtras, they're the same across sessions
|
|
3628
|
+
loadExtras: 'session',
|
|
3629
|
+
ignoreHistory: false,
|
|
3630
|
+
onActivate: function () {
|
|
3631
|
+
if (callback) callback();
|
|
3632
|
+
}
|
|
3633
|
+
}, o)).then(function (a) {
|
|
3634
|
+
|
|
3635
|
+
}, function (err) {
|
|
3636
|
+
if (o && o.handleException) {
|
|
3637
|
+
return o.handleException(err);
|
|
3638
|
+
}
|
|
3639
|
+
});
|
|
3640
|
+
} else if (o.externalLoader) {
|
|
3641
|
+
o.externalLoader.apply(this, arguments);
|
|
3642
|
+
} else {
|
|
3643
|
+
root.location = callables;
|
|
3644
|
+
}
|
|
3645
|
+
} else {
|
|
3646
|
+
if (Q.typeOf(o.fields) === 'object') {
|
|
3647
|
+
var method = 'POST';
|
|
3648
|
+
if (o.method) {
|
|
3649
|
+
switch (o.method.toUpperCase()) {
|
|
3650
|
+
case "GET":
|
|
3651
|
+
case "POST":
|
|
3652
|
+
method = o.method;
|
|
3653
|
+
break;
|
|
3654
|
+
default:
|
|
3655
|
+
method = 'POST'; // sadly HTML forms don't support other methods
|
|
3656
|
+
break;
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
Q.formPost(callables, o.fields, method, {onLoad: o.callback, target: o.target});
|
|
3660
|
+
} else {
|
|
3661
|
+
if (Q.info && callables === baseUrl) {
|
|
3662
|
+
callables+= '/';
|
|
3663
|
+
}
|
|
3664
|
+
if (!o.target || o.target === true || o.target === '_self') {
|
|
3665
|
+
if (root.location.href == callables) {
|
|
3666
|
+
root.location.reload(true);
|
|
3667
|
+
} else {
|
|
3668
|
+
root.location = callables;
|
|
3669
|
+
}
|
|
3670
|
+
} else {
|
|
3671
|
+
root.open(callables, o.target);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
Q.handle.onUrl.handle(callables, o);
|
|
3676
|
+
return 1;
|
|
3677
|
+
default:
|
|
3678
|
+
return 0;
|
|
3679
|
+
}
|
|
3680
|
+
} catch (exception) {
|
|
3681
|
+
if (options && options.handleException) {
|
|
3682
|
+
return options.handleException(exception);
|
|
3683
|
+
}
|
|
3684
|
+
throw exception;
|
|
3685
|
+
}
|
|
3686
|
+
};
|
|
3687
|
+
Q.handle.options = {
|
|
3688
|
+
loadUsingAjax: true,
|
|
3689
|
+
externalLoader: null,
|
|
3690
|
+
dontReload: false
|
|
3691
|
+
};
|
|
3692
|
+
Q.handle.onUrl = new Q.Event(function () {
|
|
3693
|
+
var elements = document.getElementsByClassName('Q_error_message');
|
|
3694
|
+
Q.each(elements, function () {
|
|
3695
|
+
Q.removeElement(this, true);
|
|
3696
|
+
});
|
|
3697
|
+
}, "Q");
|
|
3698
|
+
|
|
3508
3699
|
/**
|
|
3509
3700
|
* Custom exception constructor
|
|
3510
3701
|
* @class Q.Exception
|
|
@@ -8833,179 +9024,6 @@ Q.loadUrl.request = function (url, slotNames, callback, options) {
|
|
|
8833
9024
|
|
|
8834
9025
|
Q.loadUrl.loading = {};
|
|
8835
9026
|
|
|
8836
|
-
/**
|
|
8837
|
-
* Used for handling callbacks, whether they come as functions,
|
|
8838
|
-
* strings referring to functions (if evaluated), arrays or hashes.
|
|
8839
|
-
* @static
|
|
8840
|
-
* @method handle
|
|
8841
|
-
* @param {Mixed} callables
|
|
8842
|
-
* The callables to call
|
|
8843
|
-
* Can be a function, array of functions, object of functions, Q.Event or URL
|
|
8844
|
-
* If it is a url, simply follow it with options, callback
|
|
8845
|
-
* @param {Function} callback
|
|
8846
|
-
* You can pass a function here if callables is a URL
|
|
8847
|
-
* @param {Object} context
|
|
8848
|
-
* The context in which to call them
|
|
8849
|
-
* @param {Array} args
|
|
8850
|
-
* An array of arguments to pass to them
|
|
8851
|
-
* @param {Object} options
|
|
8852
|
-
* If callables is a url, these are the options to pass to Q.loadUrl, if any. Also can include:
|
|
8853
|
-
* @param {boolean} [options.dontReload=false] if this is true and callback is a url matching current url, it is not reloaded
|
|
8854
|
-
* @param {boolean} [options.loadUsingAjax=true] if this is true and callback is a url, it is loaded using Q.loadUrl
|
|
8855
|
-
* @param {Function} [options.externalLoader] when using loadUsingAjax, you can set this to a function to suppress loading of external websites with Q.handle.
|
|
8856
|
-
* Note: this will still not supress loading of external websites done with other means, such as window.location
|
|
8857
|
-
* @param {Object} [options.fields] optional fields to pass with any method other than "get"
|
|
8858
|
-
* @param {String|Function} [options.callback] if a string, adds a '&Q.callback='+encodeURIComponent(callback) to the querystring. If a function, this is the callback.
|
|
8859
|
-
* @param {String} [options.loadExtras="session"] if "all", asks the server to load the extra scripts, stylesheets, etc. that are loaded on first page load, can also be "response", "initial", "session" or "initial,session"
|
|
8860
|
-
* @param {String} [options.target] the name of a window or iframe to use as the target. In this case callables is treated as a url.
|
|
8861
|
-
* @param {String|Array} [options.slotNames] a comma-separated list of slot names, or an array of slot names
|
|
8862
|
-
* @param {boolean} [options.quiet] defaults to false. If true, allows visual indications that the request is going to take place.
|
|
8863
|
-
* @param {Function} [options.handleException] pass a function here to handle thrown exceptions instead of rethrowing them
|
|
8864
|
-
* @return {number}
|
|
8865
|
-
* The number of handlers executed
|
|
8866
|
-
*/
|
|
8867
|
-
Q.handle = function _Q_handle(callables, /* callback, */ context, args, options) {
|
|
8868
|
-
try {
|
|
8869
|
-
if (!callables) {
|
|
8870
|
-
return 0;
|
|
8871
|
-
}
|
|
8872
|
-
if (!context) context = root;
|
|
8873
|
-
if (!args) args = [];
|
|
8874
|
-
var i=0, count=0, k, result;
|
|
8875
|
-
if (callables === location) callables = location.href;
|
|
8876
|
-
switch (Q.typeOf(callables)) {
|
|
8877
|
-
case 'function':
|
|
8878
|
-
result = callables.apply(context, args);
|
|
8879
|
-
if (result === false) return false;
|
|
8880
|
-
return 1;
|
|
8881
|
-
case 'array':
|
|
8882
|
-
for (i=0; i<callables.length; ++i) {
|
|
8883
|
-
result = Q.handle(callables[i], context, args);
|
|
8884
|
-
if (result === false) return false;
|
|
8885
|
-
count += result;
|
|
8886
|
-
}
|
|
8887
|
-
return count;
|
|
8888
|
-
case 'Q.Event':
|
|
8889
|
-
return callables.handle.apply(context, args);
|
|
8890
|
-
case 'object':
|
|
8891
|
-
for (k in callables) {
|
|
8892
|
-
result = Q.handle(callables[k], context, args);
|
|
8893
|
-
if (result === false) return false;
|
|
8894
|
-
count += result;
|
|
8895
|
-
}
|
|
8896
|
-
return count;
|
|
8897
|
-
case 'string':
|
|
8898
|
-
var o = Q.extend({}, Q.handle.options, options);
|
|
8899
|
-
if (!callables.isUrl()
|
|
8900
|
-
&& (callables[0] != '#')
|
|
8901
|
-
&& (!o.target || o.target.toLowerCase() === '_self')) {
|
|
8902
|
-
// Assume this is not a URL.
|
|
8903
|
-
// Try to evaluate the expression, and execute the resulting function
|
|
8904
|
-
var c = Q.getObject(callables, context) || Q.getObject(callables);
|
|
8905
|
-
return Q.handle(c, context, args);
|
|
8906
|
-
}
|
|
8907
|
-
// Assume callables is a URL
|
|
8908
|
-
if (o.dontReload && Q.info && Q.info.url === callables) {
|
|
8909
|
-
return 0;
|
|
8910
|
-
}
|
|
8911
|
-
var callback = null;
|
|
8912
|
-
if (typeof arguments[1] === 'function') {
|
|
8913
|
-
// Some syntactic sugar: (url, callback) omitting context, args, options
|
|
8914
|
-
callback = arguments[1];
|
|
8915
|
-
o = Q.handle.options;
|
|
8916
|
-
} else if (arguments[1] && (arguments[3] === undefined)) {
|
|
8917
|
-
// Some more syntactic sugar: (url, options, callback) omitting context, args, options
|
|
8918
|
-
o = Q.extend({}, Q.handle.options, arguments[1]);
|
|
8919
|
-
if (typeof arguments[2] === 'function') {
|
|
8920
|
-
callback = arguments[2];
|
|
8921
|
-
}
|
|
8922
|
-
} else {
|
|
8923
|
-
o = Q.extend({}, Q.handle.options, options);
|
|
8924
|
-
if (o.callback) {
|
|
8925
|
-
callback = o.callback;
|
|
8926
|
-
}
|
|
8927
|
-
}
|
|
8928
|
-
var baseUrl = Q.baseUrl();
|
|
8929
|
-
var sameDomain = callables.sameDomain(baseUrl);
|
|
8930
|
-
if (callables[0] === '#') {
|
|
8931
|
-
root.location.hash = callables;
|
|
8932
|
-
} else if (o.loadUsingAjax && sameDomain
|
|
8933
|
-
&& (!o.target || o.target === true || o.target === '_self')) {
|
|
8934
|
-
if (callables.search(baseUrl) === 0) {
|
|
8935
|
-
// Use AJAX to refresh the page whenever the request is for a local page
|
|
8936
|
-
Q.loadUrl(callables, Q.extend({
|
|
8937
|
-
// shouldn't need to re-load responseExtras, they're the same across sessions
|
|
8938
|
-
loadExtras: 'session',
|
|
8939
|
-
ignoreHistory: false,
|
|
8940
|
-
onActivate: function () {
|
|
8941
|
-
if (callback) callback();
|
|
8942
|
-
}
|
|
8943
|
-
}, o)).then(function (a) {
|
|
8944
|
-
|
|
8945
|
-
}, function (err) {
|
|
8946
|
-
if (o && o.handleException) {
|
|
8947
|
-
return o.handleException(err);
|
|
8948
|
-
}
|
|
8949
|
-
});
|
|
8950
|
-
} else if (o.externalLoader) {
|
|
8951
|
-
o.externalLoader.apply(this, arguments);
|
|
8952
|
-
} else {
|
|
8953
|
-
root.location = callables;
|
|
8954
|
-
}
|
|
8955
|
-
} else {
|
|
8956
|
-
if (Q.typeOf(o.fields) === 'object') {
|
|
8957
|
-
var method = 'POST';
|
|
8958
|
-
if (o.method) {
|
|
8959
|
-
switch (o.method.toUpperCase()) {
|
|
8960
|
-
case "GET":
|
|
8961
|
-
case "POST":
|
|
8962
|
-
method = o.method;
|
|
8963
|
-
break;
|
|
8964
|
-
default:
|
|
8965
|
-
method = 'POST'; // sadly HTML forms don't support other methods
|
|
8966
|
-
break;
|
|
8967
|
-
}
|
|
8968
|
-
}
|
|
8969
|
-
Q.formPost(callables, o.fields, method, {onLoad: o.callback, target: o.target});
|
|
8970
|
-
} else {
|
|
8971
|
-
if (Q.info && callables === baseUrl) {
|
|
8972
|
-
callables+= '/';
|
|
8973
|
-
}
|
|
8974
|
-
if (!o.target || o.target === true || o.target === '_self') {
|
|
8975
|
-
if (root.location.href == callables) {
|
|
8976
|
-
root.location.reload(true);
|
|
8977
|
-
} else {
|
|
8978
|
-
root.location = callables;
|
|
8979
|
-
}
|
|
8980
|
-
} else {
|
|
8981
|
-
root.open(callables, o.target);
|
|
8982
|
-
}
|
|
8983
|
-
}
|
|
8984
|
-
}
|
|
8985
|
-
Q.handle.onUrl.handle(callables, o);
|
|
8986
|
-
return 1;
|
|
8987
|
-
default:
|
|
8988
|
-
return 0;
|
|
8989
|
-
}
|
|
8990
|
-
} catch (exception) {
|
|
8991
|
-
if (options && options.handleException) {
|
|
8992
|
-
return options.handleException(exception);
|
|
8993
|
-
}
|
|
8994
|
-
throw exception;
|
|
8995
|
-
}
|
|
8996
|
-
};
|
|
8997
|
-
Q.handle.options = {
|
|
8998
|
-
loadUsingAjax: true,
|
|
8999
|
-
externalLoader: null,
|
|
9000
|
-
dontReload: false
|
|
9001
|
-
};
|
|
9002
|
-
Q.handle.onUrl = new Q.Event(function () {
|
|
9003
|
-
var elements = document.getElementsByClassName('Q_error_message');
|
|
9004
|
-
Q.each(elements, function () {
|
|
9005
|
-
Q.removeElement(this, true);
|
|
9006
|
-
});
|
|
9007
|
-
}, "Q");
|
|
9008
|
-
|
|
9009
9027
|
/**
|
|
9010
9028
|
* Parses a querystring
|
|
9011
9029
|
* @static
|