-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
247 lines (222 loc) · 9.49 KB
/
config.js
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
/* JavaScript Boilerplate helper file *
* @version 1.2
* GIT URL - https://github.com/mdarif/JavaScript-Boilerplate
* Author - Mohammed Arif
*/
(function (JSB, $, undefined) {
'use strict';
/*
* Singletons serve as a namespace provider which isolate implementation code
* from the global namespace so as to provide a single point of access for functions,
* this is useful for organizing code into logical sections.
* It is possible to put parentheses around this structure to instantiate it immediately after it's parsed.
* This way it's always present when the script is executed and doesn't have to be instantiated separately.
*/
JSB.helper = (function () {
function _helper() {
/**
* In non-strict mode, 'this' is bound to the global scope when it isn't bound to anything else.
* In strict mode it is 'undefined'. That makes it an error to use it outside of a method.
*/
/*jshint validthis: true */
var _this = this,
/*
* This method return the element using javaScript getElementById() method.
* This is the private method not meant for use as a public method.
*/
id = function (el) {
return document.getElementById(el);
},
/*
* Store information in a cookie
* Accept three param name, value, days
*/
setCookie = function (name, value, days) {
var date = "",
expires = "";
if (days) {
date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + expires + "; path=/";
},
/*
* Get cookie from user machine
* Accept one parameters name
* name : name of the cookie
*/
getCookie = function (name) {
var nameEQ = name + "=",
i,
ca = document.cookie.split(';');
for (i = 0; i < ca.length; i += 1) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length, c.length);
}
}
return null;
},
/*
* Erase or delete cookie from user machine
* Accept one parameters name
* name : name of the cookie
*/
removeCookie = function (name) {
setCookie(name, "", -1);
};
/*
* Replace multiple value in a single string.
* Accept two parameters str, hash
* str : String on which replace operation is to be performed
* hash : JSON object contain string to be replaced with there replaced value
* Return the new string at the end.
*/
this.multiReplace = function (str, hash) {
var key;
for (key in hash) {
if (Object.prototype.hasOwnProperty.call(hash, key)) {
str = str.replace(new RegExp(key, 'g'), hash[key]);
}
}
return str;
};
/*
* Set the CSS on a particular element
* Accept two parameters el, styles
* el : The name of element on which CSS is to be apply.
* styles : Various CSS property with their values. Accept data in JSON format
* This method calls a private method setStyle
*/
this.setCSS = function (el, styles) {
var prop;
for (prop in styles) {
if (styles.hasOwnProperty(prop)) {
_this.setStyle(el, prop, styles[prop]);
}
}
};
/*
* Apply the CSS to the given element
* Accept three parameters elements, prop, val
* element : The element on which CSS is to be apply.
* This method will automatically search for element using getElementById() method.
* prop : CSS properties
* val : Vale for CSS property
*/
this.setStyle = function (el, prop, val) {
id(el).style[prop] = val;
};
/*
* Check if the given element has given class assign or not.
* Accept two parameters el, name
* el : Element for testing. This method will search for element using JavaScript getElementById() method.
* name : name of class to be test
* This method return true and false
*/
this.hasClass = function (el, name) {
el = id(el);
return new RegExp('(\\s|^)' + name + '(\\s|$)').test(el.className);
};
/*
* Add class to the given element
* Accept two parameters el, name
* el : element on which class to be add
* name : name of class
*/
this.addClass = function (el, name) {
if (!_this.hasClass(el, name)) {
el = id(el);
el.className += (el.className ? ' ' : '') + name;
}
};
/*
* Remove class from given element
* Accept two parameters el, name
* el : element from which class is to be remove
* name : name of the class to be remove
*/
this.removeClass = function (el, name) {
if (_this.hasClass(el, name)) {
el = id(el);
el.className = el.className.replace(new RegExp('(\\s|^)' + name + '(\\s|$)'), ' ').replace(/^\s+|\s+$/g, '');
}
};
/*
* This method will check for blank value in the provided string
* This will return true if provided string contain blank value and false if not
*/
this.isBlank = function (string) {
var isNonblank_re = /\S/;
return String(string).search(isNonblank_re) === -1;
};
/*
* Store information to client machine
* Accept two parameters name, value
* name : name of the localStorage
* value : value for the localStorage
* Store information in HTML5 localstorage if available
* else store information in cookie
*/
this.setInfo = function (name, value) {
if (typeof window.localStorage !== 'undefined') {
localStorage.setItem(name, value);
} else {
setCookie(name, value);
}
};
/*
* Get information from client machine
* Accept two parameters name, checkCookie
* name : name of the localstorage
* checkCookie : This will either be true or false.
* If set to true then scan cookie even if user system support localStorage
* Get information for HTML5 localstorage if available
* else get information from cookie
*/
this.getInfo = function (name, checkCookie) {
var value = "";
if (typeof window.localStorage !== 'undefined') {
value = localStorage.getItem(name);
} else {
value = getCookie(name);
}
if (checkCookie === true) {
value = getCookie(name);
}
return value;
};
/*
* Remove information from client machine
* Accept two parameters name, checkCookie
* name : name of the localstorage for removing it permanently
* checkCookie : This will either be true or false.
* If set to true then scan cookie and remove if found even if user system support localStorage
* Remove information for HTML5 localstorage if available
* else remove information from cookie
*/
this.removeInfo = function (name, checkCookie) {
if (typeof window.localStorage !== 'undefined') {
localStorage.removeItem(name);
} else {
removeCookie(name);
}
if (checkCookie === true) {
removeCookie(name);
}
};
this.init = function () {
return this; /*returning this from a method is a common way to allow "chaining" of methods together*/
};
return this.init(); /*this refer to JSB.helper.init()*/
}
return new _helper(); /*creating a new object of helper rather then a funtion*/
}());
/**
* Check to evaluate whether 'JSB' exists in the global namespace - if not, assign window.JSB an object literal
*/
}(window.JSB = window.JSB || {}, jQuery));