aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/devicemanager/provider/src/main/resources/elasticsearch/plugins/head/src/app/base/boot.js
blob: 46bd9341b89329fb0ad39b607ad4e3192812b657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/**
 * Copyright 2010-2013 Ben Birch
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this software except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
(function() {

	var window = this,
		$ = jQuery;

	function ns( namespace ) {
		return (namespace || "").split(".").reduce( function( space, name ) {
			return space[ name ] || ( space[ name ] = { ns: ns } );
		}, this );
	}

	var app = ns("app");

	var acx = ns("acx");

	/**
	 * object iterator, returns an array with one element for each property of the object
	 * @function
	 */
	acx.eachMap = function(obj, fn, thisp) {
		var ret = [];
		for(var n in obj) {
			ret.push(fn.call(thisp, n, obj[n], obj));
		}
		return ret;
	};

	/**
	 * augments the first argument with the properties of the second and subsequent arguments
	 * like {@link $.extend} except that existing properties are not overwritten
	 */
	acx.augment = function() {
		var args = Array.prototype.slice.call(arguments),
			src = (args.length === 1) ? this : args.shift(),
			augf = function(n, v) {
				if(! (n in src)) {
					src[n] = v;
				}
			};
		for(var i = 0; i < args.length; i++) {
			$.each(args[i], augf);
		}
		return src;
	};

	/**
	 * tests whether the argument is an array
	 * @function
	 */
	acx.isArray = $.isArray;

	/**
	 * tests whether the argument is an object
	 * @function
	 */
	acx.isObject = function (value) {
		return Object.prototype.toString.call(value) == "[object Object]";
	};

	/**
	 * tests whether the argument is a function
	 * @function
	 */
	acx.isFunction = $.isFunction;

	/**
	 * tests whether the argument is a date
	 * @function
	 */
	acx.isDate = function (value) {
		return Object.prototype.toString.call(value) == "[object Date]";
	};

	/**
	 * tests whether the argument is a regexp
	 * @function
	 */
	acx.isRegExp = function (value) {
		return Object.prototype.toString.call(value) == "[object RegExp]";
	};

	/**
	 * tests whether the value is blank or empty
	 * @function
	 */
	acx.isEmpty = function (value, allowBlank) {
		return value === null || value === undefined || ((acx.isArray(value) && !value.length)) || (!allowBlank ? value === '' : false);
	};

	/**
	 * data type for performing chainable geometry calculations<br>
	 * can be initialised x,y | {x, y} | {left, top}
	 */
	acx.vector = function(x, y) {
		return new acx.vector.prototype.Init(x, y);
	};

	acx.vector.prototype = {
		Init : function(x, y) {
			x = x || 0;
			this.y = isFinite(x.y) ? x.y : (isFinite(x.top) ? x.top : (isFinite(y) ? y : 0));
			this.x = isFinite(x.x) ? x.x : (isFinite(x.left) ? x.left : (isFinite(x) ? x : 0));
		},
		
		add : function(i, j) {
			var d = acx.vector(i, j);
			return new this.Init(this.x + d.x, this.y + d.y);
		},
		
		sub : function(i, j) {
			var d = acx.vector(i, j);
			return new this.Init(this.x - d.x, this.y - d.y);
		},
		
		addX : function(i) {
			return new this.Init(this.x + i, this.y);
		},
		
		addY : function(j) {
			return new this.Init(this.x, this.y + j);
		},

		mod : function(fn) { // runs a function against the x and y values
			return new this.Init({x: fn.call(this, this.x, "x"), y: fn.call(this, this.y, "y")});
		},
		
		/** returns true if this is within a rectangle formed by the points p and q */
		within : function(p, q) {
			return ( this.x >= ((p.x < q.x) ? p.x : q.x) && this.x <= ((p.x > q.x) ? p.x : q.x) &&
					this.y >= ((p.y < q.y) ? p.y : q.y) && this.y <= ((p.y > q.y) ? p.y : q.y) );
		},
		
		asOffset : function() {
			return { top: this.y, left: this.x };
		},
		
		asSize : function() {
			return { height: this.y, width: this.x };
		}
	};

	acx.vector.prototype.Init.prototype = acx.vector.prototype;

	/**
	 * short cut functions for working with vectors and jquery.
	 * Each function returns the equivalent jquery value in a two dimentional vector
	 */
	$.fn.vSize = function() { return acx.vector(this.width(), this.height()); };
	$.fn.vOuterSize = function(margin) { return acx.vector(this.outerWidth(margin), this.outerHeight(margin)); };
	$.fn.vScroll = function() { return acx.vector(this.scrollLeft(), this.scrollTop()); };
	$.fn.vOffset = function() { return acx.vector(this.offset()); };
	$.fn.vPosition = function() { return acx.vector(this.position()); };
	$.Event.prototype.vMouse = function() { return acx.vector(this.pageX, this.pageY); };

	/**
	 * object extensions (ecma5 compatible)
	 */
	acx.augment(Object, {
		keys: function(obj) {
			var ret = [];
			for(var n in obj) if(Object.prototype.hasOwnProperty.call(obj, n)) ret.push(n);
			return ret;
		}
	});

	/**
	 * Array prototype extensions
	 */
	acx.augment(Array.prototype, {
		'contains' : function(needle) {
			return this.indexOf(needle) !== -1;
		},

		// returns a new array consisting of all the members that are in both arrays
		'intersection' : function(b) {
			var ret = [];
			for(var i = 0; i < this.length; i++) {
				if(b.contains(this[i])) {
					ret.push(this[i]);
				}
			}
			return ret;
		},
		
		'remove' : function(value) {
			var i = this.indexOf(value);
			if(i !== -1) {
				this.splice(i, 1);
			}
		}
	});

	/**
	 * String prototype extensions
	 */
	acx.augment(String.prototype, {
		'contains' : function(needle) {
			return this.indexOf(needle) !== -1;
		},

		'equalsIgnoreCase' : function(match) {
			return this.toLowerCase() === match.toLowerCase();
		},

		'escapeHtml' : function() {
			return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
		},

		'escapeJS' : function() {
			var meta = {'"':'\\"', '\\':'\\\\', '/':'\\/', '\b':'\\b', '\f':'\\f', '\n':'\\n', '\r':'\\r', '\t':'\\t'},
				xfrm = function(c) { return meta[c] || "\\u" + c.charCodeAt(0).toString(16).zeroPad(4); };
			return this.replace(new RegExp('(["\\\\\x00-\x1f\x7f-\uffff])', 'g'), xfrm);
		},

		'escapeRegExp' : function() {
			var ret = "", esc = "\\^$*+?.()=|{,}[]-";
			for ( var i = 0; i < this.length; i++) {
				ret += (esc.contains(this.charAt(i)) ? "\\" : "") + this.charAt(i);
			}
			return ret;
		},
		
		'zeroPad' : function(len) {
			return ("0000000000" + this).substring(this.length - len + 10);
		}
	});

	$.fn.forEach = Array.prototype.forEach;

	// joey / jquery integration
	$.joey = function( obj ) {
		return $( window.joey( obj ) );
	};

	window.joey.plugins.push( function( obj ) {
		if( obj instanceof jQuery ) {
			return obj[0];
		}
	});

})();