Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example layout for a WordPress REST API powered app script. Based on https://github.com/Shelob9/josie
/**globals jQuery Josie**/
jQuery( function () {
Josie.init();
} );
(function ( $, app ) {
app.init = function() {
app.menuItems( params.mainMenuName, params.mainMenuContainer );
$(document).on ("click", "[josie=internal]", function ( event ) {
app.events.clickHandler( event );
});
};
app.events = {
clickHandler : function( event ) {
},
mainRouter : function() {
var hash = window.location.hash.replace(/^.*?#/,'');
var url = document.URL;
var urlLast = app.lastSegment( url );
var protocolSplit = url.split( '//');
if (
'index.html' === app.stripTrailingSlash(urlLast )
|| app.stripTrailingSlash( urlLast ) === app.stripTrailingSlash( protocolSplit[1] )
) {
if ( '' == hash || hash == '#' || hash == 'page=1') {
app.getPosts( 0 );
app.pagination( 1 );
}
}
else {
if ( url.indexOf("taxonomy") > -1 ) {
//@TODO This
console.log( url.indexOf( 'taxonomy') );
}
else if( url.indexOf( 'page' ) > -1 ) {
app.getPosts( urlLast );
}
else {
app.getSinglePost( '', urlLast );
}
}
}
};
app.getPosts = function( offset ) {
};
app.getSinglePost = function( ID, slug ) {
};
app.listTerms = function( taxonomy ) {
};
app.term = function( taxonomy, slug, offset ) {
};
app.pagination = function( current ) {
};
app.menuItems = function( menuName, menuContainer ) {
i
};
app.urlParams = function( sParam ) {
};
app.emptyContainer = function() {
};
app.link = function( ID, url, titleText, linkClass, text ) {
};
app.lastSegment = function (url) {
};
app.stripTrailingSlash = function(str) {
};
})( jQuery, window.Josie || ( window.Josie = {} ) );
$( document ).ready(function() {
//run router on hash change (IE URL change)
$(window).on('hashchange', Josie.events.mainRouter );
//route on load
Josie.events.mainRouter();
//intitialize foundation
$(document).foundation();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.