Skip to content

Commit

Permalink
Fixes to make things just work
Browse files Browse the repository at this point in the history
  • Loading branch information
AntJanus committed Jan 16, 2015
1 parent 8526dfe commit ebba546
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 42 deletions.
28 changes: 6 additions & 22 deletions js/angular/components/interchange/interchange.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function() {
'use strict';

angular.module('foundation.interchange', ['foundation.core', 'foundation.mediaqueries'])
angular.module('foundation.interchange', ['foundation.core', 'foundation.mediaquery'])
.directive('zfInterchange', zfInterchange)
;

zfInterchange.$inject = [ '$compile', '$http', '$templateCache', '$animate', 'FoundationApi', 'FoundationMQ'];
zfInterchange.$inject = [ '$compile', '$http', '$templateCache', 'FoundationApi', 'FoundationMQ'];

function zfInterchange($compile, $http, $templateCache, foundationApi, foundationMQ) {

Expand Down Expand Up @@ -78,27 +78,11 @@
return $http.get(templateUrl, {cache: $templateCache});
}

function collectInformation(parentElement) {
scenarios = [];
innerTemplates = [];
function collectInformation(el) {
var data = foundationMQ.collectScenariosFromElement(el);

var elements = parentElement.children();
var i = 0;

angular.forEach(elements, function(el) {
var elem = angular.element(el);


//if no source or no html, capture element itself
if (!elem.attr('src') || !elem.attr('src').match(/.html$/)) {
innerTemplates[i] = elem;
scenarios[i] = { media: elem.attr('media'), templ: i };
} else {
scenarios[i] = { media: elem.attr('media'), src: elem.attr('src') };
}

i++;
});
scenarios = data.scenarios;
innerTemplates = data.templates;
}

function checkScenario(scenario) {
Expand Down
43 changes: 23 additions & 20 deletions js/angular/services/foundation.mediaquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@
function FoundationMQ(foundationApi) {
var service = [];

var subscribers = [];

service.getMediaQueries = getMediaQueries;
service.matched = matched;
service.match = match;
service.collectScenariosFromElement = collectScenariosFromElement;

return service;

Expand Down Expand Up @@ -167,29 +166,33 @@
return matches;
}

function registerMediaCallback(media) {
window.matchMedia(media, mqListener);
}
// Collects a scenario object and templates from element
function collectScenariosFromElement(parentElement) {
var scenarios = [];
var templates = [];

function mqListener(media) {
if(media.matches && subscribers[media.matches]) {
subscribers.forEach(function(subscriber) {
subscriber();
});
}
var elements = parentElement.children();
var i = 0;

}
angular.forEach(elements, function(el) {
var elem = angular.element(el);

function subscribeMedia(media, cb) {
if(!subscribers[media]){
subscribers[media] = [];

}

subscribers[media].push(cb);
//if no source or no html, capture element itself
if (!elem.attr('src') || !elem.attr('src').match(/.html$/)) {
templates[i] = elem;
scenarios[i] = { media: elem.attr('media'), templ: i };
} else {
scenarios[i] = { media: elem.attr('media'), src: elem.attr('src') };
}

registerMediaCallback(media, cb);
i++;
});

return {
scenarios: scenarios,
templates: templates
};
}
}
})();

0 comments on commit ebba546

Please sign in to comment.