4 angular.module('foundation.core', [
5 'foundation.core.animation'
7 .service('FoundationApi', FoundationApi)
8 .service('FoundationAdapter', FoundationAdapter)
9 .factory('Utils', Utils)
12 FoundationApi.$inject = ['FoundationAnimation'];
14 function FoundationApi(FoundationAnimation) {
20 service.subscribe = subscribe;
21 service.unsubscribe = unsubscribe;
22 service.publish = publish;
23 service.getSettings = getSettings;
24 service.modifySettings = modifySettings;
25 service.generateUuid = generateUuid;
26 service.toggleAnimate = toggleAnimate;
27 service.closeActiveElements = closeActiveElements;
28 service.animate = animate;
32 function subscribe(name, callback) {
33 if (!listeners[name]) {
37 listeners[name].push(callback);
41 function unsubscribe(name, callback) {
42 if (listeners[name] !== undefined) {
43 delete listeners[name];
45 if (typeof callback == 'function') {
50 function publish(name, msg) {
51 if (!listeners[name]) {
55 listeners[name].forEach(function(cb) {
62 function getSettings() {
66 function modifySettings(tree) {
67 settings = angular.extend(settings, tree);
71 function generateUuid() {
74 //little trick to produce semi-random IDs
77 for (var i=0; i<15; i++) {
78 uuid += Math.floor(Math.random()*16).toString(16);
80 } while(!uniqueIds.indexOf(uuid));
86 function toggleAnimate(element, futureState) {
87 FoundationAnimation.toggleAnimate(element, futureState);
90 function closeActiveElements(options) {
92 options = options || {};
93 var activeElements = document.querySelectorAll('.is-active[zf-closable]');
94 // action sheets are nested zf-closable elements, so we have to target the parent
95 var nestedActiveElements = document.querySelectorAll('[zf-closable] > .is-active')
97 if (activeElements.length) {
98 angular.forEach(activeElements, function(el) {
99 if (options.exclude !== el.id) {
100 self.publish(el.id, 'close');
104 if (nestedActiveElements.length) {
105 angular.forEach(nestedActiveElements, function(el) {
106 var parentId = el.parentNode.id;
107 if (options.exclude !== parentId) {
108 self.publish(parentId, 'close');
114 function animate(element, futureState, animationIn, animationOut) {
115 FoundationAnimation.animate(element, futureState, animationIn, animationOut);
119 FoundationAdapter.$inject = ['FoundationApi'];
121 function FoundationAdapter(foundationApi) {
125 service.activate = activate;
126 service.deactivate = deactivate;
130 function activate(target) {
131 foundationApi.publish(target, 'show');
134 function deactivate(target) {
135 foundationApi.publish(target, 'hide');
143 utils.throttle = throttleUtil;
147 function throttleUtil(func, delay) {
151 var context = this, args = arguments;
153 if (timer === null) {
154 timer = setTimeout(function () {
155 func.apply(context, args);