@qbix/q.js 1.0.2 → 1.0.6
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 +28 -2
- package/dist/Metrics.js +4885 -0
- package/dist/Metrics.min.js +160 -0
- package/dist/Q.js +187 -183
- package/dist/Q.min.js +89 -88
- package/dist/Q.minimal.js +186 -182
- package/dist/Q.minimal.min.js +48 -48
- package/package.json +18 -4
package/dist/Q.minimal.js
CHANGED
|
@@ -523,9 +523,10 @@ Elp.removeClass = function (className) {
|
|
|
523
523
|
* @method addClass
|
|
524
524
|
* @chainable
|
|
525
525
|
* @param {String} className
|
|
526
|
+
* @param {Boolean} [prepend=false] If true, add the class before existing classes instead of after
|
|
526
527
|
* @return {Element} returns this, for chaining
|
|
527
528
|
*/
|
|
528
|
-
Elp.addClass = function (className) {
|
|
529
|
+
Elp.addClass = function (className, prepend) {
|
|
529
530
|
if (Q.typeOf(className) !== 'string') {
|
|
530
531
|
className = '';
|
|
531
532
|
}
|
|
@@ -535,10 +536,15 @@ Elp.addClass = function (className) {
|
|
|
535
536
|
for (var i=0; i<l; ++i) {
|
|
536
537
|
var c = classNames[i];
|
|
537
538
|
if (!c) continue;
|
|
538
|
-
if (
|
|
539
|
-
this.
|
|
539
|
+
if (prepend) {
|
|
540
|
+
if (this.hasClass(c)) {
|
|
541
|
+
this.removeClass(c);
|
|
542
|
+
}
|
|
543
|
+
this.className = c + ' ' + this.className;
|
|
540
544
|
} else {
|
|
541
|
-
this.
|
|
545
|
+
if (this.hasClass(c)) {
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
542
548
|
this.className += ' ' + c;
|
|
543
549
|
}
|
|
544
550
|
}
|
|
@@ -735,6 +741,181 @@ Q.typeOf.treatAsObject = Q.typeOf.treatAsObject = {
|
|
|
735
741
|
PluginArray: true
|
|
736
742
|
};
|
|
737
743
|
|
|
744
|
+
/**
|
|
745
|
+
* Used for handling callbacks, whether they come as functions,
|
|
746
|
+
* strings referring to functions (if evaluated), arrays or hashes.
|
|
747
|
+
* @static
|
|
748
|
+
* @method handle
|
|
749
|
+
* @param {Mixed} callables
|
|
750
|
+
* The callables to call
|
|
751
|
+
* Can be a function, array of functions, object of functions, Q.Event or URL
|
|
752
|
+
* If it is a url, simply follow it with options, callback
|
|
753
|
+
* @param {Function} callback
|
|
754
|
+
* You can pass a function here if callables is a URL
|
|
755
|
+
* @param {Object} context
|
|
756
|
+
* The context in which to call them
|
|
757
|
+
* @param {Array} args
|
|
758
|
+
* An array of arguments to pass to them
|
|
759
|
+
* @param {Object} options
|
|
760
|
+
* If callables is a url, these are the options to pass to Q.loadUrl, if any. Also can include:
|
|
761
|
+
* @param {boolean} [options.dontReload=false] if this is true and callback is a url matching current url, it is not reloaded
|
|
762
|
+
* @param {boolean} [options.loadUsingAjax=true] if this is true and callback is a url, it is loaded using Q.loadUrl
|
|
763
|
+
* @param {Function} [options.externalLoader] when using loadUsingAjax, you can set this to a function to suppress loading of external websites with Q.handle.
|
|
764
|
+
* Note: this will still not supress loading of external websites done with other means, such as window.location
|
|
765
|
+
* @param {Object} [options.fields] optional fields to pass with any method other than "get"
|
|
766
|
+
* @param {String|Function} [options.callback] if a string, adds a '&Q.callback='+encodeURIComponent(callback) to the querystring. If a function, this is the callback.
|
|
767
|
+
* @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"
|
|
768
|
+
* @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.
|
|
769
|
+
* @param {String|Array} [options.slotNames] a comma-separated list of slot names, or an array of slot names
|
|
770
|
+
* @param {boolean} [options.quiet] defaults to false. If true, allows visual indications that the request is going to take place.
|
|
771
|
+
* @param {Function} [options.handleException] pass a function here to handle thrown exceptions instead of rethrowing them
|
|
772
|
+
* @return {number}
|
|
773
|
+
* The number of handlers executed
|
|
774
|
+
*/
|
|
775
|
+
Q.handle = function _Q_handle(callables, /* callback, */ context, args, options) {
|
|
776
|
+
try {
|
|
777
|
+
if (!callables) {
|
|
778
|
+
return 0;
|
|
779
|
+
}
|
|
780
|
+
if (!context) context = root;
|
|
781
|
+
if (!args) args = [];
|
|
782
|
+
var i=0, count=0, k, result;
|
|
783
|
+
if (callables === location) callables = location.href;
|
|
784
|
+
switch (Q.typeOf(callables)) {
|
|
785
|
+
case 'function':
|
|
786
|
+
result = callables.apply(context, args);
|
|
787
|
+
if (result === false) return false;
|
|
788
|
+
return 1;
|
|
789
|
+
case 'array':
|
|
790
|
+
for (i=0; i<callables.length; ++i) {
|
|
791
|
+
result = Q.handle(callables[i], context, args);
|
|
792
|
+
if (result === false) return false;
|
|
793
|
+
count += result;
|
|
794
|
+
}
|
|
795
|
+
return count;
|
|
796
|
+
case 'Q.Event':
|
|
797
|
+
return callables.handle.apply(context, args);
|
|
798
|
+
case 'object':
|
|
799
|
+
for (k in callables) {
|
|
800
|
+
result = Q.handle(callables[k], context, args);
|
|
801
|
+
if (result === false) return false;
|
|
802
|
+
count += result;
|
|
803
|
+
}
|
|
804
|
+
return count;
|
|
805
|
+
case 'string':
|
|
806
|
+
var o = Q.extend({}, Q.handle.options, options);
|
|
807
|
+
if (!callables.isUrl()
|
|
808
|
+
&& (callables[0] != '#')
|
|
809
|
+
&& (!o.target || o.target.toLowerCase() === '_self')) {
|
|
810
|
+
// Assume this is not a URL.
|
|
811
|
+
// Try to evaluate the expression, and execute the resulting function
|
|
812
|
+
var c = Q.getObject(callables, context) || Q.getObject(callables);
|
|
813
|
+
return Q.handle(c, context, args);
|
|
814
|
+
}
|
|
815
|
+
// Assume callables is a URL
|
|
816
|
+
if (o.dontReload && Q.info && Q.info.url === callables) {
|
|
817
|
+
return 0;
|
|
818
|
+
}
|
|
819
|
+
var callback = null;
|
|
820
|
+
if (typeof arguments[1] === 'function') {
|
|
821
|
+
// Some syntactic sugar: (url, callback) omitting context, args, options
|
|
822
|
+
callback = arguments[1];
|
|
823
|
+
o = Q.handle.options;
|
|
824
|
+
} else if (arguments[1] && (arguments[3] === undefined)) {
|
|
825
|
+
// Some more syntactic sugar: (url, options, callback) omitting context, args, options
|
|
826
|
+
o = Q.extend({}, Q.handle.options, arguments[1]);
|
|
827
|
+
if (typeof arguments[2] === 'function') {
|
|
828
|
+
callback = arguments[2];
|
|
829
|
+
}
|
|
830
|
+
} else {
|
|
831
|
+
o = Q.extend({}, Q.handle.options, options);
|
|
832
|
+
if (o.callback) {
|
|
833
|
+
callback = o.callback;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
var baseUrl = Q.baseUrl();
|
|
837
|
+
var sameDomain = callables.sameDomain(baseUrl);
|
|
838
|
+
if (callables[0] === '#') {
|
|
839
|
+
root.location.hash = callables;
|
|
840
|
+
} else if (o.loadUsingAjax && sameDomain
|
|
841
|
+
&& (!o.target || o.target === true || o.target === '_self')) {
|
|
842
|
+
if (callables.search(baseUrl) === 0) {
|
|
843
|
+
// Use AJAX to refresh the page whenever the request is for a local page
|
|
844
|
+
Q.loadUrl(callables, Q.extend({
|
|
845
|
+
// shouldn't need to re-load responseExtras, they're the same across sessions
|
|
846
|
+
loadExtras: 'session',
|
|
847
|
+
ignoreHistory: false,
|
|
848
|
+
onActivate: function () {
|
|
849
|
+
if (callback) callback();
|
|
850
|
+
}
|
|
851
|
+
}, o)).then(function (a) {
|
|
852
|
+
|
|
853
|
+
}, function (err) {
|
|
854
|
+
if (o && o.handleException) {
|
|
855
|
+
return o.handleException(err);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
} else if (o.externalLoader) {
|
|
859
|
+
o.externalLoader.apply(this, arguments);
|
|
860
|
+
} else {
|
|
861
|
+
root.location = callables;
|
|
862
|
+
}
|
|
863
|
+
} else {
|
|
864
|
+
if (Q.typeOf(o.fields) === 'object') {
|
|
865
|
+
var method = 'POST';
|
|
866
|
+
if (o.method) {
|
|
867
|
+
switch (o.method.toUpperCase()) {
|
|
868
|
+
case "GET":
|
|
869
|
+
case "POST":
|
|
870
|
+
method = o.method;
|
|
871
|
+
break;
|
|
872
|
+
default:
|
|
873
|
+
method = 'POST'; // sadly HTML forms don't support other methods
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
Q.formPost(callables, o.fields, method, {onLoad: o.callback, target: o.target});
|
|
878
|
+
} else {
|
|
879
|
+
if (Q.info && callables === baseUrl) {
|
|
880
|
+
callables+= '/';
|
|
881
|
+
}
|
|
882
|
+
if (!o.target || o.target === true || o.target === '_self') {
|
|
883
|
+
if (root.location.href == callables) {
|
|
884
|
+
root.location.reload(true);
|
|
885
|
+
} else {
|
|
886
|
+
root.location = callables;
|
|
887
|
+
}
|
|
888
|
+
} else {
|
|
889
|
+
root.open(callables, o.target);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
Q.handle.onUrl.handle(callables, o);
|
|
894
|
+
return 1;
|
|
895
|
+
default:
|
|
896
|
+
return 0;
|
|
897
|
+
}
|
|
898
|
+
} catch (exception) {
|
|
899
|
+
if (options && options.handleException) {
|
|
900
|
+
return options.handleException(exception);
|
|
901
|
+
}
|
|
902
|
+
throw exception;
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
Q.handle.options = {
|
|
906
|
+
loadUsingAjax: true,
|
|
907
|
+
externalLoader: null,
|
|
908
|
+
dontReload: false
|
|
909
|
+
};
|
|
910
|
+
setTimeout(function () {
|
|
911
|
+
Q.handle.onUrl = new Q.Event(function () {
|
|
912
|
+
var elements = document.getElementsByClassName('Q_error_message');
|
|
913
|
+
Q.each(elements, function () {
|
|
914
|
+
Q.removeElement(this, true);
|
|
915
|
+
});
|
|
916
|
+
}, "Q");
|
|
917
|
+
});
|
|
918
|
+
|
|
738
919
|
/**
|
|
739
920
|
* Iterates over elements in a container, and calls the callback.
|
|
740
921
|
* Use this if you want to avoid problems with loops and closures.
|
|
@@ -2714,12 +2895,8 @@ Q.currentScript = function (stackLevels) {
|
|
|
2714
2895
|
console.warn("parseSrc: could not parse src", src);
|
|
2715
2896
|
return null;
|
|
2716
2897
|
}
|
|
2717
|
-
var src = parts[1] + parts[2].split(/[?#]/)[0];
|
|
2718
|
-
if (!root._Q_currentScript_src) {
|
|
2719
|
-
root._Q_currentScript_src = src;
|
|
2720
|
-
}
|
|
2721
2898
|
return {
|
|
2722
|
-
src:
|
|
2899
|
+
src: parts[1] + parts[2].split(/[?#]/)[0], // clean URL (no query/hash)
|
|
2723
2900
|
srcWithQuerystring: parts[1] + parts[2], // keep full URL
|
|
2724
2901
|
path: parts[1], // directory path
|
|
2725
2902
|
file: parts[2].split(/[?#]/)[0] // filename only
|
|
@@ -3523,179 +3700,6 @@ Q.getter.REQUESTING = 1;
|
|
|
3523
3700
|
Q.getter.WAITING = 2;
|
|
3524
3701
|
Q.getter.THROTTLING = 3;
|
|
3525
3702
|
|
|
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
|
-
|
|
3699
3703
|
/**
|
|
3700
3704
|
* Custom exception constructor
|
|
3701
3705
|
* @class Q.Exception
|