Jamstash/app/common/page-service.js
Hyzual c478f0116f Replaced utils setTitle and scrollTitle by a dedicated service
- Adds a Page service that will control the page's title from anywhere.
- Adds a setTitleSong method. It takes a song as parameter, that way
  player-directive isn't responsible for correctly formatting the title. It also scrolls the title if the global setting is true
- Removes the title-related methods from utils-service
2015-01-17 19:15:09 +01:00

64 lines
1.7 KiB
JavaScript

/**
* jamstash.page Module
*
* Set the page's title from anywhere, the angular way
*/
angular.module('jamstash.page', ['jamstash.settings', 'jamstash.utils'])
.factory('Page', ['$interval', 'globals', 'utils', function($interval, globals, utils){
'use strict';
var title = 'Jamstash';
var timer;
return {
title: function() { return title; },
setTitle: function(newTitle) {
title = newTitle;
return this;
},
setTitleSong: function(song) {
if (song.artist !== undefined && song.name !== undefined) {
title = utils.toHTML.un(song.artist) + " - " + utils.toHTML.un(song.name);
} else {
title = 'Jamstash';
}
if (globals.settings.ScrollTitle) {
this.scrollTitle();
}
return this;
},
scrollTitle: function() {
var shift = {
"left": function (a) {
a.push(a.shift());
},
"right": function (a) {
a.unshift(a.pop());
}
};
var opts = {
text: title,
dir: "left",
speed: 1200
};
var t = (opts.text).split("");
if (!t) {
return;
}
t.push(" ");
if (timer !== undefined) {
timer.cancel();
}
timer = $interval(function () {
var f = shift[opts.dir];
if (f) {
f(t);
title = t.join("");
}
}, opts.speed);
return this;
}
};
}]);