我已经多次重写我的脚本文件只是为了缩短它,除了两个功能之外,我已经用它很长时间了,
我希望将这些合并为一个
首先使用页面加载功能,这会在文档准备就绪时进行初始化
function pageload(elements, settings) {
elements = $.extend({}, defaultelements, elements || {});
settings = $.extend({}, defaultsettings, settings || {});
if( settings.url === '' ) {
console.log('No soup for you!');
movePage.prototype.pagein();
} else {
$.ajax({
url: location,
data: {
json: 'get_page',
slug: settings.url
},
success: function(data) {
var html = '<article id="' + data.page.slug + '" data-info="' + data.page.slug + '" class="subpage"></article>';
if(settings.motion) return false;
else settings.motion = true;
elements.thumbs.before(html);
var container = $('.subpage');
elements.body.prepend('<div class="spinner"></div>');
$('.spinner').hide();
container.load(data.page.url).hide();
elements.thumbs.stop().animate({
'top' : '100%'
}, settings.speed, settings.easing, function() {
$('.spinner').fadeIn(259);
setTimeout(function() {
$('.spinner').fadeOut(559);
setTimeout(function() {
container.fadeIn(659);
}, 450)
setTimeout(function() {
$('.spinner').remove();
}, 200)
}, 1250);
settings.motion = false;
movePage.prototype.pagein();
});
}
});
}
}
还有导航json加载脚本
function navigation(elements, settings) {
elements = $.extend({}, defaultelements, elements || {});
settings = $.extend({}, defaultsettings, settings || {});
elements.navitem.live('click', function(event) {
event.preventDefault();
$('.current-menu-item').removeClass('current-menu-item');
$(this).parent().addClass('current-menu-item');
settings.url = $(this).html();
$.ajax({
url: location,
data: {
json: 'get_page',
slug: settings.url
},
success: function(data) {
var current = $('.subpage');
if( settings.url == 'work' ) {
settings.motion = false;
} else if( current.attr('id') == settings.url ) {
settings.motion = false;
return;
} else {
var html = '<article id="' + data.page.slug + '" data-info="' + data.page.slug + '" class="subpage"></article>';
if(settings.motion) return false;
else settings.motion = true;
elements.thumbs.before(html);
var container = $('.subpage');
elements.body.prepend('<div class="spinner"></div>');
$('.spinner').hide();
container.load(data.page.url).hide();
elements.thumbs.stop().animate({
'top' : '100%'
}, settings.speed, settings.easing, function() {
$('.spinner').fadeIn(259);
setTimeout(function() {
$('.spinner').fadeOut(559);
setTimeout(function() {
container.fadeIn(659);
}, 450)
setTimeout(function() {
$('.spinner').remove();
}, 200)
}, 1250);
settings.motion = false;
movePage.prototype.pagein();
$('article:not(#' + data.page.slug + ')').remove();
});
}
}
});
});
}
这里有没有人有一个解决方案,可以将这些功能变成一个我可以在页面加载和导航点击时调用的功能。