X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fservices%2Ffoundation.core.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fservices%2Ffoundation.core.js;h=6aeb9dad0d33c2b921cb7d6aa75fbc86cb387fd4;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/services/foundation.core.js b/afb-client/bower_components/foundation-apps/js/angular/services/foundation.core.js new file mode 100644 index 0000000..6aeb9da --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/services/foundation.core.js @@ -0,0 +1,163 @@ +(function() { + 'use strict'; + + angular.module('foundation.core', [ + 'foundation.core.animation' + ]) + .service('FoundationApi', FoundationApi) + .service('FoundationAdapter', FoundationAdapter) + .factory('Utils', Utils) + ; + + FoundationApi.$inject = ['FoundationAnimation']; + + function FoundationApi(FoundationAnimation) { + var listeners = {}; + var settings = {}; + var uniqueIds = []; + var service = {}; + + service.subscribe = subscribe; + service.unsubscribe = unsubscribe; + service.publish = publish; + service.getSettings = getSettings; + service.modifySettings = modifySettings; + service.generateUuid = generateUuid; + service.toggleAnimate = toggleAnimate; + service.closeActiveElements = closeActiveElements; + service.animate = animate; + + return service; + + function subscribe(name, callback) { + if (!listeners[name]) { + listeners[name] = []; + } + + listeners[name].push(callback); + return true; + } + + function unsubscribe(name, callback) { + if (listeners[name] !== undefined) { + delete listeners[name]; + } + if (typeof callback == 'function') { + callback.call(this); + } + } + + function publish(name, msg) { + if (!listeners[name]) { + listeners[name] = []; + } + + listeners[name].forEach(function(cb) { + cb(msg); + }); + + return; + } + + function getSettings() { + return settings; + } + + function modifySettings(tree) { + settings = angular.extend(settings, tree); + return settings; + } + + function generateUuid() { + var uuid = ''; + + //little trick to produce semi-random IDs + do { + uuid += 'zf-uuid-'; + for (var i=0; i<15; i++) { + uuid += Math.floor(Math.random()*16).toString(16); + } + } while(!uniqueIds.indexOf(uuid)); + + uniqueIds.push(uuid); + return uuid; + } + + function toggleAnimate(element, futureState) { + FoundationAnimation.toggleAnimate(element, futureState); + } + + function closeActiveElements(options) { + var self = this; + options = options || {}; + var activeElements = document.querySelectorAll('.is-active[zf-closable]'); + // action sheets are nested zf-closable elements, so we have to target the parent + var nestedActiveElements = document.querySelectorAll('[zf-closable] > .is-active') + + if (activeElements.length) { + angular.forEach(activeElements, function(el) { + if (options.exclude !== el.id) { + self.publish(el.id, 'close'); + } + }); + } + if (nestedActiveElements.length) { + angular.forEach(nestedActiveElements, function(el) { + var parentId = el.parentNode.id; + if (options.exclude !== parentId) { + self.publish(parentId, 'close'); + } + }) + } + } + + function animate(element, futureState, animationIn, animationOut) { + FoundationAnimation.animate(element, futureState, animationIn, animationOut); + } + } + + FoundationAdapter.$inject = ['FoundationApi']; + + function FoundationAdapter(foundationApi) { + + var service = {}; + + service.activate = activate; + service.deactivate = deactivate; + + return service; + + function activate(target) { + foundationApi.publish(target, 'show'); + } + + function deactivate(target) { + foundationApi.publish(target, 'hide'); + } + } + + + function Utils() { + var utils = {}; + + utils.throttle = throttleUtil; + + return utils; + + function throttleUtil(func, delay) { + var timer = null; + + return function () { + var context = this, args = arguments; + + if (timer === null) { + timer = setTimeout(function () { + func.apply(context, args); + timer = null; + }, delay); + } + }; + } + } + +})();