added options: animationSpeed, animationOut, animationOutSpeed
This commit is contained in:
parent
4cddd808fc
commit
5ed5153015
33
pagify.js
33
pagify.js
|
@ -12,32 +12,38 @@
|
|||
var self = this;
|
||||
|
||||
this.defaults = {
|
||||
pages: [],
|
||||
'pages': [],
|
||||
'default': null,
|
||||
animation: 'show',
|
||||
onChange: function (page) {},
|
||||
cache: false
|
||||
'animation': 'show',
|
||||
'animationSpeed': 'normal',
|
||||
'animationOut': 'hide',
|
||||
'animationOutSpeed': 0,
|
||||
'onChange': function (page) {},
|
||||
'cache': false
|
||||
};
|
||||
this.settings = $.extend({}, this.defaults, options);
|
||||
|
||||
// Run after loading if caching, otherwise run immediately
|
||||
var runAfterLoading = function() {
|
||||
self.switchPage = function(page) {
|
||||
|
||||
// Page is selected from: passed in value, window.location, default
|
||||
if(!page) {
|
||||
page = window.location.hash.replace('#','') || self.settings['default'];
|
||||
}
|
||||
|
||||
// Load page content from cache
|
||||
if(self.settings.cache) {
|
||||
$(self).hide().html(self.pages[page])[self.settings.animation]();
|
||||
// Load page content from cache
|
||||
$(self)[self.settings.animationOut](self.settings.animationOutSpeed, function() {
|
||||
$(self).html(self.pages[page])[self.settings.animation](self.settings.animationSpeed);
|
||||
})
|
||||
self.settings.onChange(page);
|
||||
|
||||
}
|
||||
else {
|
||||
// Fetch page content
|
||||
} else {
|
||||
$.get(page+'.html', function(content) {
|
||||
$(self).hide().html(content)[self.settings.animation]();
|
||||
$(self)[self.settings.animationOut](self.settings.animationOutSpeed, function() {
|
||||
$(self).html(content)[self.settings.animation](self.settings.animationSpeed);
|
||||
})
|
||||
self.settings.onChange(page);
|
||||
}, 'text');
|
||||
}
|
||||
|
@ -51,7 +57,6 @@
|
|||
// Load initial page - current hash or default page
|
||||
if(window.location.hash) self.switchPage();
|
||||
else if(self.settings['default']) self.switchPage(self.settings['default']);
|
||||
|
||||
};
|
||||
|
||||
// Cache pages
|
||||
|
@ -62,12 +67,12 @@
|
|||
$.get(page+'.html', function(content) {
|
||||
self.pages[page] = content;
|
||||
pageLoads--;
|
||||
//alert(pageLoads);
|
||||
if(!pageLoads) runAfterLoading();
|
||||
}, 'text');
|
||||
});
|
||||
} else runAfterLoading();
|
||||
}
|
||||
else runAfterLoading();
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue