Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

update handling of resize message #806

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions js/angular/components/iconic/iconic.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@
var svgElement, ico = iconic.getAccess();

injectSvg(element[0]);

// subscribe for resize events
foundationApi.subscribe('resize', resize);

foundationApi.subscribe('resize', function () {
// only run update on current element
ico.update(element[0]);
scope.$on("$destroy", function() {
foundationApi.unsubscribe('resize', resize);
});

// handle dynamic updating of src
Expand Down Expand Up @@ -249,6 +251,11 @@
}
});
}

function resize() {
// run update on current element
ico.update(element[0]);
}
}

function addDataDash(attr) {
Expand Down
67 changes: 37 additions & 30 deletions js/angular/components/interchange/interchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,32 @@

var globalQueries = foundationMQ.getMediaQueries();

//setup
foundationApi.subscribe('resize', function(msg) {
// subscribe for resize events
foundationApi.subscribe('resize', resize);

scope.$on("$destroy", function() {
foundationApi.unsubscribe('resize', resize);
});

//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;
}

function resize(msg) {
transclude(function(clone, newScope) {
if(!scenarios || !innerTemplates) {
collectInformation(clone);
Expand Down Expand Up @@ -68,25 +92,6 @@
}
}
});

});

//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;
}
}
}
Expand Down Expand Up @@ -220,17 +225,10 @@

function postLink(scope, element, attrs) {
// subscribe for resize events
foundationApi.subscribe('resize', function() {
var orignalVisibilty = scope[queryResult];
runQuery();
if (orignalVisibilty != scope[queryResult]) {
// digest if visibility changed
scope.$digest();
}
});
foundationApi.subscribe('resize', resize);

scope.$on("$destroy", function() {
foundationApi.unsubscribe('resize');
foundationApi.unsubscribe('resize', resize);
});

// run first media query check
Expand All @@ -255,6 +253,15 @@
}
}
}

function resize() {
var orignalVisibilty = scope[queryResult];
runQuery();
if (orignalVisibilty != scope[queryResult]) {
// digest if visibility changed
scope.$digest();
}
}
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion js/angular/services/foundation.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,27 @@
}

function unsubscribe(name, callback) {
var listenerIndex = -1, i, resizeListeners;

if (listeners[name] !== undefined) {
delete listeners[name];
if (name == 'resize') {
resizeListeners = listeners['resize'];
for (i = 0; i < resizeListeners.length; i++) {
if (resizeListeners[i] === callback) {
// listener found
listenerIndex = i;
break;
}
}

if (listenerIndex != -1) {
// remove listener
resizeListeners.splice(listenerIndex, 1);
}
} else {
// delete all listeners
delete listeners[name];
}
}
if (typeof callback == 'function') {
callback.call(this);
Expand Down