Single Page App implementation for jQuery
Simple implementation of Single Page App for jQuery.
Define a collection of elements that represent pages, and the appropriate one
will be shown when the location hash changes. Includes support for loading
content from remote URLs.
Note: This plugin does not provide routing nor view controller functionality.
This plugin requires jQuery Core and
jQuery UI.
<ul>
<li><a href="#static">Static content</a></li>
<li><a href="#remote">Remotely-loaded content</a></li>
</ul>
<div id="content-area">
<section id="static">
<p>Hello, world!</p>
</section>
<section id="remote" data-url="https://www.example.com/"></section>
</div>
<script>
(function($) {
$(function() {
$('#content-area').spa();
});
})(jQuery);
</script>
See demo/index.html
for a working example.
contentLoader
(Function(url:String), optional) - Function that will bedata-url
attribute.pageSelector
(String, optional) - Selector used to identify pages. Defaults'>section'
.defaultFilter
(String, optional) - Filter applied to pageSelector
, used to':first'
. If null
, no page will be loaded by default.init
(Boolean, optional) - Whether to init the SPA right away. Defaults totrue
.$('...').spa('init')
- Inits the SPA. Only needed if the init
option wasfalse
.$('...').spa('reload')
- Reloads the SPA, simulating a browser refresh.$('...').spa('loadPage', selector)
- Loads the page matching the specifiedselector
can be any valid jQuery selector.pageSelector
option will be applied first, then selector
.$('...').spa('loadDefaultPage')
- Loads the default page, depending on thedefaultFilter
option.todofixthis.spa.pageNotFound: function(event:Event, selector:String)
-todofixthis.spa.pageContentStart: function(event:Event, page:DOMElement, url:String)
-todofixthis.spa.pageContentSuccess: function(event:Event, html:String)
-todofixthis.spa.pageContentFail: function(event:Event, xhr:jqXHR)
-todofixthis.spa.pageContentFinish: function(event:Event, page:DOMElement, xhr:jqXHR)
-pageContentFail
/pageContentSuccess
.todofixthis.spa.pageHideStart: function(event:Event, page:DOMElement)
-todofixthis.spa.pageHideFinish: function(event:Event, page:DOMElement)
-todofixthis.spa.pageShowStart: function(event:Event, page:DOMElement)
-todofixthis.spa.pageShowFinish: function(event:Event, page:DOMElement)
-