User:PhiLiP/main 2010.js
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
window.jQuery(function() { if (wgPageName=="User:PhiLiP/2010新首页之Upsuper+Littlebtc") return function($) {
var addVoidA = function(object) {
object.html("<a href=\"javascript:void(0)\">" + object.html() + "</a>");
};
var removeATag = function(object) {
object.html(object.html().replace(/<\/?a[^>]+>/gi, ""));
};
var mainPagePickSelect = function (index) {
var previousTag = $(".mainPageSliderTargetSelected").removeClass("mainPageSliderTargetSelected");
var currentTag = $("#mainPageSliderTarget" + index);
addVoidA(previousTag);
removeATag(currentTag);
currentTag.addClass("mainPageSliderTargetSelected");
$(".mainPageSliderItemSelected").removeClass("mainPageSliderItemSelected").fadeOut( function() {
$(".mainPageSliderItem").eq(index).addClass("mainPageSliderItemSelected").fadeIn();
});
};
var mainPagePickMove = function(offset) {
var mainPagePickNum = $(".mainPageSliderItem").length;
var currentIndex = $(".mainPageSliderItem").index($(".mainPageSliderItemSelected"));
var target = currentIndex + offset;
if (target >= mainPagePickNum) target = 0;
if (target < 0) target = mainPagePickNum - 1;
mainPagePickSelect(target);
};
var setFixedHeight = function() {
var maxHeight = 0;
for(i = 0; i < $(".mainPageSliderItem").length; i ++) {
currentHeight = $(".mainPageSliderItem").eq(i).height();
maxHeight = maxHeight > currentHeight ? maxHeight : currentHeight;
}
$(".mainPageSliderItem").height(maxHeight + 10);
};
var initSliderTarget = function() {
for(i = 0; i < $(".mainPageSliderItem").length; i ++) {
var currentTag = $("#mainPageSliderTarget" + i);
removeATag(currentTag);
if(i == 0) {
currentTag.addClass("mainPageSliderTargetSelected");
}
else {
addVoidA(currentTag);
}
}
addVoidA($("#mainPageSliderLeft"));
addVoidA($("#mainPageSliderRight"));
$("#mainPageSliderLeft").click(function() { mainPagePickMove(-1); });
$("#mainPageSliderRight").click(function() { mainPagePickMove(1); });
$("#mainPageSliderTarget0").click(function() { mainPagePickSelect(0); });
$("#mainPageSliderTarget1").click(function() { mainPagePickSelect(1); });
$("#mainPageSliderTarget2").click(function() { mainPagePickSelect(2); });
$("#mainPageSliderTarget3").click(function() { mainPagePickSelect(3); });
$("#mainPageSliderTarget4").click(function() { mainPagePickSelect(4); });
};
var initCreateArticle = function() {
buttonObj = $("#mainPageCreateArticle");
removeATag(buttonObj);
addVoidA(buttonObj);
buttonObj.click(function() {
$('#mainPageCreateArticleContent').clone().dialog({
'bgiframe':true, 'draggable':false, 'resizable':false, 'modal':true, 'width':600});
});
};
var mainPageFunc = function() {
setFixedHeight();
initSliderTarget();
initCreateArticle();
$("body").everyTime("30s", "interval", function() { mainPagePickMove(1); });
$("#mainPageTabList > li").click( function() {
var target = $("#mainPageTabList > li").index(this);
$(".mainPageTabItem").hide().eq(target).show();
$("#mainPageTabList > li").removeClass("selected").eq(target).addClass("selected");
});
mainPagePickSelect(0);
};
$.getScript("http://prototype.wikimedia.org/s-2/js/mwEmbed/jquery/plugins/jquery.timers.js", function() { mainPageFunc(); });
}(window.jQuery);});