Jamstash/app/common/page-service.js
Hyzual a97e5159bc Uses angular-locker to store settings in localStorage
- settings.js now has its own module : 'jamstash.settings.controller'. This makes it easier to test it and identify what dependencies it has.
- Renames 'jamstash.settings' module into 'jamstash.settings.service'
- Adds an angular constant to hold the current Jamstash version in app.js.
- Adds a way to upgrade incrementally what was in localStorage : in 4.4.5, DefaultSearchType will no longer be an object but an int, so we must init it with an int value, otherwise a blank option will be displayed. We detect what version we are using and what version was stored using persistence-service.js and run the upgrade accordingly.

- Refactors almost completely persistence-service_test.js
- Unit-tests some of settings.js's methods.
2015-03-24 18:36:54 +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.service', '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;
}
};
}]);