Last active
December 28, 2015 07:38
-
-
Save jervert/7465495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SyncUrlProtocol - Underscore/Lodash mixin for sync url protocol with window url protocol | |
* | |
* Copyright (c) 2013 Antonio Rodríguez Ruiz | |
* | |
* Licensed under the MIT license: | |
* http://www.opensource.org/licenses/mit-license.php | |
* | |
* Project home: | |
* http://outbook.es | |
* | |
* Version: 1.0.0 | |
* | |
* | |
* initialize: | |
* _.syncUrlProtocol('http://exampleurl.net/route/in/server') | |
* | |
*/ | |
_.mixin({ | |
syncUrlProtocol: function (url) { | |
var protocol = window.location.protocol, | |
httpString = 'http:', | |
httpsString = 'https:', | |
regexHttp = /^http:/g, | |
regexHttps = /^https:/g, | |
newUrl = url; | |
if (!_.isNull(url.match(regexHttps)) && protocol === httpString) { | |
newUrl = url.replace(regexHttps, httpString); | |
} else if (!_.isNull(url.match(regexHttp)) && protocol === httpsString) { | |
newUrl = url.replace(regexHttp, httpsString); | |
} | |
return newUrl; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment