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%2Fcomponents%2Finterchange%2Finterchange.js;fp=afb-client%2Fbower_components%2Ffoundation-apps%2Fjs%2Fangular%2Fcomponents%2Finterchange%2Finterchange.js;h=74ea8977c4b3dc9504699d8cca3254c257687097;hp=0000000000000000000000000000000000000000;hb=5b1e6cc132f44262a873fa8296a2a3e1017b0278;hpb=f7d2f9ac4168ee5064580c666d508667a73cefc0 diff --git a/afb-client/bower_components/foundation-apps/js/angular/components/interchange/interchange.js b/afb-client/bower_components/foundation-apps/js/angular/components/interchange/interchange.js new file mode 100644 index 0000000..74ea897 --- /dev/null +++ b/afb-client/bower_components/foundation-apps/js/angular/components/interchange/interchange.js @@ -0,0 +1,94 @@ +(function() { + 'use strict'; + + angular.module('foundation.interchange', ['foundation.core', 'foundation.mediaquery']) + .directive('zfInterchange', zfInterchange) + ; + + zfInterchange.$inject = [ '$compile', '$http', '$templateCache', 'FoundationApi', 'FoundationMQ']; + + function zfInterchange($compile, $http, $templateCache, foundationApi, foundationMQ) { + + var directive = { + restrict: 'EA', + transclude: 'element', + scope: { + position: '@' + }, + replace: true, + template: '
', + link: link + }; + + return directive; + + function link(scope, element, attrs, ctrl, transclude) { + var childScope, current, scenarios, innerTemplates; + + var globalQueries = foundationMQ.getMediaQueries(); + + //setup + foundationApi.subscribe('resize', function(msg) { + transclude(function(clone, newScope) { + if(!scenarios || !innerTemplates) { + collectInformation(clone); + } + + var ruleMatches = foundationMQ.match(scenarios); + var scenario = ruleMatches.length === 0 ? null : scenarios[ruleMatches[0].ind]; + + //this could use some love + if(scenario && checkScenario(scenario)) { + var compiled; + + if(childScope) { + childScope.$destroy(); + childScope = null; + } + + if(typeof scenario.templ !== 'undefined') { + childScope = newScope; + + //temp container + var tmp = document.createElement('div'); + tmp.appendChild(innerTemplates[scenario.templ][0]); + + element.html(tmp.innerHTML); + $compile(element.contents())(childScope); + current = scenario; + } else { + var loader = templateLoader(scenario.src); + loader.success(function(html) { + childScope = newScope; + element.html(html); + }).then(function(){ + $compile(element.contents())(childScope); + current = scenario; + }); + } + } + }); + + }); + + //init + foundationApi.publish('resize', 'initial resize'); + + function templateLoader(templateUrl) { + return $http.get(templateUrl, {cache: $templateCache}); + } + + function collectInformation(el) { + var data = foundationMQ.collectScenariosFromElement(el); + + scenarios = data.scenarios; + innerTemplates = data.templates; + } + + function checkScenario(scenario) { + return !current || current !== scenario; + } + } + } + +})();