Jamstash/app/common/page-service.js
Hyzual 3324113af8 When changing song, if fancybox is open, opens the new song's cover art in it
- Fixes a bug with the Page service. There was an error when changing songs.
- Removes fancyboxOpenImage from utils, it's directly in the main controller so we can call it from the directive. It didn't need to be in a service anymore since we have a player directive.
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) {
$interval.cancel(timer);
}
timer = $interval(function () {
var f = shift[opts.dir];
if (f) {
f(t);
title = t.join("");
}
}, opts.speed);
return this;
}
};
}]);