2015-02-27 21:52:56 +00:00
|
|
|
/**
|
|
|
|
* Service which helps set the contents of the <meta> tags (and the <title> of a page).
|
|
|
|
*/
|
|
|
|
angular.module('quay').factory('MetaService', ['$interpolate', 'Config', '$rootScope', '$interval',
|
|
|
|
function($interpolate, Config, $rootScope, $interval) {
|
|
|
|
var metaService = {};
|
2015-02-27 22:22:47 +00:00
|
|
|
var intervals = [];
|
2015-02-27 21:52:56 +00:00
|
|
|
|
|
|
|
var interpolate = function(page, expr, callback) {
|
2015-02-27 22:22:47 +00:00
|
|
|
var previous = '';
|
|
|
|
|
|
|
|
var currentInterval = $interval(function() {
|
2015-02-27 21:52:56 +00:00
|
|
|
var inter = $interpolate(expr, true, null, true);
|
2015-02-27 22:22:47 +00:00
|
|
|
var result = inter(page.scope)
|
|
|
|
|
|
|
|
if (result != previous) {
|
|
|
|
$interval.cancel(currentInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
previous = result;
|
|
|
|
callback(result);
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
intervals.push(currentInterval);
|
2015-02-27 21:52:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var initial = function(value, default_value, callback) {
|
2015-02-27 22:22:47 +00:00
|
|
|
for (var i = 0; i < intervals.length; ++i) {
|
|
|
|
$interval.cancel(intervals[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
intervals = [];
|
|
|
|
|
2015-02-27 21:52:56 +00:00
|
|
|
if (!value) {
|
|
|
|
callback(default_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value.indexOf('{{') < 0) {
|
|
|
|
callback(default_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback('Loading...');
|
|
|
|
};
|
|
|
|
|
|
|
|
metaService.getInitialTitle = function(page, callback) {
|
|
|
|
var route = page.$$route;
|
|
|
|
initial(route && route.title, Config.REGISTRY_TITLE_SHORT, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
metaService.getInitialDescription = function(page, callback) {
|
|
|
|
var route = page.$$route;
|
|
|
|
initial(route && route.description, Config.REGISTRY_TITLE_SHORT, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
metaService.getTitle = function(page, callback) {
|
|
|
|
var route = page.$$route;
|
|
|
|
if (!route || !route.title || route.title.indexOf('{{') < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
interpolate(page, route.title, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
metaService.getDescription = function(page, callback) {
|
|
|
|
var route = page.$$route;
|
|
|
|
if (!route || !route.description || route.description.indexOf('{{') < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
interpolate(page, route.description, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
return metaService;
|
|
|
|
}]);
|