-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhate.jquery.js
More file actions
56 lines (51 loc) · 2.54 KB
/
hate.jquery.js
File metadata and controls
56 lines (51 loc) · 2.54 KB
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
(function(jQuery){//JQuery Plugin##################
var $this = undefined,
_openCloseDelimiters = ['{{', '}}'],
//##################################################################################################################
_init = function(){
jQuery.fn.hate = _hate;
},
//##################################################################################################################
_setOptions = function(openCloseDelimiters){
var openCloseDelimiters = openCloseDelimiters;
if(openCloseDelimiters.length &&
openCloseDelimiters.length === 2 &&
typeof openCloseDelimiters[0] === 'string' &&
typeof openCloseDelimiters[1] === 'string') _openCloseDelimiters = openCloseDelimiters;
},
//##################################################################################################################
_process = function(collection){
var collection = collection,
tempalteStr = $this.html(),
openDmtr = _openCloseDelimiters[0],
closeDmtr = _openCloseDelimiters[1],
collectionLength, i, j;
if(!collection.length){
for(i in collection) tempalteStr = tempalteStr.replace(new RegExp(openDmtr + i + closeDmtr, 'g'), collection[i]);
}else{
collectionLength = collection.length;
for(i = 0; i < collectionLength; i+=1)
for(j in collection[i])
tempalteStr = tempalteStr.replace(regEx.compile(openDmtr + j + closeDmtr, 'g'), collection[i][j]);
}
$this.html(tempalteStr);
},
//##################################################################################################################
_compile = function(optionsOrObjectArrOrObj){
var collection = optionsOrObjectArrOrObj;
if(collection.hasOwnProperty('openCloseDelimiters')) return _setOptions(collection.openCloseDelimiters);
(/^\[object Array]|\[object Object]$/).test(Object.prototype.toString.call(collection)) &&
(!collection.length || collection.length && typeof collection[0] === 'object')?
_process(collection)
: $this.html('Error: Invalid hate.jquery.js params. Expecting Object or Array of Objects.');
},
//##################################################################################################################
_hate = function(optionsOrObjectArrOrObj){
$this = this;
_compile(optionsOrObjectArrOrObj);
return this;
};
//##################################################################################################################
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_init();
}(jQuery));