config.js | |
---|---|
/*global Ply, jQuery */
/*jshint eqeqeq: true, curly: true, white: true */ | |
The Config module provides hooks for many of the processes in Ply and is meant to be modified/replaced by the user. | Ply.config = (function ($) {
return { |
Core | core: { |
Error callbackThis function will get called for each JavaScript error. It receives the exception and severity. | onError: function (ex, sev) { |
ExamplePost the exception information including location and stack trace to a logging server. | $.post('/error/logclienterror', {
name: ex.name,
description: ex.description,
message: ex.message,
lineNumber: ex.lineNumber,
stackTrace: ex.stack
}); |
If the error is fatal, inform the user. | if (sev > 1) {
alert('An error has occurred. Please refresh your browser');
}
}
}, |
Read | read: { |
URL GeneratorIf no | urlGenerator: function (name) { |
ExampleReplace the underscores with slashes, remove all dashes, and prefix with
a | return '/' + name.replace('_', '/').replace('-', '').toLowerCase();
}
}, |
UI | ui: { |
BaseThe base object from which all views are copied. Any properties
created on this object will be available to every view created
using | base: {}, |
DefaultsThe default options for each view object. When the view is started, the
options defined in | defaults: {}, |
Selector generatorIf no | selectorGenerator: function (name) { |
ExampleSplit the name on title case, join using | var stub = name.match(/[A-Z]?[a-z]+/g).join('_').toLowerCase(),
controller = stub.split('_')[0]; |
Create a "stub" which consists of the controller and action name separated by an underscore. | stub = controller + "_" + stub.substr(controller.length + 1).replace('_', '-'); |
Return a selector consisting of a class matching | return '.view-' + stub + ', .' + stub;
}, |
Register callbackThis function is called every time | onRegister: function (name, options) { |
ExampleIf a truthy value (in this case, an object or | if (options.modal) { |
Make sure options.modal is an object so we can naively access properties on it. | options.modal = typeof options.modal === 'object' ? options.modal : {}; |
Create a new modal view by calling $.modal (using SimpleModal in this example) and pass in the view object as the modal element. | $.modal(options.view, { |
Pass in a predefined set of accessible properties on the modal option to the plugin. Done a) to abstract out the library in use underneath, b) to limit the overridable properties of modal. | containerId: options.modal.containerId,
dataClass: options.modal.dataClass,
maxWidth: options.modal.maxWidth || 300,
maxHeight: options.modal.maxHeight,
updateOnOpen: options.modal.updateOnOpen,
onShow: function (dialog) { |
When the modal view is shown, rebind | options.view = dialog.data; |
Call | Ply.ui.start(name, options); |
Put in modal boilerplate code, e.g. binding to close the modal. | dialog.data.delegate('.modal-close', 'click', function (e) {
e.preventDefault();
$.modal.close();
});
}
});
} |
Return false from this method to avoid | return;
}
}
}; |
Alias | })(jQuery);
|