@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.js
CHANGED
|
@@ -594,9 +594,10 @@ Elp.removeClass = function (className) {
|
|
|
594
594
|
* @method addClass
|
|
595
595
|
* @chainable
|
|
596
596
|
* @param {String} className
|
|
597
|
+
* @param {Boolean} [prepend=false] If true, add the class before existing classes instead of after
|
|
597
598
|
* @return {Element} returns this, for chaining
|
|
598
599
|
*/
|
|
599
|
-
Elp.addClass = function (className) {
|
|
600
|
+
Elp.addClass = function (className, prepend) {
|
|
600
601
|
if (Q.typeOf(className) !== 'string') {
|
|
601
602
|
className = '';
|
|
602
603
|
}
|
|
@@ -606,10 +607,15 @@ Elp.addClass = function (className) {
|
|
|
606
607
|
for (var i=0; i<l; ++i) {
|
|
607
608
|
var c = classNames[i];
|
|
608
609
|
if (!c) continue;
|
|
609
|
-
if (
|
|
610
|
-
this.
|
|
610
|
+
if (prepend) {
|
|
611
|
+
if (this.hasClass(c)) {
|
|
612
|
+
this.removeClass(c);
|
|
613
|
+
}
|
|
614
|
+
this.className = c + ' ' + this.className;
|
|
611
615
|
} else {
|
|
612
|
-
this.
|
|
616
|
+
if (this.hasClass(c)) {
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
613
619
|
this.className += ' ' + c;
|
|
614
620
|
}
|
|
615
621
|
}
|
|
@@ -806,6 +812,182 @@ Q.typeOf.treatAsObject = Q.typeOf.treatAsObject = {
|
|
|
806
812
|
PluginArray: true
|
|
807
813
|
};
|
|
808
814
|
|
|
815
|
+
/**
|
|
816
|
+
* Used for handling callbacks, whether they come as functions,
|
|
817
|
+
* strings referring to functions (if evaluated), arrays or hashes.
|
|
818
|
+
* @static
|
|
819
|
+
* @method handle
|
|
820
|
+
* @param {Mixed} callables
|
|
821
|
+
* The callables to call
|
|
822
|
+
* Can be a function, array of functions, object of functions, Q.Event or URL
|
|
823
|
+
* If it is a url, simply follow it with options, callback
|
|
824
|
+
* @param {Function} callback
|
|
825
|
+
* You can pass a function here if callables is a URL
|
|
826
|
+
* @param {Object} context
|
|
827
|
+
* The context in which to call them
|
|
828
|
+
* @param {Array} args
|
|
829
|
+
* An array of arguments to pass to them
|
|
830
|
+
* @param {Object} options
|
|
831
|
+
* If callables is a url, these are the options to pass to Q.loadUrl, if any. Also can include:
|
|
832
|
+
* @param {boolean} [options.dontReload=false] if this is true and callback is a url matching current url, it is not reloaded
|
|
833
|
+
* @param {boolean} [options.loadUsingAjax=true] if this is true and callback is a url, it is loaded using Q.loadUrl
|
|
834
|
+
* @param {Function} [options.externalLoader] when using loadUsingAjax, you can set this to a function to suppress loading of external websites with Q.handle.
|
|
835
|
+
* Note: this will still not supress loading of external websites done with other means, such as window.location
|
|
836
|
+
* @param {Object} [options.fields] optional fields to pass with any method other than "get"
|
|
837
|
+
* @param {String|Function} [options.callback] if a string, adds a '&Q.callback='+encodeURIComponent(callback) to the querystring. If a function, this is the callback.
|
|
838
|
+
* @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"
|
|
839
|
+
* @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.
|
|
840
|
+
* @param {String|Array} [options.slotNames] a comma-separated list of slot names, or an array of slot names
|
|
841
|
+
* @param {boolean} [options.quiet] defaults to false. If true, allows visual indications that the request is going to take place.
|
|
842
|
+
* @param {Function} [options.handleException] pass a function here to handle thrown exceptions instead of rethrowing them
|
|
843
|
+
* @return {number}
|
|
844
|
+
* The number of handlers executed
|
|
845
|
+
*/
|
|
846
|
+
Q.handle = function _Q_handle(callables, /* callback, */ context, args, options) {
|
|
847
|
+
try {
|
|
848
|
+
if (!callables) {
|
|
849
|
+
return 0;
|
|
850
|
+
}
|
|
851
|
+
if (!context) context = root;
|
|
852
|
+
if (!args) args = [];
|
|
853
|
+
var i=0, count=0, k, result;
|
|
854
|
+
if (callables === location) callables = location.href;
|
|
855
|
+
switch (Q.typeOf(callables)) {
|
|
856
|
+
case 'function':
|
|
857
|
+
result = callables.apply(context, args);
|
|
858
|
+
if (result === false) return false;
|
|
859
|
+
return 1;
|
|
860
|
+
case 'array':
|
|
861
|
+
for (i=0; i<callables.length; ++i) {
|
|
862
|
+
result = Q.handle(callables[i], context, args);
|
|
863
|
+
if (result === false) return false;
|
|
864
|
+
count += result;
|
|
865
|
+
}
|
|
866
|
+
return count;
|
|
867
|
+
case 'Q.Event':
|
|
868
|
+
return callables.handle.apply(context, args);
|
|
869
|
+
case 'object':
|
|
870
|
+
for (k in callables) {
|
|
871
|
+
result = Q.handle(callables[k], context, args);
|
|
872
|
+
if (result === false) return false;
|
|
873
|
+
count += result;
|
|
874
|
+
}
|
|
875
|
+
return count;
|
|
876
|
+
case 'string':
|
|
877
|
+
var o = Q.extend({}, Q.handle.options, options);
|
|
878
|
+
if (!callables.isUrl()
|
|
879
|
+
&& (callables[0] != '#')
|
|
880
|
+
&& (!o.target || o.target.toLowerCase() === '_self')) {
|
|
881
|
+
// Assume this is not a URL.
|
|
882
|
+
// Try to evaluate the expression, and execute the resulting function
|
|
883
|
+
var c = Q.getObject(callables, context) || Q.getObject(callables);
|
|
884
|
+
return Q.handle(c, context, args);
|
|
885
|
+
}
|
|
886
|
+
// Assume callables is a URL
|
|
887
|
+
if (o.dontReload && Q.info && Q.info.url === callables) {
|
|
888
|
+
return 0;
|
|
889
|
+
}
|
|
890
|
+
var callback = null;
|
|
891
|
+
if (typeof arguments[1] === 'function') {
|
|
892
|
+
// Some syntactic sugar: (url, callback) omitting context, args, options
|
|
893
|
+
callback = arguments[1];
|
|
894
|
+
o = Q.handle.options;
|
|
895
|
+
} else if (arguments[1] && (arguments[3] === undefined)) {
|
|
896
|
+
// Some more syntactic sugar: (url, options, callback) omitting context, args, options
|
|
897
|
+
o = Q.extend({}, Q.handle.options, arguments[1]);
|
|
898
|
+
if (typeof arguments[2] === 'function') {
|
|
899
|
+
callback = arguments[2];
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
o = Q.extend({}, Q.handle.options, options);
|
|
903
|
+
if (o.callback) {
|
|
904
|
+
callback = o.callback;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
var baseUrl = Q.baseUrl();
|
|
908
|
+
var sameDomain = callables.sameDomain(baseUrl);
|
|
909
|
+
if (callables[0] === '#') {
|
|
910
|
+
root.location.hash = callables;
|
|
911
|
+
} else if (o.loadUsingAjax && sameDomain
|
|
912
|
+
&& (!o.target || o.target === true || o.target === '_self')) {
|
|
913
|
+
if (callables.search(baseUrl) === 0) {
|
|
914
|
+
// Use AJAX to refresh the page whenever the request is for a local page
|
|
915
|
+
Q.loadUrl(callables, Q.extend({
|
|
916
|
+
// shouldn't need to re-load responseExtras, they're the same across sessions
|
|
917
|
+
loadExtras: 'session',
|
|
918
|
+
ignoreHistory: false,
|
|
919
|
+
onActivate: function () {
|
|
920
|
+
if (callback) callback();
|
|
921
|
+
}
|
|
922
|
+
}, o)).then(function (a) {
|
|
923
|
+
|
|
924
|
+
}, function (err) {
|
|
925
|
+
if (o && o.handleException) {
|
|
926
|
+
return o.handleException(err);
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
} else if (o.externalLoader) {
|
|
930
|
+
o.externalLoader.apply(this, arguments);
|
|
931
|
+
} else {
|
|
932
|
+
root.location = callables;
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
if (Q.typeOf(o.fields) === 'object') {
|
|
936
|
+
var method = 'POST';
|
|
937
|
+
if (o.method) {
|
|
938
|
+
switch (o.method.toUpperCase()) {
|
|
939
|
+
case "GET":
|
|
940
|
+
case "POST":
|
|
941
|
+
method = o.method;
|
|
942
|
+
break;
|
|
943
|
+
default:
|
|
944
|
+
method = 'POST'; // sadly HTML forms don't support other methods
|
|
945
|
+
break;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
Q.formPost(callables, o.fields, method, {onLoad: o.callback, target: o.target});
|
|
949
|
+
} else {
|
|
950
|
+
if (Q.info && callables === baseUrl) {
|
|
951
|
+
callables+= '/';
|
|
952
|
+
}
|
|
953
|
+
if (!o.target || o.target === true || o.target === '_self') {
|
|
954
|
+
if (root.location.href == callables) {
|
|
955
|
+
root.location.reload(true);
|
|
956
|
+
} else {
|
|
957
|
+
root.location = callables;
|
|
958
|
+
}
|
|
959
|
+
} else {
|
|
960
|
+
root.open(callables, o.target);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
Q.handle.onUrl.handle(callables, o);
|
|
965
|
+
return 1;
|
|
966
|
+
default:
|
|
967
|
+
return 0;
|
|
968
|
+
}
|
|
969
|
+
} catch (exception) {
|
|
970
|
+
if (options && options.handleException) {
|
|
971
|
+
return options.handleException(exception);
|
|
972
|
+
}
|
|
973
|
+
throw exception;
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
Q.handle.options = {
|
|
977
|
+
loadUsingAjax: true,
|
|
978
|
+
externalLoader: null,
|
|
979
|
+
dontReload: false
|
|
980
|
+
};
|
|
981
|
+
setTimeout(function () {
|
|
982
|
+
Q.handle.onUrl = new Q.Event(function () {
|
|
983
|
+
var elements = document.getElementsByClassName('Q_error_message');
|
|
984
|
+
Q.each(elements, function () {
|
|
985
|
+
Q.removeElement(this, true);
|
|
986
|
+
});
|
|
987
|
+
Q.Visual.stopHints();
|
|
988
|
+
}, "Q");
|
|
989
|
+
});
|
|
990
|
+
|
|
809
991
|
/**
|
|
810
992
|
* Iterates over elements in a container, and calls the callback.
|
|
811
993
|
* Use this if you want to avoid problems with loops and closures.
|
|
@@ -3173,12 +3355,8 @@ Q.currentScript = function (stackLevels) {
|
|
|
3173
3355
|
console.warn("parseSrc: could not parse src", src);
|
|
3174
3356
|
return null;
|
|
3175
3357
|
}
|
|
3176
|
-
var src = parts[1] + parts[2].split(/[?#]/)[0];
|
|
3177
|
-
if (!root._Q_currentScript_src) {
|
|
3178
|
-
root._Q_currentScript_src = src;
|
|
3179
|
-
}
|
|
3180
3358
|
return {
|
|
3181
|
-
src:
|
|
3359
|
+
src: parts[1] + parts[2].split(/[?#]/)[0], // clean URL (no query/hash)
|
|
3182
3360
|
srcWithQuerystring: parts[1] + parts[2], // keep full URL
|
|
3183
3361
|
path: parts[1], // directory path
|
|
3184
3362
|
file: parts[2].split(/[?#]/)[0] // filename only
|
|
@@ -4036,180 +4214,6 @@ Q.getter.REQUESTING = 1;
|
|
|
4036
4214
|
Q.getter.WAITING = 2;
|
|
4037
4215
|
Q.getter.THROTTLING = 3;
|
|
4038
4216
|
|
|
4039
|
-
/**
|
|
4040
|
-
* Used for handling callbacks, whether they come as functions,
|
|
4041
|
-
* strings referring to functions (if evaluated), arrays or hashes.
|
|
4042
|
-
* @static
|
|
4043
|
-
* @method handle
|
|
4044
|
-
* @param {Mixed} callables
|
|
4045
|
-
* The callables to call
|
|
4046
|
-
* Can be a function, array of functions, object of functions, Q.Event or URL
|
|
4047
|
-
* If it is a url, simply follow it with options, callback
|
|
4048
|
-
* @param {Function} callback
|
|
4049
|
-
* You can pass a function here if callables is a URL
|
|
4050
|
-
* @param {Object} context
|
|
4051
|
-
* The context in which to call them
|
|
4052
|
-
* @param {Array} args
|
|
4053
|
-
* An array of arguments to pass to them
|
|
4054
|
-
* @param {Object} options
|
|
4055
|
-
* If callables is a url, these are the options to pass to Q.loadUrl, if any. Also can include:
|
|
4056
|
-
* @param {boolean} [options.dontReload=false] if this is true and callback is a url matching current url, it is not reloaded
|
|
4057
|
-
* @param {boolean} [options.loadUsingAjax=true] if this is true and callback is a url, it is loaded using Q.loadUrl
|
|
4058
|
-
* @param {Function} [options.externalLoader] when using loadUsingAjax, you can set this to a function to suppress loading of external websites with Q.handle.
|
|
4059
|
-
* Note: this will still not supress loading of external websites done with other means, such as window.location
|
|
4060
|
-
* @param {Object} [options.fields] optional fields to pass with any method other than "get"
|
|
4061
|
-
* @param {String|Function} [options.callback] if a string, adds a '&Q.callback='+encodeURIComponent(callback) to the querystring. If a function, this is the callback.
|
|
4062
|
-
* @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"
|
|
4063
|
-
* @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.
|
|
4064
|
-
* @param {String|Array} [options.slotNames] a comma-separated list of slot names, or an array of slot names
|
|
4065
|
-
* @param {boolean} [options.quiet] defaults to false. If true, allows visual indications that the request is going to take place.
|
|
4066
|
-
* @param {Function} [options.handleException] pass a function here to handle thrown exceptions instead of rethrowing them
|
|
4067
|
-
* @return {number}
|
|
4068
|
-
* The number of handlers executed
|
|
4069
|
-
*/
|
|
4070
|
-
Q.handle = function _Q_handle(callables, /* callback, */ context, args, options) {
|
|
4071
|
-
try {
|
|
4072
|
-
if (!callables) {
|
|
4073
|
-
return 0;
|
|
4074
|
-
}
|
|
4075
|
-
if (!context) context = root;
|
|
4076
|
-
if (!args) args = [];
|
|
4077
|
-
var i=0, count=0, k, result;
|
|
4078
|
-
if (callables === location) callables = location.href;
|
|
4079
|
-
switch (Q.typeOf(callables)) {
|
|
4080
|
-
case 'function':
|
|
4081
|
-
result = callables.apply(context, args);
|
|
4082
|
-
if (result === false) return false;
|
|
4083
|
-
return 1;
|
|
4084
|
-
case 'array':
|
|
4085
|
-
for (i=0; i<callables.length; ++i) {
|
|
4086
|
-
result = Q.handle(callables[i], context, args);
|
|
4087
|
-
if (result === false) return false;
|
|
4088
|
-
count += result;
|
|
4089
|
-
}
|
|
4090
|
-
return count;
|
|
4091
|
-
case 'Q.Event':
|
|
4092
|
-
return callables.handle.apply(context, args);
|
|
4093
|
-
case 'object':
|
|
4094
|
-
for (k in callables) {
|
|
4095
|
-
result = Q.handle(callables[k], context, args);
|
|
4096
|
-
if (result === false) return false;
|
|
4097
|
-
count += result;
|
|
4098
|
-
}
|
|
4099
|
-
return count;
|
|
4100
|
-
case 'string':
|
|
4101
|
-
var o = Q.extend({}, Q.handle.options, options);
|
|
4102
|
-
if (!callables.isUrl()
|
|
4103
|
-
&& (callables[0] != '#')
|
|
4104
|
-
&& (!o.target || o.target.toLowerCase() === '_self')) {
|
|
4105
|
-
// Assume this is not a URL.
|
|
4106
|
-
// Try to evaluate the expression, and execute the resulting function
|
|
4107
|
-
var c = Q.getObject(callables, context) || Q.getObject(callables);
|
|
4108
|
-
return Q.handle(c, context, args);
|
|
4109
|
-
}
|
|
4110
|
-
// Assume callables is a URL
|
|
4111
|
-
if (o.dontReload && Q.info && Q.info.url === callables) {
|
|
4112
|
-
return 0;
|
|
4113
|
-
}
|
|
4114
|
-
var callback = null;
|
|
4115
|
-
if (typeof arguments[1] === 'function') {
|
|
4116
|
-
// Some syntactic sugar: (url, callback) omitting context, args, options
|
|
4117
|
-
callback = arguments[1];
|
|
4118
|
-
o = Q.handle.options;
|
|
4119
|
-
} else if (arguments[1] && (arguments[3] === undefined)) {
|
|
4120
|
-
// Some more syntactic sugar: (url, options, callback) omitting context, args, options
|
|
4121
|
-
o = Q.extend({}, Q.handle.options, arguments[1]);
|
|
4122
|
-
if (typeof arguments[2] === 'function') {
|
|
4123
|
-
callback = arguments[2];
|
|
4124
|
-
}
|
|
4125
|
-
} else {
|
|
4126
|
-
o = Q.extend({}, Q.handle.options, options);
|
|
4127
|
-
if (o.callback) {
|
|
4128
|
-
callback = o.callback;
|
|
4129
|
-
}
|
|
4130
|
-
}
|
|
4131
|
-
var baseUrl = Q.baseUrl();
|
|
4132
|
-
var sameDomain = callables.sameDomain(baseUrl);
|
|
4133
|
-
if (callables[0] === '#') {
|
|
4134
|
-
root.location.hash = callables;
|
|
4135
|
-
} else if (o.loadUsingAjax && sameDomain
|
|
4136
|
-
&& (!o.target || o.target === true || o.target === '_self')) {
|
|
4137
|
-
if (callables.search(baseUrl) === 0) {
|
|
4138
|
-
// Use AJAX to refresh the page whenever the request is for a local page
|
|
4139
|
-
Q.loadUrl(callables, Q.extend({
|
|
4140
|
-
// shouldn't need to re-load responseExtras, they're the same across sessions
|
|
4141
|
-
loadExtras: 'session',
|
|
4142
|
-
ignoreHistory: false,
|
|
4143
|
-
onActivate: function () {
|
|
4144
|
-
if (callback) callback();
|
|
4145
|
-
}
|
|
4146
|
-
}, o)).then(function (a) {
|
|
4147
|
-
|
|
4148
|
-
}, function (err) {
|
|
4149
|
-
if (o && o.handleException) {
|
|
4150
|
-
return o.handleException(err);
|
|
4151
|
-
}
|
|
4152
|
-
});
|
|
4153
|
-
} else if (o.externalLoader) {
|
|
4154
|
-
o.externalLoader.apply(this, arguments);
|
|
4155
|
-
} else {
|
|
4156
|
-
root.location = callables;
|
|
4157
|
-
}
|
|
4158
|
-
} else {
|
|
4159
|
-
if (Q.typeOf(o.fields) === 'object') {
|
|
4160
|
-
var method = 'POST';
|
|
4161
|
-
if (o.method) {
|
|
4162
|
-
switch (o.method.toUpperCase()) {
|
|
4163
|
-
case "GET":
|
|
4164
|
-
case "POST":
|
|
4165
|
-
method = o.method;
|
|
4166
|
-
break;
|
|
4167
|
-
default:
|
|
4168
|
-
method = 'POST'; // sadly HTML forms don't support other methods
|
|
4169
|
-
break;
|
|
4170
|
-
}
|
|
4171
|
-
}
|
|
4172
|
-
Q.formPost(callables, o.fields, method, {onLoad: o.callback, target: o.target});
|
|
4173
|
-
} else {
|
|
4174
|
-
if (Q.info && callables === baseUrl) {
|
|
4175
|
-
callables+= '/';
|
|
4176
|
-
}
|
|
4177
|
-
if (!o.target || o.target === true || o.target === '_self') {
|
|
4178
|
-
if (root.location.href == callables) {
|
|
4179
|
-
root.location.reload(true);
|
|
4180
|
-
} else {
|
|
4181
|
-
root.location = callables;
|
|
4182
|
-
}
|
|
4183
|
-
} else {
|
|
4184
|
-
root.open(callables, o.target);
|
|
4185
|
-
}
|
|
4186
|
-
}
|
|
4187
|
-
}
|
|
4188
|
-
Q.handle.onUrl.handle(callables, o);
|
|
4189
|
-
return 1;
|
|
4190
|
-
default:
|
|
4191
|
-
return 0;
|
|
4192
|
-
}
|
|
4193
|
-
} catch (exception) {
|
|
4194
|
-
if (options && options.handleException) {
|
|
4195
|
-
return options.handleException(exception);
|
|
4196
|
-
}
|
|
4197
|
-
throw exception;
|
|
4198
|
-
}
|
|
4199
|
-
};
|
|
4200
|
-
Q.handle.options = {
|
|
4201
|
-
loadUsingAjax: true,
|
|
4202
|
-
externalLoader: null,
|
|
4203
|
-
dontReload: false
|
|
4204
|
-
};
|
|
4205
|
-
Q.handle.onUrl = new Q.Event(function () {
|
|
4206
|
-
var elements = document.getElementsByClassName('Q_error_message');
|
|
4207
|
-
Q.each(elements, function () {
|
|
4208
|
-
Q.removeElement(this, true);
|
|
4209
|
-
});
|
|
4210
|
-
Q.Visual.stopHints();
|
|
4211
|
-
}, "Q");
|
|
4212
|
-
|
|
4213
4217
|
/**
|
|
4214
4218
|
* Custom exception constructor
|
|
4215
4219
|
* @class Q.Exception
|