Minor fixes and polyfills

This commit is contained in:
Mark McDowall 2013-09-11 14:38:35 -07:00
parent 89a72a50cf
commit feda4a9b67
7 changed files with 44 additions and 43 deletions

View File

@ -60,17 +60,18 @@ namespace NzbDrone.Host.Owin
{
if (ex.InnerException == null)
{
throw ex;
throw;
}
if (ex.InnerException as HttpListenerException == null)
if (ex.InnerException is HttpListenerException)
{
throw ex;
throw new PortInUseException("Port {0} is already in use, please ensure NzbDrone is not already running.",
ex,
_configFileProvider.Port);
}
throw new PortInUseException("Port {0} is already in use, please ensure NzbDrone is not already running.",
ex,
_configFileProvider.Port);
throw ex.InnerException;
}
}

View File

@ -64,7 +64,7 @@ define(
});
Handlebars.registerHelper('titleWithYear', function () {
if (this.title.match(/\s\(\d{4}\)$/)) {
if (this.title.endsWith(' ({0})'.format(this.year))) {
return this.title;
}

View File

@ -11,7 +11,7 @@ define(function () {
//check if ajax call was made with data option
if (xhr && xhr.data && xhr.type === 'DELETE') {
if (xhr.url.indexOf('?') === -1) {
if (!xhr.url.contains('?')) {
xhr.url = xhr.url + '?' + $.param(xhr.data);
}
else {

View File

@ -1,33 +0,0 @@
'use strict';
define(
[
], function () {
return {
startsWith: function (str, starts) {
if (starts === '') {
return true;
}
if (str == null || starts == null) {
return false;
}
str = String(str);
starts = String(starts);
return str.length >= starts.length && str.slice(0, starts.length) === starts;
},
endsWith: function (str, ends) {
if (ends === '') {
return true;
}
if (str == null || ends == null) {
return false;
}
str = String(str);
ends = String(ends);
return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
}
}
});

View File

@ -60,6 +60,7 @@
</div>
</footer>
</body>
<script src="/polyfills.js"></script>
<script src="/JsLibraries/jquery.js"></script>
<script src="/JsLibraries/messenger.js"></script>
<script src="/ServerStatus.js"></script>

View File

@ -1,5 +1,5 @@
'use strict';
define(['Shared/StringHelpers'],function (StringHelpers) {
define(function () {
//This module will automatically route all relative links through backbone router rather than
//causing links to reload pages.
@ -40,7 +40,7 @@ define(['Shared/StringHelpers'],function (StringHelpers) {
}
if (!StringHelpers.startsWith(href, 'http')) {
if (!href.startsWith('http')) {
router.navigate(href, { trigger: true });
}

32
UI/polyfills.js Normal file
View File

@ -0,0 +1,32 @@
if (!String.prototype.startsWith) {
Object.defineProperty(String.prototype, 'startsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function (searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
}
});
}
if (!String.prototype.endsWith) {
Object.defineProperty(String.prototype, 'endsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function (searchString, position) {
position = position || this.length;
position = position - searchString.length;
var lastIndex = this.lastIndexOf(searchString);
return lastIndex !== -1 && lastIndex === position;
}
});
}
if(!('contains' in String.prototype))
{
String.prototype.contains = function(str, startIndex) {
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
};
}