js-beautify all the controllers, services and directives (and jshint)
This commit is contained in:
parent
95f7ef53f2
commit
bb7d018de4
23 changed files with 2533 additions and 3446 deletions
350
js/utils.js
350
js/utils.js
|
@ -1,15 +1,17 @@
|
|||
JamStash.service('utils', function ($cookieStore, globals, model) {
|
||||
this.safeApply = function (fn) {
|
||||
JamStash.service('utils', function($cookieStore, globals, model) {
|
||||
|
||||
this.safeApply = function(fn) {
|
||||
var phase = this.$root.$$phase;
|
||||
if (phase == '$apply' || phase == '$digest') {
|
||||
if (fn && (typeof (fn) === 'function')) {
|
||||
if (fn && (typeof(fn) === 'function')) {
|
||||
fn();
|
||||
}
|
||||
} else {
|
||||
this.$apply(fn);
|
||||
}
|
||||
};
|
||||
this.setValue = function (key, value, notify) {
|
||||
|
||||
this.setValue = function(key, value, notify) {
|
||||
/*
|
||||
if (value !== null) {
|
||||
$cookieStore.put(key, value);
|
||||
|
@ -22,10 +24,13 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
try {
|
||||
localStorage.setItem(key, JSON.stringify(value));
|
||||
} catch (e) {
|
||||
if (globals.settings.Debug) { console.log(e); }
|
||||
if (globals.settings.Debug) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.getValue = function (value) {
|
||||
};
|
||||
|
||||
this.getValue = function(value) {
|
||||
/*
|
||||
if ($cookieStore.get(value)) {
|
||||
return $cookieStore.get(value);
|
||||
|
@ -35,57 +40,93 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
*/
|
||||
try {
|
||||
var item = localStorage.getItem(value);
|
||||
if (item != '' && typeof item != 'undefined') {
|
||||
if (item !== '' && typeof item != 'undefined') {
|
||||
return JSON.parse(item);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
if (globals.settings.Debug) { console.log(e); }
|
||||
if (globals.settings.Debug) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.mapSong = function (data) {
|
||||
};
|
||||
|
||||
this.mapSong = function(data) {
|
||||
var song = data;
|
||||
var url, title, track, rating, starred, contenttype, suffix, description;
|
||||
var specs = '', coverartthumb = '', coverartfull = '';
|
||||
var specs = '',
|
||||
coverartthumb = '',
|
||||
coverartfull = '';
|
||||
if (typeof song.coverArt != 'undefined') {
|
||||
coverartthumb = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&size=60&id=' + song.coverArt;
|
||||
coverartfull = globals.BaseURL() + '/getCoverArt.view?' + globals.BaseParams() + '&id=' + song.coverArt;
|
||||
}
|
||||
if (typeof song.description == 'undefined') { description = ''; } else { description = song.description; }
|
||||
if (typeof song.title == 'undefined') { title = ' '; } else { title = song.title.toString(); }
|
||||
if (typeof song.track == 'undefined') { track = ' '; } else { track = song.track.toString(); }
|
||||
if (typeof song.starred !== 'undefined') { starred = true; } else { starred = false; }
|
||||
if (song.bitRate !== undefined) { specs += song.bitRate + ' Kbps'; }
|
||||
if (song.transcodedSuffix !== undefined) { specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix; } else { specs += ', ' + song.suffix; }
|
||||
if (song.transcodedSuffix !== undefined) { suffix = song.transcodedSuffix; } else { suffix = song.suffix; }
|
||||
if (suffix == 'ogg') { suffix = 'oga'; }
|
||||
if (typeof song.description == 'undefined') {
|
||||
description = '';
|
||||
} else {
|
||||
description = song.description;
|
||||
}
|
||||
if (typeof song.title == 'undefined') {
|
||||
title = ' ';
|
||||
} else {
|
||||
title = song.title.toString();
|
||||
}
|
||||
if (typeof song.track == 'undefined') {
|
||||
track = ' ';
|
||||
} else {
|
||||
track = song.track.toString();
|
||||
}
|
||||
if (typeof song.starred !== 'undefined') {
|
||||
starred = true;
|
||||
} else {
|
||||
starred = false;
|
||||
}
|
||||
if (song.bitRate !== undefined) {
|
||||
specs += song.bitRate + ' Kbps';
|
||||
}
|
||||
if (song.transcodedSuffix !== undefined) {
|
||||
specs += ', transcoding:' + song.suffix + ' > ' + song.transcodedSuffix;
|
||||
} else {
|
||||
specs += ', ' + song.suffix;
|
||||
}
|
||||
if (song.transcodedSuffix !== undefined) {
|
||||
suffix = song.transcodedSuffix;
|
||||
} else {
|
||||
suffix = song.suffix;
|
||||
}
|
||||
if (suffix == 'ogg') {
|
||||
suffix = 'oga';
|
||||
}
|
||||
var salt = Math.floor(Math.random() * 100000);
|
||||
url = globals.BaseURL() + '/stream.view?' + globals.BaseParams() + '&id=' + song.id + '&salt=' + salt;
|
||||
return new model.Song(song.id, song.parent, track, title, song.artist, song.artistId, song.album, song.albumId, coverartthumb, coverartfull, song.duration, song.userRating, starred, suffix, specs, url, 0, description);
|
||||
}
|
||||
this.confirmDelete = function (text) {
|
||||
};
|
||||
|
||||
this.confirmDelete = function(text) {
|
||||
var question = confirm(text);
|
||||
if (question) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.makeBaseAuth = function (user, password) {
|
||||
};
|
||||
|
||||
this.makeBaseAuth = function(user, password) {
|
||||
var tok = user + ':' + password;
|
||||
var hash = $.base64Encode(tok);
|
||||
return "Basic " + hash;
|
||||
}
|
||||
this.HexEncode = function (n) {
|
||||
};
|
||||
|
||||
this.HexEncode = function(n) {
|
||||
for (var u = "0123456789abcdef", i = [], r = [], t = 0; t < 256; t++)
|
||||
i[t] = u.charAt(t >> 4) + u.charAt(t & 15);
|
||||
for (t = 0; t < n.length; t++)
|
||||
r[t] = i[n.charCodeAt(t)];
|
||||
return r.join("")
|
||||
}
|
||||
this.switchTheme = function (theme) {
|
||||
return r.join("");
|
||||
};
|
||||
|
||||
this.switchTheme = function(theme) {
|
||||
switch (theme.toLowerCase()) {
|
||||
case 'dark':
|
||||
$('link[data-name=theme]').attr('href', 'style/Dark.css');
|
||||
|
@ -96,16 +137,18 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// HTML5
|
||||
this.browserStorageCheck = function () {
|
||||
if (typeof (localStorage) == 'undefined') {
|
||||
this.browserStorageCheck = function() {
|
||||
if (typeof(localStorage) == 'undefined') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.timeToSeconds = function (time) {
|
||||
};
|
||||
|
||||
this.timeToSeconds = function(time) {
|
||||
var a = time.split(':'); // split it at the colons
|
||||
var seconds;
|
||||
switch (a.length) {
|
||||
|
@ -122,8 +165,9 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
break;
|
||||
}
|
||||
return seconds;
|
||||
}
|
||||
this.secondsToTime = function (secs) {
|
||||
};
|
||||
|
||||
this.secondsToTime = function(secs) {
|
||||
// secs = 4729
|
||||
var times = new Array(3600, 60, 1);
|
||||
var time = '';
|
||||
|
@ -135,12 +179,10 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
// 2: 49/1 = 49
|
||||
if (tmp < 1) {
|
||||
tmp = '00';
|
||||
}
|
||||
else if (tmp < 10) {
|
||||
} else if (tmp < 10) {
|
||||
tmp = '0' + tmp;
|
||||
}
|
||||
if (i == 0 && tmp == '00') {
|
||||
} else {
|
||||
if (i === 0 && tmp == '00') {} else {
|
||||
time += tmp;
|
||||
if (i < 2) {
|
||||
time += ':';
|
||||
|
@ -149,27 +191,30 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
secs = secs % times[i];
|
||||
}
|
||||
return time;
|
||||
}
|
||||
this.arrayObjectIndexOf = function (myArray, searchTerm, property) {
|
||||
};
|
||||
|
||||
this.arrayObjectIndexOf = function(myArray, searchTerm, property) {
|
||||
for (var i = 0, len = myArray.length; i < len; i++) {
|
||||
if (myArray[i][property] === searchTerm) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
this.logObjectProperties = function (obj) {
|
||||
$.each(obj, function (key, value) {
|
||||
};
|
||||
|
||||
this.logObjectProperties = function(obj) {
|
||||
$.each(obj, function(key, value) {
|
||||
var parent = key;
|
||||
if (typeof value === "object") {
|
||||
$.each(value, function (key, value) {
|
||||
$.each(value, function(key, value) {
|
||||
console.log(parent + ' > ' + key + ' : ' + value);
|
||||
});
|
||||
} else {
|
||||
console.log(key + ' : ' + value);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.clickButton = function (el) {
|
||||
var el = $(el);
|
||||
};
|
||||
|
||||
this.clickButton = function(el) {
|
||||
el = $(el);
|
||||
if (el) {
|
||||
var classes = $(el).attr('class').split(" ");
|
||||
for (var i = 0, l = classes.length; i < l; ++i) {
|
||||
|
@ -186,86 +231,143 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.findKeyForCode = function (code) {
|
||||
var map = { 'keymap': [
|
||||
{ 'key': 'a', 'code': 65 },
|
||||
{ 'key': 'b', 'code': 66 },
|
||||
{ 'key': 'c', 'code': 67 },
|
||||
{ 'key': 'd', 'code': 68 },
|
||||
{ 'key': 'e', 'code': 69 },
|
||||
{ 'key': 'f', 'code': 70 },
|
||||
{ 'key': 'g', 'code': 71 },
|
||||
{ 'key': 'h', 'code': 72 },
|
||||
{ 'key': 'i', 'code': 73 },
|
||||
{ 'key': 'j', 'code': 74 },
|
||||
{ 'key': 'k', 'code': 75 },
|
||||
{ 'key': 'l', 'code': 76 },
|
||||
{ 'key': 'm', 'code': 77 },
|
||||
{ 'key': 'n', 'code': 78 },
|
||||
{ 'key': 'o', 'code': 79 },
|
||||
{ 'key': 'p', 'code': 80 },
|
||||
{ 'key': 'q', 'code': 81 },
|
||||
{ 'key': 'r', 'code': 82 },
|
||||
{ 'key': 's', 'code': 83 },
|
||||
{ 'key': 't', 'code': 84 },
|
||||
{ 'key': 'u', 'code': 85 },
|
||||
{ 'key': 'v', 'code': 86 },
|
||||
{ 'key': 'w', 'code': 87 },
|
||||
{ 'key': 'x', 'code': 88 },
|
||||
{ 'key': 'y', 'code': 89 },
|
||||
{ 'key': 'z', 'code': 90 }
|
||||
]
|
||||
};
|
||||
|
||||
this.findKeyForCode = function(code) {
|
||||
var map = {
|
||||
'keymap': [{
|
||||
'key': 'a',
|
||||
'code': 65
|
||||
}, {
|
||||
'key': 'b',
|
||||
'code': 66
|
||||
}, {
|
||||
'key': 'c',
|
||||
'code': 67
|
||||
}, {
|
||||
'key': 'd',
|
||||
'code': 68
|
||||
}, {
|
||||
'key': 'e',
|
||||
'code': 69
|
||||
}, {
|
||||
'key': 'f',
|
||||
'code': 70
|
||||
}, {
|
||||
'key': 'g',
|
||||
'code': 71
|
||||
}, {
|
||||
'key': 'h',
|
||||
'code': 72
|
||||
}, {
|
||||
'key': 'i',
|
||||
'code': 73
|
||||
}, {
|
||||
'key': 'j',
|
||||
'code': 74
|
||||
}, {
|
||||
'key': 'k',
|
||||
'code': 75
|
||||
}, {
|
||||
'key': 'l',
|
||||
'code': 76
|
||||
}, {
|
||||
'key': 'm',
|
||||
'code': 77
|
||||
}, {
|
||||
'key': 'n',
|
||||
'code': 78
|
||||
}, {
|
||||
'key': 'o',
|
||||
'code': 79
|
||||
}, {
|
||||
'key': 'p',
|
||||
'code': 80
|
||||
}, {
|
||||
'key': 'q',
|
||||
'code': 81
|
||||
}, {
|
||||
'key': 'r',
|
||||
'code': 82
|
||||
}, {
|
||||
'key': 's',
|
||||
'code': 83
|
||||
}, {
|
||||
'key': 't',
|
||||
'code': 84
|
||||
}, {
|
||||
'key': 'u',
|
||||
'code': 85
|
||||
}, {
|
||||
'key': 'v',
|
||||
'code': 86
|
||||
}, {
|
||||
'key': 'w',
|
||||
'code': 87
|
||||
}, {
|
||||
'key': 'x',
|
||||
'code': 88
|
||||
}, {
|
||||
'key': 'y',
|
||||
'code': 89
|
||||
}, {
|
||||
'key': 'z',
|
||||
'code': 90
|
||||
}]
|
||||
};
|
||||
var keyFound = 0;
|
||||
$.each(map.keymap, function (i, mapping) {
|
||||
$.each(map.keymap, function(i, mapping) {
|
||||
if (mapping.code === code) {
|
||||
keyFound = mapping.key;
|
||||
}
|
||||
});
|
||||
return keyFound;
|
||||
}
|
||||
};
|
||||
|
||||
this.toHTML = {
|
||||
on: function (str) {
|
||||
on: function(str) {
|
||||
var a = [],
|
||||
i = 0;
|
||||
for (; i < str.length; ) a[i] = str.charCodeAt(i++);
|
||||
return "&#" + a.join(";&#") + ";"
|
||||
i = 0;
|
||||
for (; i < str.length;) a[i] = str.charCodeAt(i++);
|
||||
return "&#" + a.join(";&#") + ";";
|
||||
},
|
||||
un: function (str) {
|
||||
un: function(str) {
|
||||
return str.replace(/&#(x)?([^;]{1,5});?/g,
|
||||
function (a, b, c) {
|
||||
return String.fromCharCode(parseInt(c, b ? 16 : 10))
|
||||
})
|
||||
function(a, b, c) {
|
||||
return String.fromCharCode(parseInt(c, b ? 16 : 10));
|
||||
});
|
||||
}
|
||||
};
|
||||
this.getParameterByName = function (name) {
|
||||
this.getParameterByName = function(name) {
|
||||
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
||||
var regexS = "[\\?&]" + name + "=([^&#]*)";
|
||||
var regex = new RegExp(regexS);
|
||||
var results = regex.exec(window.location.search);
|
||||
if (results == null)
|
||||
if (results === null)
|
||||
return "";
|
||||
else
|
||||
return decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
}
|
||||
this.getPathFromUrl = function (url) {
|
||||
};
|
||||
|
||||
this.getPathFromUrl = function(url) {
|
||||
var strurl = url.toString();
|
||||
var u = strurl.substring(0, strurl.indexOf('?'));
|
||||
return u
|
||||
}
|
||||
this.setTitle = function (text) {
|
||||
if (text != "") {
|
||||
return u;
|
||||
};
|
||||
|
||||
this.setTitle = function(text) {
|
||||
if (text !== "") {
|
||||
document.title = text;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var timer = 0;
|
||||
this.scrollTitle = function (text) {
|
||||
this.scrollTitle = function(text) {
|
||||
var shift = {
|
||||
"left": function (a) {
|
||||
"left": function(a) {
|
||||
a.push(a.shift());
|
||||
},
|
||||
"right": function (a) {
|
||||
"right": function(a) {
|
||||
a.unshift(a.pop());
|
||||
}
|
||||
};
|
||||
|
@ -281,23 +383,19 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
}
|
||||
t.push(" ");
|
||||
clearInterval(timer);
|
||||
timer = setInterval(function () {
|
||||
timer = setInterval(function() {
|
||||
var f = shift[opts.dir];
|
||||
if (f) {
|
||||
f(t);
|
||||
document.title = t.join("");
|
||||
}
|
||||
}, opts.speed);
|
||||
/*
|
||||
$.marqueeTitle({
|
||||
text: text,
|
||||
dir: "left",
|
||||
speed: 1200
|
||||
});
|
||||
*/
|
||||
}
|
||||
this.parseVersionString = function (str) {
|
||||
if (typeof (str) != 'string') { return false; }
|
||||
};
|
||||
|
||||
this.parseVersionString = function(str) {
|
||||
if (typeof(str) != 'string') {
|
||||
return false;
|
||||
}
|
||||
var x = str.split('.');
|
||||
// parse from string or default to 0 if can't parse
|
||||
var maj = parseInt(x[0]) || 0;
|
||||
|
@ -307,9 +405,10 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
major: maj,
|
||||
minor: min,
|
||||
patch: pat
|
||||
}
|
||||
}
|
||||
this.checkVersion = function (runningVersion, minimumVersion) {
|
||||
};
|
||||
};
|
||||
|
||||
this.checkVersion = function(runningVersion, minimumVersion) {
|
||||
if (runningVersion.major >= minimumVersion.major) {
|
||||
if (runningVersion.minor >= minimumVersion.minor) {
|
||||
if (runningVersion.patch >= minimumVersion.patch) {
|
||||
|
@ -323,8 +422,9 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.checkVersionNewer = function (runningVersion, newVersion) {
|
||||
};
|
||||
|
||||
this.checkVersionNewer = function(runningVersion, newVersion) {
|
||||
if (runningVersion.major < newVersion.major) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -338,14 +438,14 @@ JamStash.service('utils', function ($cookieStore, globals, model) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.parseDate = function (date) {
|
||||
};
|
||||
|
||||
this.parseDate = function(date) {
|
||||
// input: "2012-09-23 20:00:00.0"
|
||||
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
var parts = date.split(" ");
|
||||
var dateParts = parts[0].split("-");
|
||||
var month = parseInt(dateParts[1], 10) - 1;
|
||||
var date = months[month] + " " + dateParts[2] + ", " + dateParts[0];
|
||||
return date;
|
||||
}
|
||||
});
|
||||
return months[month] + " " + dateParts[2] + ", " + dateParts[0];
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue