-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgo.js
More file actions
2220 lines (1758 loc) · 68.1 KB
/
go.js
File metadata and controls
2220 lines (1758 loc) · 68.1 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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* GoJS 0.7.9.4
* Dependencies: jQuery 1.5+
*
* GoJS is a full-featured MVC framework that provides support for controllers, actions, views, models, routing,
* deep linking, back/front button support, loading indication, resource loading, template rendering, and storage.
*
* (c) 2012 Sterling Nichols
* Distributed under the MIT license.
* For all details and documentation:
* http://exsurgo.github.com/gojs
*/
/***** Public objects *****/
// Controller
var Controller = function (ctrlName, items) {
return this.construct(ctrlName, items);
};
// Action
var Action = function (props) {
return this.construct(props);
};
// ActionEvent
var ActionEvent = function (props) {
return this.construct(props);
};
/***** Core *****/
var Go = (function () {
var go = {};
/***** Init *****/
// Private fields
var _controllers = {}, // Controllers
_updaters = {}, // Custom update functions
_events = [], // Global events
_content, // Main content area
_componentFields = {}; // Fields for components to share
// Default config
var _config = {
//Routes
routes: [], //TODO: Move this to its own field
//Settings
autoActivateViews: true, // Automatically activate every link and form
autoCorrectLinks: true, // Change standard URL's to ajax (#) URL's
contentSelector: "[go-content]", // The main content area
defaultContentUrl: null, // URL to request if content area is empty on page load
submitFilter: null, // Don't submit any form elements that match this
loadingIndicatorCSS: "loading-indicator", // CSS style for the loading indicator
prefixControllerNameToViews: true, // If true append the controller name to view keys
//Resource Routes
scriptRoute: "/scripts/{key}.js",
styleRoute: "/styles/{key}.css",
viewRoute: "/views/{key}.html",
controllerRoute: "/controllers/{key}.js",
modelRoute: "/models/{key}.js"
};
// Properties
go.isRequesting = false; // Is making a request
go.wait = false; // Hold all actions from running
/***** Public Methods *****/
// Run Action
go.run = function () {
//Arguments, overloaded
var args = arguments,
a1 = args[0],
a2 = args[1],
a3 = args[2];
//Argument is string, assume is URL
if (args.length == 1 && isString(a1)) handleRun(new ActionEvent({ url: a1 }));
//Argument is an ActionEvent
else if (a1 instanceof ActionEvent) handleRun(a1);
//Arguments are controllerName, actionName and values
else {
//Create ActionEvent object
var e = new ActionEvent({
values: extend(a3, { //values
controller: a1, //controllerName
action: a2 //actionName
})
});
handleRun(e);
}
};
// Get
go.get = function (url, callback) {
go.request({ url: url, response: callback });
};
// Post
go.post = function (url, data, callback) {
go.request(url, {
isPost: true,
postData: data,
response: callback
});
};
// Request
go.request = function (url, options) {
handleRequest(url, options);
};
// Reload
go.reload = function (redirect, enableSSL) {
//Locals
var protocol = location.protocol,
host = location.host;
//Show progress
go.showLoading();
//Hold any requests
go.wait = go.formatURL(redirect);
//If protocol is changing, change entire href
if ((protocol == "http" && enableSSL) || (protocol == "https" && !enableSSL)) {
location.href = "http" + (enableSSL ? "s" : "") + "://" + host + "#" + newHash;
}
//Else change hash and reload
{
//Must use $location.hash, not $hash
location.hash = go.wait;
location.reload();
}
};
// Get/Set config
go.config = function (config) {
//Get
if (!config) return _config;
//Set
else for (var key in config) {
var val = config[key];
//Join arrays
if (isArray(val) && isArray(_config[key])) {
_config[key] = _config[key].concat(val);
}
//Assign other values
else _config[key] = val;
}
};
// Set routes
go.route = function (routes) {
_config.routes = _config.routes.concat(routes);
};
// Add event
go.on = function () {
var args = arguments,
events = getArg(args, "string", 1).split(",");
$(events).each(function () {
var event = $.trim(this).toLowerCase();
_events.push({
type: event,
event: getArg(args, "function", 1),
route: getArg(args, "string", 2)
});
});
};
// Run update
go.update = function (updater, element) {
handleUpdate(new ActionEvent({
updater: updater,
element: element
}));
};
// Add updaters
go.addUpdaters = function (updaters) {
_updaters = extend(_updaters, updaters);
};
// Add component
go.module = function (func) {
func.call(null, go, jQuery, _componentFields);
}
/***** Constructors *****/
//Construct objects internally for access to private functions
Controller.prototype.construct = function (ctrlName, items) {
// Create controller object
var ctrl = {
name: ctrlName,
//Hash object to store actions
actions: {}
};
// Add each item to controller
for (var key in items) {
var action = items[key],
isActionObj = action instanceof Action;
// Actions
if (isActionObj || isFunction(action)) {
// Only for Action objects
if (isActionObj) {
// Add properties
extend(action, {
controller: ctrl,
name: key
});
// Add action specific routes
// Important, add action routes at beginning of collection so other routes are overridden
// TODO: Need separate collection for action routes
// TODO: Add support for multiple routes?
var route = action.route;
if (route) {
// String
if (isString(route)) _config.routes.unshift({ route: route, defaults: { controller: ctrlName, action: key } });
// Object
else _config.routes.unshift(route);
}
}
// Add action to controller "actions" collection
ctrl.actions[key] = action;
}
// Todo: add support for controller specific routes
// Else just add item to controller
// Normally, functions would be added as helpers in this case
else ctrl[key] = item;
};
// Shortcut Methods
// Allows for MyController.list(values) rather than Go.run("MyController", "list", values)
// For functions, can use arguments... MyController.list(arg1, arg2)
// Important! Must use separate function for key to resolve correctly
for (var key in ctrl.actions) addShortcut(ctrl, key);
function addShortcut(ctrl, actionName) {
// Only add if controller property name does not already exist
if (!ctrl[actionName]) {
// Get action from "actions" collection
var action = ctrl.actions[actionName];
// If function, pass in arguments and use empty ActionEvent as context
if (isFunction(action)) {
ctrl[actionName] = function () {
action.apply(new ActionEvent({}), arguments);
};
}
// Else if Action object, use Go.run() method
else {
ctrl[actionName] = function (values) {
go.run(ctrl.name, actionName, values);
};
}
}
}
// Add controller to global collection
_controllers[ctrlName] = ctrl;
// Return controller for chaining
return ctrl;
};
Action.prototype.construct = function (options) {
return extend(this, options);
};
ActionEvent.prototype.construct = function (options) {
if (!options.values) options.values = {};
return extend(this, options);
};
/***** Handlers *****/
function handleReady(e) {
//Find and cache content area
_content = $(_config.contentSelector);
//Create ActionEvent object
//URL is either current hash or "/" by default
var e = new ActionEvent({
element: $("body"),
url: go.formatURL(location.hash) || "/"
});
getRouteValuesFromUrl(e);
//EVENT: ready
triggerEvents("ready", e);
//Activate entire document
runNextHandler(handleActivate, e);
//Handle initial hash value
requireAll(e, function () {
//Empty content area
_content.empty();
//Don't start if url is held
if (go.wait == e.url) go.wait = null;
//Goto start
else handleRun(e);
});
//Request default content URL if nothing is being requested and content is empty
//TODO: Remove this?
setTimeout(function () {
var url = _config.defaultContentUrl;
if (url && !Go.isRequesting && !_content.find("*").length) {
handleRun({ url: url });
}
}, 500);
}
function handleRun(e) {
if (e.url) {
//Ensure proper URL format
e.url = go.formatURL(e.url);
//Get route values
getRouteValuesFromUrl(e);
};
//EVENT: beforeRun
triggerEvents("beforeRun", e);
//Load all resources
requireAll(e, function () {
//Locate action
if (e.action || tryLocateAction(e)) {
var action = e.action;
//EVENT: run
triggerEvents("run", e);
//Load all resources
requireAll(e, function () {
//If "action.remote" then make request
//Assume all other actions are local otherwise
//TODO: Add global config to set all remote
if (action.remote) runNextHandler(handleRequest, e);
//Else if has view, the render
else if (action.view) runNextHandler(handleRender, e);
// If action is function, run here
// If triggered by route, then e is passed as arg
else if (isFunction(e.action)) {
e.action.call(e, e);
runNextHandler(handleComplete, e);
}
//Else complete
else runNextHandler(handleComplete, e);
});
}
//Show error if unable to location action
//Each activated link must have a controller action
else if (!e.action) throw "Could not locate action for URL \"" + e.url + "\"";
});
}
function handleRequest(e) {
//Locals
var action = e.action,
sender = $(e.sender),
postData = e.postData,
isPost = e.isPost || (postData != undefined && postData != null),
remote = action && action.remote,
remoteURL;
//Resolve remote URL
var remoteURL = isFunction(remote) ? remote(e) : //Run if function
isString(remote) ? remote : //Use self if string
e.url; //Use URL if anything else
//Merge URL with values
remoteURL = e.remote = Go.format(remoteURL, e.values);
//Confirm request
if (!confirmAction(e.sender)) return false;
//Show loading indicator
go.showLoading();
//EVENT: request
triggerEvents("request", e);
//Serialize post data
//TODO: Check to see if this is needed
if (isPost && postData && isString(postData)) postData = $.param(postData);
//Signify request is in progress
go.isRequesting = true;
//Make request
$.ajax({
url: remoteURL,
type: isPost ? "post" : "get",
data: postData,
cache: false,
success: function (data, status, xhr) {
//Update properties
extend(e, {
data: data,
status: status,
xhr: xhr
});
//Response
runNextHandler(handleResponse, e);
},
error: function (xhr, status, error) {
//Update properties
extend(e, {
error: error,
status: status,
xhr: xhr
});
//Error
runNextHandler(handleRequestError, e);
}
});
}
function handleRequestError(e) {
//Enable sender
go.enable(e.sender, true);
//EVENT: requestError
triggerEvents("requestError", e);
//Hide progress
go.hideLoading();
//Signify request is complete
go.isRequesting = false;
}
function handleResponse(e) {
// Locals
var contentType = (e.xhr.getResponseHeader("content-type") || "").toLowerCase(),
data = e.data,
isHTML = (/html/i).test(contentType),
isJSON = (/json/i).test(contentType);
// Update properties
extend(e, {
contentType: contentType,
isHTML: isHTML,
isJSON: isJSON
});
// Some other response type, Check for JSON
// Attempt to parse, continue on exception
if (!isHTML && !isJSON) {
try {
data = $.parseJSON(data);
isJSON = true;
} catch (e) { }
}
// EVENT: response
triggerEvents("response", e);
// Hide progress
go.hideLoading();
// Signify request is complete
go.isRequesting = false;
// Error(s) found, indicated by "error" or "errors" properties
if (isJSON && data && (data.error || data.errors)) runNextHandler(handleError, e);
// Success
else runNextHandler(handleSuccess, e);
}
function handleSuccess(e) {
// EVENT: success
triggerEvents("success", e);
// Next handler
// Update if HTML and has updater
// TODO: Is this needed, Should HTML be requested at all here?
if (e.isHTML && e.updater) runNextHandler(handleUpdate, e);
// Render if view is specified
else if (Go.getProp("action.view", e)) runNextHandler(handleRender, e);
//Else handle complete
else runNextHandler(handleComplete, e);
}
function handleError(e) {
//Add error(s) props to "e" for easy access
extend(e, e.data, "error,errors");
// Enable sender
go.enable(e.sender, true);
//EVENT: error
triggerEvents("error", e);
}
function handleRender(e) {
// Locals
var action = e.action,
view = action.view;
// If no view, then goto complete
if (!view) {
runNextHandler(handleComplete, e);
return;
}
// Prefix controller name to view
// TODO: Need a better way to do this
if (_config.prefixControllerNameToViews && !/\//.test(view))
view = e.values.controller + "/" + view;
// Replace any params with values
view = go.format(view, e.values);
// Ensure view is loaded
go.require({ views: view }, function () {
//Get model
var model = resolveModel(e);
// Render the template if model is provided
// Pass event object internally as 3rd param
// TODO: Should template be rendered if no model? Then view property can't be used in some cases
e.element = go.render(view, model, /* internal */ e);
// EVENT: render
triggerEvents("render", e);
// Update the rendered element
runNextHandler(handleUpdate, e);
});
}
function handleUpdate(e) {
// Locals
var action = e.action,
element = $(e.element),
id = element.attr("id"),
updater = e.updater,
updateData = isPlainObject(updater) ? updater : {},
target;
// Get updater name
// Can be string, or object with "name" property
var updaterName = (isString(e.updater) ? e.updater : e.updater.type).toLowerCase();
// Ensure "updater" property is provided
if (!updaterName) {
runNextHandler(handleComplete, e);
return;
}
// Ensure element has id
if (!id) {
id = go.createRandomId();
element.attr("id", id);
}
// Add properties to event object
extend(e, {
updateData: updateData,
updateId: id,
element: element
});
// EVENT: updating
triggerEvents("updating", e);
// Hide update
element.hide();
// Check custom updaters
var isUpdated = false;
for (var item in _updaters) {
if (item.toLowerCase() == updaterName) {
// Run custom updater
_updaters[item](e);
isUpdated = true;
continue;
}
}
// Check standard updates
// content, replace, insert, append, prepend, after, before
if (!isUpdated) {
// Content
if (updaterName == "content") {
// TODO: Move address/title to complete?
// Address
go.setAddress(e.address || e.url);
// Page Title
var title = evalFunc(e.title, e);
if (title) document.title = title;
// Content
$(_config.contentSelector).empty().append(element);
// Scroll to top by default
if (!updateData.scroll && isFunction(scrollTo)) $(window).scrollTop(0);
}
// Other Updaters
else {
// Try to get existing version of element
var existing = $("#" + id);
// Replace
if (updaterName == "replace" || existing.length) existing.replaceWith(element);
// Targeted updates
else {
// Try to get from string via pattern "{updater}: selector"
if (/:/.test(updaterName)) {
var i = updaterName.indexOf(":");
target = updaterName.slice(i + 1);
updaterName = updaterName.slice(0, i);
}
// Try to get from object
else target = updaterData.target;
// Merge with values
target = go.format(target, e.values);
// Require target
if (!target) throw "Element \"" + id + "\" with update \"" + updaterName + "\" requires a target";
// Convert to jQuery
target = $(target);
if (updaterName == "insert") target.html(element);
if (updaterName == "prepend") target.prepend(element);
if (updaterName == "append") target.append(element);
if (updaterName == "before") target.before(element);
if (updaterName == "after") target.after(element);
}
}
}
// EVENT: updated
triggerEvents("updated", e);
// Show update
element.show();
// Activate the view
runNextHandler(handleActivate, e);
}
function handleActivate(e) {
// Locals
var element = e.element;
// EVENT: activate
triggerEvents("activate", e);
// Run activator
go.activate(element);
// Run complete handler
runNextHandler(handleComplete, e);
}
function handleComplete(e) {
// Enable sender
go.enable(e.sender, true);
// EVENT: complete
triggerEvents("complete", e);
// Redirect
var redirect = getActionValue("redirect", e);
if (redirect) Go.run(redirect);
// Remove
var remove = getActionValue("remove", e);
if (remove) $(remove).remove();
// Empty
var empty = getActionValue("empty", e);
if (empty) $(empty).empty();
// Show
var show = getActionValue("show", e);
if (show) $(show).show();
// Hide
var hide = getActionValue("hide", e);
if (hide) $(hide).hide();
// Focus
var focus = getActionValue("focus", e);
if (focus) $(focus).focus();
}
/***** Private Methods *****/
// Get route values from URL
// Adds values to e, return true if found
// TODO: Return route object instead?
function getRouteValuesFromUrl(e) {
//Prevent from running twice
if (e.routeMatched != undefined) return e.routeMatched;
//Ensure values is initialized
e.values = (e.values || {});
//Locals
var url = go.trimChars(e.url, "/"),
routes = _config.routes,
length = routes.length;
//Query string
if (/\?/.test(url)) {
//Split string from path
var parts = url.split("?");
params = parts[1].split("&");
//Reassign URL path
url = go.trimChars(parts[0], "/");
//Add params to e.values
for (var i = 0; i < params.length; i++) {
var pair = params[i].split("=");
e.values[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
}
//Convert empty path to default "/"
url = url || "/"
//Exit on empty arguments
if (!url || !routes) return;
//Check each route, take first match
for (var i = 0; i < length; i++) {
//Locals
var routeObj = routes[i],
route = go.trimChars(routeObj.route, "/") || "/",
require = routeObj.require,
defaults = routeObj.defaults,
paramRegex = /{[\w\d_]+}/ig,
routeRegex = new RegExp("^" + route.replace(paramRegex, "([^\\/]+)") + "$", "i"),
vals = e.values;
//Check URL with regex
if (routeRegex.test(url)) {
//Add require to event only if it doesn't exist
if (!e.require && require) e.require = require;
//Merge values with defaults
vals = extend(vals, defaults);
//Get param names
var paramNames = route.match(paramRegex);
//Route might not contain any params
if (paramNames) {
//Remove curly brackets from names
go.trimChars(paramNames, "{}");
//Get param values
//Skip first item in array, Only take param matches
var paramValues = url.match(routeRegex).slice(1);
for (var i = 0; i < paramNames.length; i++) {
vals[paramNames[i]] = paramValues[i];
}
}
//Success, Route has been matched
//Return true only if controller and action found
if (vals.controller && vals.action) {
e.routeMatched = true;
e.route = route;
return true;
}
}
}
//No matching route found
e.routeMatched = false;
return false;
}
// Try to locate a controller and action
function tryLocateAction(e) {
//Try to match controller/action
var ctrl = findPropIgnoreCase(_controllers, e.values.controller), action;
if (ctrl) action = findPropIgnoreCase(ctrl.actions, e.values.action);
//Match found, add values to event
if (action) {
//Add specific action properties to "e"
//Allows for easier access... e.view rather than e.action.view
//Need to avoid certain props such as require and events
//TODO: Add additional props in future
extend(e, action, "model,view,controller,remote,updater,title,address,menu");
//Add properties to "e"
e.controller = ctrl;
e.action = action;
//Return true if located
return true;
}
}
// Resolve model from property and response
function resolveModel(e) {
//Locals
var model,
modelType = e.action.model,
data = e.data || null;
//Model is function, execute with e as this, and response data as argument
if (isFunction(modelType)) model = modelType.call(e, e.data);
//Model is object, combine
else if (typeof modelType == "object") model = extend(data, modelType);
//Model is null or undefined, just use data
else if (!modelType) model = data;
//Assign resolved model
if (model) e.model = model;
return model;
}
// Trigger events on e, controller or action
// Trigger events added by "on" method
function triggerEvents(eventType, e) {
//Context, try to get controller
//Use window if controller not available
var values = e.values,
controller = (e.controller || //Try first
e.values ? findPropIgnoreCase(_controllers, e.values.controller) : false || //Try to resolve if not exists
window); //Else, just use window
//Match event by lowercase
eventType = eventType.toLowerCase();
//Try to run global events added by "on" method
$(_events).each(function () {
//Check for event type
if (this.type == eventType) {
//Check for route
//Exit loop if route exists and doesn't match
if (this.route) {
var regex = new RegExp(this.route, "i");
if (!regex.test(e.url)) return;
}
//Call function
this.event.call(controller, e);
}
});
//Try to run event on ActionEvent "e" object
callFunction(e, eventType, e, e);
//Try to run event on Action "action" object
callFunction(e, "action." + eventType, e, e);
}
// Run the next step, can be canceled or delayed
function runNextHandler(nextHandler, e) {
//If e.cancel, then exit process
if (e.cancel) return;
//If e.delay, then wait
else if (e.delay) {
setTimeout(function () { nextHandler(e); }, e.delay);
delete e.delay;
}
//Run normally
else nextHandler(e);
}
// Load all required resources for an event
// Load required on event, controller and action
function requireAll(e, callback) {
//e.require
go.require(e.require, function () {
//e.controller.require
go.require(Go.getProp("controller.require", e), function () {
//e.action.require
go.require(Go.getProp("action.require", e), function () {
callback();
});
});
});
}
/***** Private Helpers *****/
// Confirm
// Use go-confirm, go-confirm="{verb}", or go-confirm="{message}"
// TODO: Add default message to config
// TODO: Remove this from core framework
function confirmAction(sender) {
if (isFunction(confirm) && sender) {
if (sender.is("[go-confirm]")) {
var val = sender.attr("go-confirm");
// Single word, assume is a verb
if (val.indexOf(" ") == -1) return confirm("Are you sure you want to " + val + "?");
// Assume is a full statement
else if (val.indexOf(" ") > -1) return confirm(val);
// No value, use generic confirm
else return confirm("Are you sure you want to do this?");
}
}
return true;
}