Skip to content

Instantly share code, notes, and snippets.

@jervert
Last active December 28, 2015 07:38
Show Gist options
  • Save jervert/7465495 to your computer and use it in GitHub Desktop.
Save jervert/7465495 to your computer and use it in GitHub Desktop.
/*
* 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