Last active
December 21, 2015 03:48
-
-
Save gustavo-rodrigues-dev/6244753 to your computer and use it in GitHub Desktop.
Função que converte os dados passados via GET para um objeto
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
/** | |
* @return object getUrlData | |
*/ | |
function getUrlData(callback){ | |
var _default = { | |
typeData : {}, | |
basePath : window.location.pathname | |
}, | |
base = window.location, | |
local = base.href.replace(base.origin+_default.basePath, '').split(/[?,&,#]/), | |
dados = _default.typeData; | |
for(var x in local){ | |
if(local != undefined){ | |
var bit = local[x].split('='); | |
if(bit[0] != ''){ | |
dados[bit[0]] = bit[1]; | |
} | |
} | |
} | |
if (typeof callback == 'function') { | |
return callback(dados); | |
} | |
return dados; | |
} |
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
function getUrlData(e){var t={typeData:{},basePath:window.location.pathname},n=window.location,r=n.href.replace(n.origin+t.basePath,"").split(/[?,&,#]/),i=t.typeData;for(var s in r){if(r!=undefined){var o=r[s].split("=");if(o[0]!=""){i[o[0]]=o[1]}}}if(typeof e=="function"){return e(i)}return i} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment