Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.KDJ || (window.KDJ = {}); //namespace
- KDJ.controller = (function () {
- $(document).off('PAGE_DISPLAYED');
- $(document).on('PAGE_DISPLAYED', function (e, data) {
- if(data.customFunction !== undefined) {
- //do things if you want
- data.customFunction();
- //do things if you want
- // here I use the return to pass by the switch
- //you could use another property like if(data.useSwitch) => switch() or simply use an else clause
- return;
- }
- switch(data.pageId) {
- case "page1":
- // do something..
- break;
- default:
- break;
- }
- });
- return {
- // exported methods and props..
- };
- })();
- KDJ.view = (function () {
- // ...
- $(document).off('pagechange');
- //This object its optional, you could pass it explicitly everywhere.
- var pageDisplayedObj = {
- 'pageId': loadedPageId,
- 'key': key,
- customFunction: function() {}
- }
- $(document).on('pagechange', function (e, ui) {
- //I redefine customFunction to do what I need, again, you could pass pageDisplayedObj explicitly
- pageDisplayedObj.customFunction = function(ui) {
- console.log("I'm doing something awesome with the ui!");
- };
- $(document).trigger(PAGE_DISPLAYED, pageDisplayedObj);
- });
- $(document).on('pagechange', function (e, ui) {
- //here I'll use the switch
- pageDisplayedObj.customFunction = undefined;
- $(document).trigger(PAGE_DISPLAYED, pageDisplayedObj);
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement