Created
January 9, 2019 13:09
-
-
Save crowdfundhq/32976a3a2ed179d76c05e37fec761d0f 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
<script> | |
window.hq.postDialog = function(form){ | |
var params = hq.serialize(form); | |
var center = hq.initDialog(); | |
window.hq.post(form.action, center, params); | |
}; | |
// General post ajax method | |
window.hq.post = function(url, el, params){ | |
if(!el){ el = document.getElementById('content');} | |
hq.ajax(url, { | |
method:'post', | |
data: params, | |
success: function(data){ | |
if(data === ''){ | |
// Redirect based on the response and where you came from | |
var redirect = cookies.get('redirect'); | |
if(redirect){ | |
window.location.href = redirect; | |
} else { | |
window.location.reload(true); | |
} | |
} else if(data[0] === '/'){ | |
// Create parser | |
var parser = document.createElement('a'); | |
parser.href = url; | |
var path = parser.pathname; | |
// Redirect based on path | |
if(path === '/users') { | |
window.location.reload(true); | |
} else { | |
window.location.replace(data); | |
} | |
} else { | |
// No redirect, just update current page | |
el.innerHTML = data; | |
if(!dialogOpen()){ scrollTo(0, 0)}; | |
loadScripts(); | |
} | |
} | |
}); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment