Skip to content

Instantly share code, notes, and snippets.

@wp-lab
Last active May 23, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-lab/58ef11c28a0187db7104 to your computer and use it in GitHub Desktop.
Save wp-lab/58ef11c28a0187db7104 to your computer and use it in GitHub Desktop.
<script async type="text/javascript">
function loadDynamicCategories() {
$.getJSON('http://www.example.com/wp-admin/admin-ajax.php?action=wpl_ebay_store_categories&callback=?', function(data) {
$('#categories_wrapper').append('<ul></ul>');
$.each(data, function(index) {
$('#categories_wrapper ul').append('<li id="'+data[index].cat_id+'"><a href="'+data[index].url+'">'+data[index].cat_name+'</a></li>');
});
});
// add optional link to store home page at the top
$('#categories_wrapper ul').prepend('<li><a href="'+'[[ebay_store_url]]'+'">Store Home</a></li>');
}
function loadjQuery() {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js";
head.appendChild(script);
waitUntiljQueryIsLoaded();
}
function waitUntiljQueryIsLoaded() {
if ( typeof window.jQuery !== 'undefined' && window.jQuery ) {
if (typeof jQueryLoaded == 'function') {
jQueryLoaded();
}
} else {
window.setTimeout( waitUntiljQueryIsLoaded, 100 );
}
}
// payload - executed when jQuery has been loaded
function jQueryLoaded() {
jQuery(document).ready(function(){
// load categories
loadDynamicCategories();
});
}
// init
loadjQuery();
</script>
@wp-lab
Copy link
Author

wp-lab commented Aug 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment