diff options
| author | pliablepixels <pliablepixels@gmail.com> | 2016-02-18 16:12:42 -0500 |
|---|---|---|
| committer | pliablepixels <pliablepixels@gmail.com> | 2016-02-18 16:12:42 -0500 |
| commit | af74ef969c3cf21e78ee2e93e2956a8812512fe9 (patch) | |
| tree | c04d2d8718e260be9411a0f72d74ede8ef52b454 /www/js/app.js | |
| parent | 5e5f52e9af8b63f1444f2756f5a8816715b63a7a (diff) | |
#164 - initial fixes and refactoring
Former-commit-id: 5a21c98c22d8035454cf92eb7b7a4a2b65a4f0e3
Diffstat (limited to 'www/js/app.js')
| -rw-r--r-- | www/js/app.js | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/www/js/app.js b/www/js/app.js index b699d627..f4c2f819 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -41,7 +41,7 @@ angular.module('zmApp', [ authoremail: 'pliablepixels+zmNinja@gmail.com', logFileMaxSize: 20000, // after this limit log gets reset loginInterval: 300000, //5m*60s*1000 - ZM auto login after 5 mins - //loginInterval: 60000, + //loginInterval: 30000, updateCheckInterval: 86400000, // 24 hrs loadingTimeout: 15000, safeMontageLimit: 10, @@ -71,6 +71,7 @@ angular.module('zmApp', [ blogUrl:"http://pliablepixels.github.io/feed.json", nphSwitchTimer:6000, eventHistoryTimer:10000, + eventPlaybackQuery:3000, }) @@ -168,6 +169,112 @@ angular.module('zmApp', [ }; }) +//------------------------------------------------------- +// Ability to share controllers with modals +// Credit: http://codepen.io/julianpaulozzi/pen/wBgpjM +//------------------------------------------------------- + +.factory('appModalService', +['$ionicModal', '$rootScope', '$q', '$injector', '$controller', function($ionicModal, $rootScope, $q, $injector, $controller) { + + return { + show: show + }; + + function show(templateUrl, controller, parameters, options) { + // Grab the injector and create a new scope + var deferred = $q.defer(), + ctrlInstance, + modalScope = $rootScope.$new(), + thisScopeId = modalScope.$id, + defaultOptions = { + animation: 'slide-in-up', + focusFirstInput: false, + backdropClickToClose: true, + hardwareBackButtonClose: true, + modalCallback: null + }; + + options = angular.extend({}, defaultOptions, options); + + $ionicModal.fromTemplateUrl(templateUrl, { + scope: modalScope, + animation: options.animation, + focusFirstInput: options.focusFirstInput, + backdropClickToClose: options.backdropClickToClose, + hardwareBackButtonClose: options.hardwareBackButtonClose + }).then(function (modal) { + modalScope.modal = modal; + + modalScope.openModal = function () { + modalScope.modal.show(); + }; + modalScope.closeModal = function (result) { + deferred.resolve(result); + modalScope.modal.hide(); + }; + modalScope.$on('modal.hidden', function (thisModal) { + if (thisModal.currentScope) { + var modalScopeId = thisModal.currentScope.$id; + if (thisScopeId === modalScopeId) { + deferred.resolve(null); + _cleanup(thisModal.currentScope); + } + } + }); + + // Invoke the controller + var locals = { '$scope': modalScope, 'parameters': parameters }; + var ctrlEval = _evalController(controller); + ctrlInstance = $controller(controller, locals); + if (ctrlEval.isControllerAs) { + ctrlInstance.openModal = modalScope.openModal; + ctrlInstance.closeModal = modalScope.closeModal; + } + + modalScope.modal.show() + .then(function () { + modalScope.$broadcast('modal.afterShow', modalScope.modal); + }); + + if (angular.isFunction(options.modalCallback)) { + options.modalCallback(modal); + } + + }, function (err) { + deferred.reject(err); + }); + + return deferred.promise; + } + + function _cleanup(scope) { + scope.$destroy(); + if (scope.modal) { + scope.modal.remove(); + } + } + + function _evalController(ctrlName) { + var result = { + isControllerAs: false, + controllerName: '', + propName: '' + }; + var fragments = (ctrlName || '').trim().split(/\s+/); + result.isControllerAs = fragments.length === 3 && (fragments[1] || '').toLowerCase() === 'as'; + if (result.isControllerAs) { + result.controllerName = fragments[0]; + result.propName = fragments[2]; + } else { + result.controllerName = ctrlName; + } + + return result; + } + +}]) + //------------------------------------------------------------------ // this directive will be called any time an image completes loading // via img tags where this directive is added (I am using this in |
