ninjs-framework 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.bundle/config +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/Rakefile +76 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/ninjs-framework.rb +164 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine-html.js +190 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.css +166 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine.js +2476 -0
- data/lib/ninjs-framework/assets/jasmine/jasmine_favicon.png +0 -0
- data/lib/ninjs-framework/core/.core.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.existence.pdoc.yaml +12 -0
- data/lib/ninjs-framework/core/.extend.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/.nin.pdoc.yaml +0 -0
- data/lib/ninjs-framework/core/application.js +17 -0
- data/lib/ninjs-framework/core/dom.js +164 -0
- data/lib/ninjs-framework/core/existence.js +60 -0
- data/lib/ninjs-framework/core/extend.js +14 -0
- data/lib/ninjs-framework/core/module.js +66 -0
- data/lib/ninjs-framework/core/nin.js +5 -0
- data/lib/ninjs-framework/extensions/jquery.elements.js +60 -0
- data/lib/ninjs-framework/templates/application.js.erb +3 -0
- data/lib/ninjs-framework/templates/autoload.js.erb +3 -0
- data/lib/ninjs-framework/templates/core.js.erb +3 -0
- data/lib/ninjs-framework/templates/dependency.js.erb +3 -0
- data/lib/ninjs-framework/templates/jasmine.yml.erb +75 -0
- data/lib/ninjs-framework/templates/test-index.html.erb +51 -0
- data/lib/ninjs-framework/utilities/all.js +5 -0
- data/lib/ninjs-framework/utilities/array.js +29 -0
- data/lib/ninjs-framework/utilities/cookie.js +59 -0
- data/lib/ninjs-framework/utilities/css.js +51 -0
- data/lib/ninjs-framework/utilities/number.js +11 -0
- data/lib/ninjs-framework/utilities/string.js +61 -0
- data/spec/fixtures/myapp.js +530 -0
- data/spec/fixtures/nin.js +297 -0
- data/spec/fixtures/ninjs.conf +9 -0
- data/spec/fixtures/test.elements.js +3 -0
- data/spec/fixtures/test.js +14 -0
- data/spec/fixtures/test.model.js +3 -0
- data/spec/fixtures/test.module.js +10 -0
- data/spec/fixtures/utilities.js +211 -0
- data/spec/javascripts/application_spec.js +22 -0
- data/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/javascripts/existence_spec.js +71 -0
- data/spec/javascripts/extension_spec.js +22 -0
- data/spec/javascripts/helpers/SpecHelper.js +3 -0
- data/spec/javascripts/module_spec.js +30 -0
- data/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/javascripts/support/jasmine.yml +75 -0
- data/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/ninjs_framework_spec.rb +121 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/tmp/Rakefile +76 -0
- data/spec/tmp/application/myapp.js +530 -0
- data/spec/tmp/application/test.js +14 -0
- data/spec/tmp/elements/test.elements.js +3 -0
- data/spec/tmp/lib/nin.js +297 -0
- data/spec/tmp/lib/utilities.js +211 -0
- data/spec/tmp/models/test.model.js +3 -0
- data/spec/tmp/modules/test.module.js +10 -0
- data/spec/tmp/ninjs.conf +9 -0
- data/spec/tmp/spec/index.html +51 -0
- data/spec/tmp/spec/javascripts/application_spec.js +22 -0
- data/spec/tmp/spec/javascripts/array_utility_spec.js +49 -0
- data/spec/tmp/spec/javascripts/existence_spec.js +71 -0
- data/spec/tmp/spec/javascripts/extension_spec.js +22 -0
- data/spec/tmp/spec/javascripts/module_spec.js +30 -0
- data/spec/tmp/spec/javascripts/string_utility_spec.js +85 -0
- data/spec/tmp/spec/javascripts/support/jasmine-html.js +190 -0
- data/spec/tmp/spec/javascripts/support/jasmine.css +166 -0
- data/spec/tmp/spec/javascripts/support/jasmine.js +2476 -0
- data/spec/tmp/spec/javascripts/support/jasmine.yml.erb +75 -0
- data/spec/tmp/spec/javascripts/support/jasmine_config.rb +23 -0
- data/spec/tmp/spec/javascripts/support/jasmine_favicon.png +0 -0
- data/spec/tmp/spec/javascripts/support/jasmine_runner.rb +32 -0
- metadata +285 -0
@@ -0,0 +1,297 @@
|
|
1
|
+
is_defined = function(suspect) {
|
2
|
+
return ((suspect === undefined) || (suspect === null)) ? false : true;
|
3
|
+
};
|
4
|
+
|
5
|
+
is_undefined = function(suspect) {
|
6
|
+
return (suspect === undefined) ? true : false;
|
7
|
+
};
|
8
|
+
|
9
|
+
is_typeof = function(type, suspect) {
|
10
|
+
if (is_undefined(type)) {
|
11
|
+
throw new SyntaxError("is_typeof(Type, suspect): type is undefined");
|
12
|
+
}
|
13
|
+
if (is_undefined(suspect)) {
|
14
|
+
throw new SyntaxError("is_typeof(Type, suspect): suspect is undefined");
|
15
|
+
}
|
16
|
+
|
17
|
+
return (suspect.constructor == type) ? true : false;
|
18
|
+
};
|
19
|
+
|
20
|
+
is_numeric = function(suspect) {
|
21
|
+
if(is_typeof(Number, suspect)) {
|
22
|
+
return true;
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
var pattern = /^-?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
26
|
+
return pattern.test(suspect);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
is_string = function(suspect) {
|
31
|
+
return is_typeof(String, suspect);
|
32
|
+
};
|
33
|
+
|
34
|
+
is_array = function(suspect) {
|
35
|
+
return is_typeof(Array, suspect);
|
36
|
+
};
|
37
|
+
|
38
|
+
is_number = function(suspect) {
|
39
|
+
return is_typeof(Number, suspect);
|
40
|
+
};
|
41
|
+
|
42
|
+
is_date = function(suspect) {
|
43
|
+
return is_typeof(Date, suspect);
|
44
|
+
};
|
45
|
+
|
46
|
+
is_bool = function(suspect) {
|
47
|
+
return is_typeof(Boolean, suspect);
|
48
|
+
};
|
49
|
+
|
50
|
+
is_regex = function(suspect) {
|
51
|
+
return is_typeof(RegExp, suspect);
|
52
|
+
};
|
53
|
+
|
54
|
+
is_empty = function(suspect) {
|
55
|
+
return suspect.length === 0;
|
56
|
+
};
|
57
|
+
|
58
|
+
is_not_empty = function(suspect) {
|
59
|
+
return suspect.length >= 1;
|
60
|
+
};
|
61
|
+
unless = function(expression, callback, fallback) {
|
62
|
+
if (is_undefined(callback)) {
|
63
|
+
throw new SyntaxError("unless(expression, callback[, fallback]): callback is undefined");
|
64
|
+
}
|
65
|
+
|
66
|
+
if (!!!expression) {
|
67
|
+
callback.call(this);
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
if (is_defined(fallback)) {
|
71
|
+
fallback.call(this);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
};
|
75
|
+
var DomReady = window.DomReady = {},
|
76
|
+
userAgent = navigator.userAgent.toLowerCase(),
|
77
|
+
browser = {
|
78
|
+
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
|
79
|
+
safari: /webkit/.test(userAgent),
|
80
|
+
opera: /opera/.test(userAgent),
|
81
|
+
msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),
|
82
|
+
mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))
|
83
|
+
},
|
84
|
+
readyBound = false,
|
85
|
+
isReady = false,
|
86
|
+
readyList = [];
|
87
|
+
|
88
|
+
|
89
|
+
function domReady() {
|
90
|
+
if(!isReady) {
|
91
|
+
isReady = true;
|
92
|
+
|
93
|
+
if(readyList) {
|
94
|
+
var length = readyList.length;
|
95
|
+
for(var fn = 0; fn < length; fn++) {
|
96
|
+
readyList[fn].call(window, []);
|
97
|
+
}
|
98
|
+
|
99
|
+
readyList = [];
|
100
|
+
}
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
function addLoadEvent(func) {
|
105
|
+
var oldonload = window.onload;
|
106
|
+
if (typeof window.onload != 'function') {
|
107
|
+
window.onload = func;
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
window.onload = function() {
|
111
|
+
if (oldonload) {
|
112
|
+
oldonload();
|
113
|
+
}
|
114
|
+
func();
|
115
|
+
}
|
116
|
+
}
|
117
|
+
};
|
118
|
+
|
119
|
+
function bindReady() {
|
120
|
+
if(readyBound) {
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
|
124
|
+
readyBound = true;
|
125
|
+
|
126
|
+
if (document.addEventListener && !browser.opera) {
|
127
|
+
document.addEventListener("DOMContentLoaded", domReady, false);
|
128
|
+
}
|
129
|
+
|
130
|
+
if (browser.msie && window == top) (function() {
|
131
|
+
if (isReady) return;
|
132
|
+
try {
|
133
|
+
document.documentElement.doScroll("left");
|
134
|
+
}
|
135
|
+
catch(error) {
|
136
|
+
setTimeout(arguments.callee, 0);
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
domReady();
|
140
|
+
})();
|
141
|
+
|
142
|
+
if(browser.opera) {
|
143
|
+
document.addEventListener( "DOMContentLoaded", function () {
|
144
|
+
if (isReady) return;
|
145
|
+
for (var i = 0; i < document.styleSheets.length; i++)
|
146
|
+
if (document.styleSheets[i].disabled) {
|
147
|
+
setTimeout( arguments.callee, 0 );
|
148
|
+
return;
|
149
|
+
}
|
150
|
+
domReady();
|
151
|
+
}, false);
|
152
|
+
}
|
153
|
+
|
154
|
+
if(browser.safari) {
|
155
|
+
var numStyles;
|
156
|
+
(function(){
|
157
|
+
if (isReady) return;
|
158
|
+
|
159
|
+
if (document.readyState != "loaded" && document.readyState != "complete") {
|
160
|
+
setTimeout( arguments.callee, 0 );
|
161
|
+
return;
|
162
|
+
}
|
163
|
+
|
164
|
+
if (numStyles === undefined) {
|
165
|
+
var links = document.getElementsByTagName("link");
|
166
|
+
for (var i=0; i < links.length; i++) {
|
167
|
+
if(links[i].getAttribute('rel') == 'stylesheet') {
|
168
|
+
numStyles++;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
|
172
|
+
var styles = document.getElementsByTagName("style");
|
173
|
+
numStyles += styles.length;
|
174
|
+
}
|
175
|
+
|
176
|
+
if (document.styleSheets.length != numStyles) {
|
177
|
+
setTimeout( arguments.callee, 0 );
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
|
181
|
+
domReady();
|
182
|
+
})();
|
183
|
+
}
|
184
|
+
|
185
|
+
addLoadEvent(domReady);
|
186
|
+
};
|
187
|
+
|
188
|
+
DomReady.ready = function(fn, args) {
|
189
|
+
bindReady();
|
190
|
+
|
191
|
+
if (isReady) {
|
192
|
+
fn.call(window, []);
|
193
|
+
}
|
194
|
+
else {
|
195
|
+
readyList.push( function() { return fn.call(window, []); } );
|
196
|
+
}
|
197
|
+
};
|
198
|
+
|
199
|
+
NinjsDOM = function() {
|
200
|
+
this.cached_selectors = {};
|
201
|
+
};
|
202
|
+
|
203
|
+
NinjsDOM.prototype.ready = function(fn, args) {
|
204
|
+
bindReady();
|
205
|
+
|
206
|
+
if (isReady) {
|
207
|
+
fn.call(window, args || []);
|
208
|
+
}
|
209
|
+
else {
|
210
|
+
readyList.push( function() { return fn.call(window, args || []); } );
|
211
|
+
}
|
212
|
+
};
|
213
|
+
|
214
|
+
bindReady();
|
215
|
+
NinjsModule = function(name) {
|
216
|
+
this.dom = new NinjsDOM(this);
|
217
|
+
this.data = {};
|
218
|
+
this.name = name;
|
219
|
+
};
|
220
|
+
|
221
|
+
NinjsModule.prototype.actions = function() {};
|
222
|
+
|
223
|
+
NinjsModule.prototype.run = function() {
|
224
|
+
var mod = this;
|
225
|
+
this.dom.ready(function() {
|
226
|
+
mod.execute();
|
227
|
+
});
|
228
|
+
};
|
229
|
+
|
230
|
+
NinjsModule.prototype.execute = function() {
|
231
|
+
this.actions();
|
232
|
+
};
|
233
|
+
|
234
|
+
NinjsModule.prototype.elements = function(elements) {
|
235
|
+
if (is_undefined(elements)) {
|
236
|
+
if (is_typeof(Object, elements)) {
|
237
|
+
throw new SyntaxError("NinjsModule.elements(elements): elements is undefined");
|
238
|
+
}
|
239
|
+
else if (is_string(elements)) {
|
240
|
+
throw new SyntaxError("NinjsModule.elements(name): name is undefined");
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
if (is_string(elements)) {
|
245
|
+
var name = elements;
|
246
|
+
return this.dom.cached_selectors[name];
|
247
|
+
}
|
248
|
+
else {
|
249
|
+
var dom = this.dom;
|
250
|
+
dom.ready(function() {
|
251
|
+
for(var key in elements) {
|
252
|
+
if (elements.hasOwnProperty(key)) {
|
253
|
+
dom.cached_selectors[key] = elements[key];
|
254
|
+
}
|
255
|
+
}
|
256
|
+
});
|
257
|
+
}
|
258
|
+
};
|
259
|
+
|
260
|
+
NinjsModule.prototype.set_data = function(key, value) {
|
261
|
+
if (is_undefined(key)) {
|
262
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): key is undefined');
|
263
|
+
}
|
264
|
+
|
265
|
+
if (is_typeof(String, key) && is_undefined(value)) {
|
266
|
+
throw new SyntaxError('NinjsModule.set_data(key, value): value is undefined');
|
267
|
+
}
|
268
|
+
|
269
|
+
if (is_typeof(String, key)) {
|
270
|
+
this.data[key] = value;
|
271
|
+
}
|
272
|
+
else if (is_typeof(Object, key)) {
|
273
|
+
var data = key;
|
274
|
+
for(var property in data) {
|
275
|
+
this.data[property] = data[property];
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
return this;
|
280
|
+
};
|
281
|
+
NinjsApplication = function() {};
|
282
|
+
|
283
|
+
NinjsApplication.prototype.add_module = function(name) {
|
284
|
+
if (is_undefined(name)) {
|
285
|
+
throw new SyntaxError("NinjsApplication.add_module(name): name is undefined");
|
286
|
+
}
|
287
|
+
|
288
|
+
if (is_defined(this[name])) {
|
289
|
+
throw new SyntaxError("NinjsApplication.add_module(name): '" + name + "' already declared");
|
290
|
+
}
|
291
|
+
|
292
|
+
if (this.name === name) {
|
293
|
+
throw new SyntaxError("NinjsApplication.add_module(name): a module cannot have the same name as the application");
|
294
|
+
}
|
295
|
+
|
296
|
+
return this[name] = new NinjsModule(name);
|
297
|
+
};
|
@@ -0,0 +1,211 @@
|
|
1
|
+
Array.prototype.is_empty = function() {
|
2
|
+
return is_empty(this);
|
3
|
+
};
|
4
|
+
|
5
|
+
Array.prototype.not_empty = function() {
|
6
|
+
return is_not_empty(this);
|
7
|
+
};
|
8
|
+
|
9
|
+
Array.prototype.each = function(callback) {
|
10
|
+
if(is_undefined(callback)) {
|
11
|
+
throw new SyntaxError("Array.each(callback): callback is undefined");
|
12
|
+
}
|
13
|
+
|
14
|
+
for (var i = 0; i < this.length; i++) {
|
15
|
+
var args = [this[i], i];
|
16
|
+
callback.apply(this, args);
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
Array.prototype.contains = function(suspect) {
|
21
|
+
var matches = [];
|
22
|
+
this.each(function(value, index) {
|
23
|
+
if(value === suspect) {
|
24
|
+
matches.push(index);
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
return matches.not_empty() ? matches : false;
|
29
|
+
};
|
30
|
+
String.prototype.is_empty = function() {
|
31
|
+
return (this.length < 1) ? true : false;
|
32
|
+
};
|
33
|
+
|
34
|
+
String.prototype.not_empty = function() {
|
35
|
+
return (this.length < 1) ? false : true;
|
36
|
+
};
|
37
|
+
|
38
|
+
String.prototype.is_numeric = function() {
|
39
|
+
var pattern = /^(\.|-)?\d+(?:\.\d*)?(?:e[+\-]?\d+)?$/i;
|
40
|
+
return pattern.test(this);
|
41
|
+
};
|
42
|
+
|
43
|
+
String.prototype.trim = function() {
|
44
|
+
return this.replace(/^\s+|\s+$/g, "");
|
45
|
+
};
|
46
|
+
|
47
|
+
String.prototype.ltrim = function() {
|
48
|
+
return this.replace(/^\s+/,"");
|
49
|
+
};
|
50
|
+
|
51
|
+
String.prototype.rtrim = function() {
|
52
|
+
return this.replace(/\s+$/,"");
|
53
|
+
};
|
54
|
+
|
55
|
+
String.prototype.each = function(callback) {
|
56
|
+
if(is_undefined(callback)) {
|
57
|
+
throw new SyntaxError("String.each(callback): callback is undefined");
|
58
|
+
}
|
59
|
+
|
60
|
+
for (var i = 0; i < this.length; i++) {
|
61
|
+
var args = [this.charAt(i), i];
|
62
|
+
callback.apply(this, args);
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
String.prototype.capitalize = function() {
|
67
|
+
return this.substr(0, 1).toUpperCase() + this.substr(1);
|
68
|
+
};
|
69
|
+
|
70
|
+
String.prototype.reverse = function() {
|
71
|
+
return this.split('').reverse().join('');
|
72
|
+
};
|
73
|
+
|
74
|
+
String.prototype.to_n = function() {
|
75
|
+
return parseFloat(this);
|
76
|
+
};
|
77
|
+
|
78
|
+
String.prototype.pluck = function(needle) {
|
79
|
+
var pattern = new RegExp(needle, 'g');
|
80
|
+
return this.replace(pattern, '');
|
81
|
+
};
|
82
|
+
|
83
|
+
String.prototype.single_space = function() {
|
84
|
+
var no_hard_spaces = this.replace(/\ \;/g, ' ');
|
85
|
+
return no_hard_spaces.replace(/\s+/g, ' ');
|
86
|
+
};
|
87
|
+
|
88
|
+
String.prototype.compress = function() {
|
89
|
+
return this.replace(/\s+/g, '');
|
90
|
+
};
|
91
|
+
Number.prototype.to_hex = function() {
|
92
|
+
if (this === 0) {
|
93
|
+
return "00";
|
94
|
+
}
|
95
|
+
|
96
|
+
var chars = "0123456789ABCDEF";
|
97
|
+
var n = Math.max(0, this);
|
98
|
+
n = Math.min(n, 255);
|
99
|
+
n = Math.round(n);
|
100
|
+
return chars.charAt((n - n % 16)/16) + chars.charAt(n % 16);
|
101
|
+
};
|
102
|
+
var CSS = function() {};
|
103
|
+
|
104
|
+
CSS.rgb2hex = function(r,g,b) {
|
105
|
+
pattern = /(\d{1,3})\,\s?(\d{1,3})\,\s?(\d{1,3})/gi;
|
106
|
+
var rgb;
|
107
|
+
if (is_typeof(String, r)) {
|
108
|
+
rgb = r.match(pattern);
|
109
|
+
rgb = rgb[0].split(',');
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
rgb = false;
|
113
|
+
}
|
114
|
+
|
115
|
+
if (rgb) {
|
116
|
+
r = parseInt(rgb[0], 10);
|
117
|
+
g = parseInt(rgb[1], 10);
|
118
|
+
b = parseInt(rgb[2], 10);
|
119
|
+
}
|
120
|
+
else {
|
121
|
+
r = parseInt(r, 10);
|
122
|
+
g = parseInt(g, 10);
|
123
|
+
b = parseInt(b, 10);
|
124
|
+
}
|
125
|
+
return '#' + r.to_hex() + g.to_hex() + b.to_hex();
|
126
|
+
};
|
127
|
+
|
128
|
+
CSS.hex2rgb = function(hex) {
|
129
|
+
hex = hex.replace('#', '');
|
130
|
+
|
131
|
+
var rgb = [];
|
132
|
+
|
133
|
+
rgb[0] = parseInt(hex.substring(0,2), 16);
|
134
|
+
rgb[1] = parseInt(hex.substring(2,4), 16);
|
135
|
+
rgb[2] = parseInt(hex.substring(4,6), 16);
|
136
|
+
|
137
|
+
rgb.red = rgb[0];
|
138
|
+
rgb.green = rgb[1];
|
139
|
+
rgb.blue = rgb[2];
|
140
|
+
|
141
|
+
rgb.to_s = function() {
|
142
|
+
return 'rgb(' + rgb.red +', ' + rgb.green + ', ' + rgb.blue + ')';
|
143
|
+
};
|
144
|
+
|
145
|
+
rgb.each = function(callback) {
|
146
|
+
for (var i = 0; i < 3; i++) {
|
147
|
+
callback.call(this, rgb[i]);
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
151
|
+
return rgb;
|
152
|
+
};
|
153
|
+
var Cookie = function(name, data, exp) {
|
154
|
+
if (is_undefined(name)) {
|
155
|
+
throw new SyntaxError('new Cookie(name, data[, exp]): name is undefined');
|
156
|
+
}
|
157
|
+
|
158
|
+
function set_exp(days) {
|
159
|
+
var date = new Date();
|
160
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
161
|
+
var expires = "; expires=" + date.toGMTString();
|
162
|
+
}
|
163
|
+
|
164
|
+
this.name = name;
|
165
|
+
|
166
|
+
unless(this.read(), function() {
|
167
|
+
if (is_undefined(data)) {
|
168
|
+
this.data = '';
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
this.data = data;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (is_defined(days)) {
|
175
|
+
this.exp = set_exp(days);
|
176
|
+
}
|
177
|
+
else {
|
178
|
+
this.exp = '';
|
179
|
+
}
|
180
|
+
});
|
181
|
+
|
182
|
+
this.save();
|
183
|
+
};
|
184
|
+
|
185
|
+
Cookie.prototype.save = function() {
|
186
|
+
document.cookie = this.name + "=" + this.data + this.exp + "; path=/";
|
187
|
+
};
|
188
|
+
|
189
|
+
Cookie.prototype.read = function() {
|
190
|
+
var nameEQ = this.name + "=";
|
191
|
+
var ca = document.cookie.split(';');
|
192
|
+
var length = ca.length;
|
193
|
+
|
194
|
+
for (var i = 0; i < length; i++) {
|
195
|
+
var c = ca[i];
|
196
|
+
while (c.charAt(0) == ' ') {
|
197
|
+
c = c.substring(1, c.length);
|
198
|
+
}
|
199
|
+
if (c.indexOf(nameEQ) === 0) {
|
200
|
+
return c.substring(nameEQ.length,c.length);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
return null;
|
205
|
+
};
|
206
|
+
|
207
|
+
Cookie.prototype.remove = function() {
|
208
|
+
this.data = '';
|
209
|
+
this.exp = -1;
|
210
|
+
this.save();
|
211
|
+
};
|