semantic_ui_rails 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +1 -0
- data/app/assets/fonts/semantic/icons.eot +0 -0
- data/app/assets/fonts/semantic/icons.svg +450 -0
- data/app/assets/fonts/semantic/icons.ttf +0 -0
- data/app/assets/fonts/semantic/icons.woff +0 -0
- data/app/assets/images/semantic/loader-large-inverted.gif +0 -0
- data/app/assets/images/semantic/loader-large.gif +0 -0
- data/app/assets/images/semantic/loader-medium-inverted.gif +0 -0
- data/app/assets/images/semantic/loader-medium.gif +0 -0
- data/app/assets/images/semantic/loader-mini-inverted.gif +0 -0
- data/app/assets/images/semantic/loader-mini.gif +0 -0
- data/app/assets/images/semantic/loader-small-inverted.gif +0 -0
- data/app/assets/images/semantic/loader-small.gif +0 -0
- data/app/assets/javascript/semantic/accordion.js +411 -0
- data/app/assets/javascript/semantic/behavior/api.js +666 -0
- data/app/assets/javascript/semantic/behavior/colorize.js +271 -0
- data/app/assets/javascript/semantic/behavior/form.js +703 -0
- data/app/assets/javascript/semantic/behavior/state.js +752 -0
- data/app/assets/javascript/semantic/chatroom.js +766 -0
- data/app/assets/javascript/semantic/checkbox.js +348 -0
- data/app/assets/javascript/semantic/dimmer.js +524 -0
- data/app/assets/javascript/semantic/dropdown.js +707 -0
- data/app/assets/javascript/semantic/modal.js +478 -0
- data/app/assets/javascript/semantic/nag.js +542 -0
- data/app/assets/javascript/semantic/popup.js +721 -0
- data/app/assets/javascript/semantic/rating.js +358 -0
- data/app/assets/javascript/semantic/search.js +769 -0
- data/app/assets/javascript/semantic/shape.js +776 -0
- data/app/assets/javascript/semantic/sidebar.js +489 -0
- data/app/assets/javascript/semantic/tab.js +674 -0
- data/app/assets/javascript/semantic/transition.js +650 -0
- data/app/assets/javascript/semantic/video.js +459 -0
- data/app/assets/stylesheets/semantic/accordion.css +97 -0
- data/app/assets/stylesheets/semantic/breadcrumb.css +66 -0
- data/app/assets/stylesheets/semantic/button.css +993 -0
- data/app/assets/stylesheets/semantic/chatroom.css +242 -0
- data/app/assets/stylesheets/semantic/checkbox.css +300 -0
- data/app/assets/stylesheets/semantic/comment.css +178 -0
- data/app/assets/stylesheets/semantic/dimmer.css +185 -0
- data/app/assets/stylesheets/semantic/divider.css +155 -0
- data/app/assets/stylesheets/semantic/dropdown.css +415 -0
- data/app/assets/stylesheets/semantic/feed.css +126 -0
- data/app/assets/stylesheets/semantic/form.css +427 -0
- data/app/assets/stylesheets/semantic/grid.css +561 -0
- data/app/assets/stylesheets/semantic/header.css +277 -0
- data/app/assets/stylesheets/semantic/icon.css +811 -0
- data/app/assets/stylesheets/semantic/image.css +143 -0
- data/app/assets/stylesheets/semantic/input.css +225 -0
- data/app/assets/stylesheets/semantic/item.css +564 -0
- data/app/assets/stylesheets/semantic/label.css +687 -0
- data/app/assets/stylesheets/semantic/list.css +418 -0
- data/app/assets/stylesheets/semantic/loader.css +148 -0
- data/app/assets/stylesheets/semantic/menu.css +1409 -0
- data/app/assets/stylesheets/semantic/message.css +242 -0
- data/app/assets/stylesheets/semantic/modal.css +123 -0
- data/app/assets/stylesheets/semantic/nag.css +130 -0
- data/app/assets/stylesheets/semantic/popup.css +209 -0
- data/app/assets/stylesheets/semantic/progress.css +257 -0
- data/app/assets/stylesheets/semantic/rating.css +120 -0
- data/app/assets/stylesheets/semantic/reveal.css +283 -0
- data/app/assets/stylesheets/semantic/search.css +222 -0
- data/app/assets/stylesheets/semantic/segment.css +362 -0
- data/app/assets/stylesheets/semantic/shape.css +87 -0
- data/app/assets/stylesheets/semantic/sidebar.css +100 -0
- data/app/assets/stylesheets/semantic/step.css +240 -0
- data/app/assets/stylesheets/semantic/tab.css +52 -0
- data/app/assets/stylesheets/semantic/table.css +468 -0
- data/app/assets/stylesheets/semantic/transition.css +867 -0
- data/app/assets/stylesheets/semantic/video.css +81 -0
- data/lib/semantic_ui_rails/version.rb +3 -0
- data/lib/semantic_ui_rails.rb +7 -0
- data/semantic_ui_rails.gemspec +23 -0
- metadata +149 -0
@@ -0,0 +1,666 @@
|
|
1
|
+
/* ******************************
|
2
|
+
API
|
3
|
+
Author: Jack Lukic
|
4
|
+
Notes: First Commit May 08, 2012
|
5
|
+
|
6
|
+
These are modules which bind API functionality to the DOM
|
7
|
+
|
8
|
+
Requires: nada
|
9
|
+
|
10
|
+
Initialization:
|
11
|
+
$('.button')
|
12
|
+
.apiButton({
|
13
|
+
success: function() {}
|
14
|
+
})
|
15
|
+
;
|
16
|
+
|
17
|
+
in our example api is automapped to an object literal
|
18
|
+
@ quirky.config.endpoint.api
|
19
|
+
|
20
|
+
HTML:
|
21
|
+
<div class="button" action="follow" data-id="5">
|
22
|
+
|
23
|
+
URL : quirky.config.endpoint.api.follow
|
24
|
+
Given Value: /follow/{$id}/
|
25
|
+
Sent Value : /follow/5/
|
26
|
+
|
27
|
+
(4 ways to map api endpoint, each will be looked for in succession)
|
28
|
+
url mapping order:
|
29
|
+
first : defined in plugin init as url (arbitrary url)
|
30
|
+
second : defined in plugin init as action (action in obj literal grouping 'api')
|
31
|
+
third : defined in data-url
|
32
|
+
fourth : defined in data-action
|
33
|
+
|
34
|
+
beforeSend:
|
35
|
+
this callback can be used to modify request settings before XHR
|
36
|
+
it also can be used to look for for pre-conditions to prevent API
|
37
|
+
call by returning "false"
|
38
|
+
|
39
|
+
****************************** */
|
40
|
+
|
41
|
+
;(function ( $, window, document, undefined ) {
|
42
|
+
|
43
|
+
$.api = $.fn.api = function(parameters) {
|
44
|
+
|
45
|
+
var
|
46
|
+
settings = $.extend(true, {}, $.api.settings, parameters),
|
47
|
+
|
48
|
+
// if this keyword isn't a jQuery object, create one
|
49
|
+
context = (typeof this != 'function')
|
50
|
+
? this
|
51
|
+
: $('<div/>'),
|
52
|
+
// context defines the element used for loading/error state
|
53
|
+
$context = (settings.stateContext)
|
54
|
+
? $(settings.stateContext)
|
55
|
+
: $(context),
|
56
|
+
// module is the thing that initiates the api action, can be independent of context
|
57
|
+
$module = typeof this == 'object'
|
58
|
+
? $(context)
|
59
|
+
: $context,
|
60
|
+
|
61
|
+
element = this,
|
62
|
+
time = new Date().getTime(),
|
63
|
+
performance = [],
|
64
|
+
|
65
|
+
moduleSelector = $module.selector || '',
|
66
|
+
moduleNamespace = settings.namespace + '-module',
|
67
|
+
|
68
|
+
className = settings.className,
|
69
|
+
metadata = settings.metadata,
|
70
|
+
error = settings.error,
|
71
|
+
|
72
|
+
instance = $module.data(moduleNamespace),
|
73
|
+
|
74
|
+
query = arguments[0],
|
75
|
+
methodInvoked = (instance !== undefined && typeof query == 'string'),
|
76
|
+
queryArguments = [].slice.call(arguments, 1),
|
77
|
+
|
78
|
+
module,
|
79
|
+
invokedResponse
|
80
|
+
;
|
81
|
+
|
82
|
+
module = {
|
83
|
+
initialize: function() {
|
84
|
+
var
|
85
|
+
runSettings,
|
86
|
+
|
87
|
+
loadingTimer = new Date().getTime(),
|
88
|
+
loadingDelay,
|
89
|
+
|
90
|
+
promise,
|
91
|
+
url,
|
92
|
+
|
93
|
+
formData = {},
|
94
|
+
data,
|
95
|
+
|
96
|
+
ajaxSettings = {},
|
97
|
+
xhr
|
98
|
+
;
|
99
|
+
|
100
|
+
// serialize parent form if requested!
|
101
|
+
if(settings.serializeForm && $(this).toJSON() !== undefined) {
|
102
|
+
formData = module.get.formData();
|
103
|
+
module.debug('Adding form data to API Request', formData);
|
104
|
+
$.extend(true, settings.data, formData);
|
105
|
+
}
|
106
|
+
|
107
|
+
// let beforeSend change settings object
|
108
|
+
runSettings = $.proxy(settings.beforeSend, $module)(settings);
|
109
|
+
|
110
|
+
// check for exit conditions
|
111
|
+
if(runSettings !== undefined && !runSettings) {
|
112
|
+
module.error(error.beforeSend);
|
113
|
+
module.reset();
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
|
117
|
+
// get real url from template
|
118
|
+
url = module.get.url( module.get.templateURL() );
|
119
|
+
|
120
|
+
// exit conditions reached from missing url parameters
|
121
|
+
if( !url ) {
|
122
|
+
module.error(error.missingURL);
|
123
|
+
module.reset();
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
127
|
+
// promise handles notification on api request, so loading min. delay can occur for all notifications
|
128
|
+
promise =
|
129
|
+
$.Deferred()
|
130
|
+
.always(function() {
|
131
|
+
if(settings.stateContext) {
|
132
|
+
$context
|
133
|
+
.removeClass(className.loading)
|
134
|
+
;
|
135
|
+
}
|
136
|
+
$.proxy(settings.complete, $module)();
|
137
|
+
})
|
138
|
+
.done(function(response) {
|
139
|
+
module.debug('API request successful');
|
140
|
+
// take a stab at finding success state if json
|
141
|
+
if(settings.dataType == 'json') {
|
142
|
+
if (response.error !== undefined) {
|
143
|
+
$.proxy(settings.failure, $context)(response.error, settings, $module);
|
144
|
+
}
|
145
|
+
else if ($.isArray(response.errors)) {
|
146
|
+
$.proxy(settings.failure, $context)(response.errors[0], settings, $module);
|
147
|
+
}
|
148
|
+
else {
|
149
|
+
$.proxy(settings.success, $context)(response, settings, $module);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
// otherwise
|
153
|
+
else {
|
154
|
+
$.proxy(settings.success, $context)(response, settings, $module);
|
155
|
+
}
|
156
|
+
})
|
157
|
+
.fail(function(xhr, status, httpMessage) {
|
158
|
+
var
|
159
|
+
errorMessage = (settings.error[status] !== undefined)
|
160
|
+
? settings.error[status]
|
161
|
+
: httpMessage,
|
162
|
+
response
|
163
|
+
;
|
164
|
+
// let em know unless request aborted
|
165
|
+
if(xhr !== undefined) {
|
166
|
+
// readyState 4 = done, anything less is not really sent
|
167
|
+
if(xhr.readyState !== undefined && xhr.readyState == 4) {
|
168
|
+
|
169
|
+
// if http status code returned and json returned error, look for it
|
170
|
+
if( xhr.status != 200 && httpMessage !== undefined && httpMessage !== '') {
|
171
|
+
module.error(error.statusMessage + httpMessage);
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
if(status == 'error' && settings.dataType == 'json') {
|
175
|
+
try {
|
176
|
+
response = $.parseJSON(xhr.responseText);
|
177
|
+
if(response && response.error !== undefined) {
|
178
|
+
errorMessage = response.error;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
catch(error) {
|
182
|
+
module.error(error.JSONParse);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
$context
|
187
|
+
.removeClass(className.loading)
|
188
|
+
.addClass(className.error)
|
189
|
+
;
|
190
|
+
// show error state only for duration specified in settings
|
191
|
+
if(settings.errorLength > 0) {
|
192
|
+
setTimeout(function(){
|
193
|
+
$context
|
194
|
+
.removeClass(className.error)
|
195
|
+
;
|
196
|
+
}, settings.errorLength);
|
197
|
+
}
|
198
|
+
module.debug('API Request error:', errorMessage);
|
199
|
+
$.proxy(settings.failure, $context)(errorMessage, settings, this);
|
200
|
+
}
|
201
|
+
else {
|
202
|
+
module.debug('Request Aborted (Most likely caused by page change)');
|
203
|
+
}
|
204
|
+
}
|
205
|
+
})
|
206
|
+
;
|
207
|
+
|
208
|
+
// look for params in data
|
209
|
+
$.extend(true, ajaxSettings, settings, {
|
210
|
+
success : function(){},
|
211
|
+
failure : function(){},
|
212
|
+
complete : function(){},
|
213
|
+
type : settings.method || settings.type,
|
214
|
+
data : data,
|
215
|
+
url : url,
|
216
|
+
beforeSend : settings.beforeXHR
|
217
|
+
});
|
218
|
+
|
219
|
+
if(settings.stateContext) {
|
220
|
+
$context
|
221
|
+
.addClass(className.loading)
|
222
|
+
;
|
223
|
+
}
|
224
|
+
|
225
|
+
if(settings.progress) {
|
226
|
+
module.verbose('Adding progress events');
|
227
|
+
$.extend(true, ajaxSettings, {
|
228
|
+
xhr: function() {
|
229
|
+
var
|
230
|
+
xhr = new window.XMLHttpRequest()
|
231
|
+
;
|
232
|
+
xhr.upload.addEventListener('progress', function(event) {
|
233
|
+
var
|
234
|
+
percentComplete
|
235
|
+
;
|
236
|
+
if (event.lengthComputable) {
|
237
|
+
percentComplete = Math.round(event.loaded / event.total * 10000) / 100 + '%';
|
238
|
+
$.proxy(settings.progress, $context)(percentComplete, event);
|
239
|
+
}
|
240
|
+
}, false);
|
241
|
+
xhr.addEventListener('progress', function(event) {
|
242
|
+
var
|
243
|
+
percentComplete
|
244
|
+
;
|
245
|
+
if (event.lengthComputable) {
|
246
|
+
percentComplete = Math.round(event.loaded / event.total * 10000) / 100 + '%';
|
247
|
+
$.proxy(settings.progress, $context)(percentComplete, event);
|
248
|
+
}
|
249
|
+
}, false);
|
250
|
+
return xhr;
|
251
|
+
}
|
252
|
+
});
|
253
|
+
}
|
254
|
+
|
255
|
+
module.verbose('Creating AJAX request with settings: ', ajaxSettings);
|
256
|
+
xhr =
|
257
|
+
$.ajax(ajaxSettings)
|
258
|
+
.always(function() {
|
259
|
+
// calculate if loading time was below minimum threshold
|
260
|
+
loadingDelay = ( settings.loadingLength - (new Date().getTime() - loadingTimer) );
|
261
|
+
settings.loadingDelay = loadingDelay < 0
|
262
|
+
? 0
|
263
|
+
: loadingDelay
|
264
|
+
;
|
265
|
+
})
|
266
|
+
.done(function(response) {
|
267
|
+
var
|
268
|
+
context = this
|
269
|
+
;
|
270
|
+
setTimeout(function(){
|
271
|
+
promise.resolveWith(context, [response]);
|
272
|
+
}, settings.loadingDelay);
|
273
|
+
})
|
274
|
+
.fail(function(xhr, status, httpMessage) {
|
275
|
+
var
|
276
|
+
context = this
|
277
|
+
;
|
278
|
+
// page triggers abort on navigation, dont show error
|
279
|
+
if(status != 'abort') {
|
280
|
+
setTimeout(function(){
|
281
|
+
promise.rejectWith(context, [xhr, status, httpMessage]);
|
282
|
+
}, settings.loadingDelay);
|
283
|
+
}
|
284
|
+
else {
|
285
|
+
$context
|
286
|
+
.removeClass(className.error)
|
287
|
+
.removeClass(className.loading)
|
288
|
+
;
|
289
|
+
}
|
290
|
+
})
|
291
|
+
;
|
292
|
+
if(settings.stateContext) {
|
293
|
+
$module
|
294
|
+
.data(metadata.promise, promise)
|
295
|
+
.data(metadata.xhr, xhr)
|
296
|
+
;
|
297
|
+
}
|
298
|
+
},
|
299
|
+
|
300
|
+
get: {
|
301
|
+
formData: function() {
|
302
|
+
return $module
|
303
|
+
.closest('form')
|
304
|
+
.toJSON()
|
305
|
+
;
|
306
|
+
},
|
307
|
+
templateURL: function() {
|
308
|
+
var
|
309
|
+
action = $module.data(settings.metadata.action) || settings.action || false,
|
310
|
+
url
|
311
|
+
;
|
312
|
+
if(action) {
|
313
|
+
module.debug('Creating url for: ', action);
|
314
|
+
if(settings.api[action] !== undefined) {
|
315
|
+
url = settings.api[action];
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
module.error(error.missingAction);
|
319
|
+
}
|
320
|
+
}
|
321
|
+
// override with url if specified
|
322
|
+
if(settings.url) {
|
323
|
+
url = settings.url;
|
324
|
+
module.debug('Getting url', url);
|
325
|
+
}
|
326
|
+
return url;
|
327
|
+
},
|
328
|
+
url: function(url, urlData) {
|
329
|
+
var
|
330
|
+
urlVariables
|
331
|
+
;
|
332
|
+
if(url) {
|
333
|
+
urlVariables = url.match(settings.regExpTemplate);
|
334
|
+
urlData = urlData || settings.urlData;
|
335
|
+
|
336
|
+
if(urlVariables) {
|
337
|
+
module.debug('Looking for URL variables', urlVariables);
|
338
|
+
$.each(urlVariables, function(index, templateValue){
|
339
|
+
var
|
340
|
+
term = templateValue.substr( 2, templateValue.length - 3),
|
341
|
+
termValue = ($.isPlainObject(urlData) && urlData[term] !== undefined)
|
342
|
+
? urlData[term]
|
343
|
+
: ($module.data(term) !== undefined)
|
344
|
+
? $module.data(term)
|
345
|
+
: urlData[term]
|
346
|
+
;
|
347
|
+
module.verbose('Looking for variable', term, $module, $module.data(term), urlData[term]);
|
348
|
+
// remove optional value
|
349
|
+
if(termValue === false) {
|
350
|
+
module.debug('Removing variable from URL', urlVariables);
|
351
|
+
url = url.replace('/' + templateValue, '');
|
352
|
+
}
|
353
|
+
// undefined condition
|
354
|
+
else if(termValue === undefined || !termValue) {
|
355
|
+
module.error(error.missingParameter + term);
|
356
|
+
url = false;
|
357
|
+
return false;
|
358
|
+
}
|
359
|
+
else {
|
360
|
+
url = url.replace(templateValue, termValue);
|
361
|
+
}
|
362
|
+
});
|
363
|
+
}
|
364
|
+
}
|
365
|
+
return url;
|
366
|
+
}
|
367
|
+
},
|
368
|
+
|
369
|
+
// reset api request
|
370
|
+
reset: function() {
|
371
|
+
$module
|
372
|
+
.data(metadata.promise, false)
|
373
|
+
.data(metadata.xhr, false)
|
374
|
+
;
|
375
|
+
$context
|
376
|
+
.removeClass(className.error)
|
377
|
+
.removeClass(className.loading)
|
378
|
+
;
|
379
|
+
},
|
380
|
+
|
381
|
+
setting: function(name, value) {
|
382
|
+
if(value !== undefined) {
|
383
|
+
if( $.isPlainObject(name) ) {
|
384
|
+
$.extend(true, settings, name);
|
385
|
+
}
|
386
|
+
else {
|
387
|
+
settings[name] = value;
|
388
|
+
}
|
389
|
+
}
|
390
|
+
else {
|
391
|
+
return settings[name];
|
392
|
+
}
|
393
|
+
},
|
394
|
+
internal: function(name, value) {
|
395
|
+
if(value !== undefined) {
|
396
|
+
if( $.isPlainObject(name) ) {
|
397
|
+
$.extend(true, module, name);
|
398
|
+
}
|
399
|
+
else {
|
400
|
+
module[name] = value;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
else {
|
404
|
+
return module[name];
|
405
|
+
}
|
406
|
+
},
|
407
|
+
debug: function() {
|
408
|
+
if(settings.debug) {
|
409
|
+
if(settings.performance) {
|
410
|
+
module.performance.log(arguments);
|
411
|
+
}
|
412
|
+
else {
|
413
|
+
module.debug = Function.prototype.bind.call(console.info, console, settings.moduleName + ':');
|
414
|
+
module.debug.apply(console, arguments);
|
415
|
+
}
|
416
|
+
}
|
417
|
+
},
|
418
|
+
verbose: function() {
|
419
|
+
if(settings.verbose && settings.debug) {
|
420
|
+
if(settings.performance) {
|
421
|
+
module.performance.log(arguments);
|
422
|
+
}
|
423
|
+
else {
|
424
|
+
module.verbose = Function.prototype.bind.call(console.info, console, settings.moduleName + ':');
|
425
|
+
module.verbose.apply(console, arguments);
|
426
|
+
}
|
427
|
+
}
|
428
|
+
},
|
429
|
+
error: function() {
|
430
|
+
module.error = Function.prototype.bind.call(console.error, console, settings.moduleName + ':');
|
431
|
+
module.error.apply(console, arguments);
|
432
|
+
},
|
433
|
+
performance: {
|
434
|
+
log: function(message) {
|
435
|
+
var
|
436
|
+
currentTime,
|
437
|
+
executionTime,
|
438
|
+
previousTime
|
439
|
+
;
|
440
|
+
if(settings.performance) {
|
441
|
+
currentTime = new Date().getTime();
|
442
|
+
previousTime = time || currentTime;
|
443
|
+
executionTime = currentTime - previousTime;
|
444
|
+
time = currentTime;
|
445
|
+
performance.push({
|
446
|
+
'Element' : element,
|
447
|
+
'Name' : message[0],
|
448
|
+
'Arguments' : [].slice.call(message, 1) || '',
|
449
|
+
'Execution Time' : executionTime
|
450
|
+
});
|
451
|
+
}
|
452
|
+
clearTimeout(module.performance.timer);
|
453
|
+
module.performance.timer = setTimeout(module.performance.display, 100);
|
454
|
+
},
|
455
|
+
display: function() {
|
456
|
+
var
|
457
|
+
title = settings.moduleName + ':',
|
458
|
+
totalTime = 0
|
459
|
+
;
|
460
|
+
clearTimeout(module.performance.timer);
|
461
|
+
time = false;
|
462
|
+
$.each(performance, function(index, data) {
|
463
|
+
totalTime += data['Execution Time'];
|
464
|
+
});
|
465
|
+
title += ' ' + totalTime + 'ms';
|
466
|
+
if(moduleSelector) {
|
467
|
+
title += ' \'' + moduleSelector + '\'';
|
468
|
+
}
|
469
|
+
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
|
470
|
+
console.groupCollapsed(title);
|
471
|
+
if(console.table) {
|
472
|
+
console.table(performance);
|
473
|
+
}
|
474
|
+
else {
|
475
|
+
$.each(performance, function(index, data) {
|
476
|
+
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
|
477
|
+
});
|
478
|
+
}
|
479
|
+
console.groupEnd();
|
480
|
+
}
|
481
|
+
performance = [];
|
482
|
+
}
|
483
|
+
},
|
484
|
+
invoke: function(query, passedArguments, context) {
|
485
|
+
var
|
486
|
+
maxDepth,
|
487
|
+
found,
|
488
|
+
response
|
489
|
+
;
|
490
|
+
passedArguments = passedArguments || queryArguments;
|
491
|
+
context = element || context;
|
492
|
+
if(typeof query == 'string' && instance !== undefined) {
|
493
|
+
query = query.split(/[\. ]/);
|
494
|
+
maxDepth = query.length - 1;
|
495
|
+
$.each(query, function(depth, value) {
|
496
|
+
var camelCaseValue = (depth != maxDepth)
|
497
|
+
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
|
498
|
+
: query
|
499
|
+
;
|
500
|
+
if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
|
501
|
+
instance = instance[value];
|
502
|
+
}
|
503
|
+
else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) {
|
504
|
+
instance = instance[camelCaseValue];
|
505
|
+
}
|
506
|
+
else if( instance[value] !== undefined ) {
|
507
|
+
found = instance[value];
|
508
|
+
return false;
|
509
|
+
}
|
510
|
+
else if( instance[camelCaseValue] !== undefined ) {
|
511
|
+
found = instance[camelCaseValue];
|
512
|
+
return false;
|
513
|
+
}
|
514
|
+
else {
|
515
|
+
module.error(error.method);
|
516
|
+
return false;
|
517
|
+
}
|
518
|
+
});
|
519
|
+
}
|
520
|
+
if ( $.isFunction( found ) ) {
|
521
|
+
response = found.apply(context, passedArguments);
|
522
|
+
}
|
523
|
+
else if(found !== undefined) {
|
524
|
+
response = found;
|
525
|
+
}
|
526
|
+
if($.isArray(invokedResponse)) {
|
527
|
+
invokedResponse.push(response);
|
528
|
+
}
|
529
|
+
else if(typeof invokedResponse == 'string') {
|
530
|
+
invokedResponse = [invokedResponse, response];
|
531
|
+
}
|
532
|
+
else if(response !== undefined) {
|
533
|
+
invokedResponse = response;
|
534
|
+
}
|
535
|
+
return found;
|
536
|
+
}
|
537
|
+
};
|
538
|
+
|
539
|
+
if(methodInvoked) {
|
540
|
+
if(instance === undefined) {
|
541
|
+
module.initialize();
|
542
|
+
}
|
543
|
+
module.invoke(query);
|
544
|
+
}
|
545
|
+
else {
|
546
|
+
if(instance !== undefined) {
|
547
|
+
module.destroy();
|
548
|
+
}
|
549
|
+
module.initialize();
|
550
|
+
}
|
551
|
+
|
552
|
+
return (invokedResponse !== undefined)
|
553
|
+
? invokedResponse
|
554
|
+
: this
|
555
|
+
;
|
556
|
+
};
|
557
|
+
|
558
|
+
// handle DOM attachment to API functionality
|
559
|
+
$.fn.apiButton = function(parameters) {
|
560
|
+
$(this)
|
561
|
+
.each(function(){
|
562
|
+
var
|
563
|
+
// if only function passed it is success callback
|
564
|
+
$module = $(this),
|
565
|
+
selector = $(this).selector || '',
|
566
|
+
|
567
|
+
settings = ( $.isFunction(parameters) )
|
568
|
+
? $.extend(true, {}, $.api.settings, $.fn.apiButton.settings, { stateContext: this, success: parameters })
|
569
|
+
: $.extend(true, {}, $.api.settings, $.fn.apiButton.settings, { stateContext: this}, parameters),
|
570
|
+
module
|
571
|
+
;
|
572
|
+
module = {
|
573
|
+
initialize: function() {
|
574
|
+
if(settings.context && selector !== '') {
|
575
|
+
$(settings.context)
|
576
|
+
.on(selector, 'click.' + settings.namespace, module.click)
|
577
|
+
;
|
578
|
+
}
|
579
|
+
else {
|
580
|
+
$module
|
581
|
+
.on('click.' + settings.namespace, module.click)
|
582
|
+
;
|
583
|
+
}
|
584
|
+
},
|
585
|
+
click: function() {
|
586
|
+
if(!settings.filter || $(this).filter(settings.filter).size() === 0) {
|
587
|
+
$.proxy( $.api, this )(settings);
|
588
|
+
}
|
589
|
+
}
|
590
|
+
};
|
591
|
+
module.initialize();
|
592
|
+
})
|
593
|
+
;
|
594
|
+
return this;
|
595
|
+
};
|
596
|
+
|
597
|
+
$.api.settings = {
|
598
|
+
name : 'API',
|
599
|
+
namespace : 'api',
|
600
|
+
|
601
|
+
debug : true,
|
602
|
+
verbose : true,
|
603
|
+
performance : true,
|
604
|
+
|
605
|
+
api : {},
|
606
|
+
|
607
|
+
beforeSend : function(settings) {
|
608
|
+
return settings;
|
609
|
+
},
|
610
|
+
beforeXHR : function(xhr) {},
|
611
|
+
success : function(response) {},
|
612
|
+
complete : function(response) {},
|
613
|
+
failure : function(errorCode) {},
|
614
|
+
progress : false,
|
615
|
+
|
616
|
+
error : {
|
617
|
+
missingAction : 'API action used but no url was defined',
|
618
|
+
missingURL : 'URL not specified for the API action',
|
619
|
+
missingParameter : 'Missing an essential URL parameter: ',
|
620
|
+
|
621
|
+
timeout : 'Your request timed out',
|
622
|
+
error : 'There was an error with your request',
|
623
|
+
parseError : 'There was an error parsing your request',
|
624
|
+
JSONParse : 'JSON could not be parsed during error handling',
|
625
|
+
statusMessage : 'Server gave an error: ',
|
626
|
+
beforeSend : 'The before send function has aborted the request',
|
627
|
+
exitConditions : 'API Request Aborted. Exit conditions met'
|
628
|
+
},
|
629
|
+
|
630
|
+
className: {
|
631
|
+
loading : 'loading',
|
632
|
+
error : 'error'
|
633
|
+
},
|
634
|
+
|
635
|
+
metadata: {
|
636
|
+
action : 'action',
|
637
|
+
promise : 'promise',
|
638
|
+
xhr : 'xhr'
|
639
|
+
},
|
640
|
+
|
641
|
+
regExpTemplate: /\{\$([A-z]+)\}/g,
|
642
|
+
|
643
|
+
action : false,
|
644
|
+
url : false,
|
645
|
+
urlData : false,
|
646
|
+
serializeForm : false,
|
647
|
+
|
648
|
+
stateContext : false,
|
649
|
+
|
650
|
+
method : 'get',
|
651
|
+
data : {},
|
652
|
+
dataType : 'json',
|
653
|
+
cache : true,
|
654
|
+
|
655
|
+
loadingLength : 200,
|
656
|
+
errorLength : 2000
|
657
|
+
|
658
|
+
};
|
659
|
+
|
660
|
+
$.fn.apiButton.settings = {
|
661
|
+
filter : '.disabled, .loading',
|
662
|
+
context : false,
|
663
|
+
stateContext : false
|
664
|
+
};
|
665
|
+
|
666
|
+
})( jQuery, window , document );
|