Skip to content

Instantly share code, notes, and snippets.

@fenriz07
Created December 1, 2017 05:08
Show Gist options
  • Save fenriz07/8e399af8efd5080ead1085715215d488 to your computer and use it in GitHub Desktop.
Save fenriz07/8e399af8efd5080ead1085715215d488 to your computer and use it in GitHub Desktop.
Small object to manipulate ajax page for wordpress. Inherit to your liking!
jQuery(document).ready(function($) {
/*
Small object to manipulate ajax page for wordpress. Inherit to your liking!
For: CmantikWeb - Servio Zambrano
*/
var loadMore = {
paged : 2,
switchp : 1,
action : "get_daypackage",
buttom : $('#more-package'),
msg_not_result : function(){ return this.buttom.data('nmr');},
template : function(){ return this.buttom.data('template') || 'v1';},
packageforcol : function(){ return this.buttom.data('pfc') || 3;},
checkSwitch : function(){
if(!this.switchp){
return true;
}
},
obtainSlug : function(){
var url = window.location.pathname.substr(1);
var lvls = url.split('/');
lvls.pop();
return lvls[lvls.length-1];
},
renderPackages : function(html){
if($('.package-item-holder').length){
var rows = $('.package-item-holder > .row');
}else{
var rows = $('.twelve.columns > .row');
}
$(html).insertAfter(rows[rows.length-1]);
},
getPackage : function(event){
if(this.checkSwitch()){ return 0;}
var loadmore = this;
jQuery.getJSON("/wp-admin/admin-ajax.php", {
action: this.action,paged:this.paged,slug:this.obtainSlug(),template:this.template(),pfc:this.packageforcol()
}, function(response) {
if(response.html == "") {
loadmore.switchp = 0;
$(event.target).html(loadmore.msg_not_result());
}
else {
loadmore.renderPackages(response.html);
loadmore.paged += 1;
}
}
);
}
};
$('#more-package').click(function(event) {
loadMore.getPackage(event);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment