cheeky-angular
Version:
Angular Components for Cheeky CMS
2 lines • 1.35 kB
JavaScript
!function(window,angular){"use strict";angular.module("cheeky",["angular-cache"]).directive("cheekyContent",["cheekyCMS",function(content){return{restrict:"EA",link:function(scope,element,attrs){var path=attrs.path||attrs.cheekyContent;content.fetch(path).then(function(data){data?element.html(data):console.log("[cheeky]","No content found for path",path)})}}}]).directive("cheekyEditable",["cheekyCMS",function(){return{link:function(scope,element,attrs){if(aloha){{attrs.path||attrs.cheekyContent}aloha(angular.element(element)[0])}}}}]).provider("cheekyCMS",[function(){var CACHE_KEY="cheeky",CACHE_LIFETIME=9e5,STORAGE_MODE="localStorage",KEY_MAP={};this.map=function(m){KEY_MAP=m},this.$get=["$q","$http","CacheFactory",function($q,$http,CacheFactory){function fetch(path){var deferred=$q.defer(),parts=path.split("."),ns=parts[0],cp=parts.slice(1).join(".");return _fetch(ns).then(function(cache){deferred.resolve(_.get(cache,cp))}),deferred.promise}function warmup(ns){_fetch(ns)}function _fetch(ns){var deferred=$q.defer();return $http.get(KEY_MAP[ns],{cache:CacheFactory.get(CACHE_KEY)}).success(function(data){deferred.resolve(data)}),deferred.promise}return CacheFactory(CACHE_KEY,{maxAge:CACHE_LIFETIME,storageMode:STORAGE_MODE}),{fetch:fetch,warmup:warmup}}]}])}(window,angular);
//# sourceMappingURL=../dist/cheeky-angular.min.js.map