User:Huawei251/common.js: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
// <pre> |
// <pre> |
||
console.log('test'); |
|||
// https://zh.wikipedia.org/wiki/Topic:Vjutwz17iablx6jw |
|||
// 可以做两件事情: |
|||
// # 在没有js脚本的前提下调整模板,让它至少不会严重影响阅读。 |
|||
// # 加入到小工具中,默认开启,像“可折叠表格”那样。IP用户提供的代码有点小bug,已经修改。 |
|||
// TODO |
|||
// 2. 允许循环往复 |
|||
// 3. 检查无脚本模式和移动端效果 |
|||
/** |
|||
* Skrypt dla Szablon:Galeria |
|||
*/ |
|||
mw.loader.using(['oojs-ui-core', 'ext.gadget.site-lib']).then(function () { |
|||
$(function () { |
|||
var toggleImage = function (group, remindex, shwindex) { |
|||
$("#ImageGroupsGr" + group + "Im" + remindex).hide(); |
|||
$("#ImageGroupsGr" + group + "Im" + shwindex).show(); |
|||
}; |
|||
$('div.ImageGroup').each(function(i, group) { |
|||
console.log('group ' + i); |
|||
var unitnode = $('div.ImageGroupUnits', group).get(0); |
|||
if (unitnode === undefined) { |
|||
console.log('A'); |
|||
return 1; |
|||
} |
|||
var units = $(unitnode).children().children('.center'); |
|||
var count = units.get().length; |
|||
if (count <= 1) { |
|||
console.log('B'); |
|||
return 1; |
|||
} |
|||
var cycle = group.getAttribute('data-cycle') || true; |
|||
units.each(function(j, currentimage) { |
|||
console.log('unit ' + j); |
|||
$(currentimage).attr('id', "ImageGroupsGr" + i + "Im" + j); |
|||
var leftlink = new OO.ui.ButtonWidget({ |
|||
framed: false, |
|||
icon: 'previous', |
|||
label: wgULS('上一个', '上一個'), |
|||
invisibleLabel: true, |
|||
title: wgULS('上一个', '上一個') |
|||
}); |
|||
var rightlink = new OO.ui.ButtonWidget({ |
|||
framed: false, |
|||
icon: 'next', |
|||
label: wgULS('下一个', '下一個'), |
|||
invisibleLabel: true, |
|||
title: wgULS('下一个', '下一個') |
|||
}); |
|||
var label = new OO.ui.ButtonWidget( { |
|||
framed: false, |
|||
disabled: true, |
|||
label: (j + 1) + '/' + count |
|||
}); |
|||
leftlink.on('click', function() { |
|||
var prev = (j-1)>=0 ? (j-1) : (count-1); |
|||
toggleImage(i, j, prev); |
|||
}); |
|||
rightlink.on('click', function() { |
|||
var next = (j+1)<count ? (j+1) : 0; |
|||
toggleImage(i, j, next); |
|||
}); |
|||
if (j === 0 && !cycle) { |
|||
leftlink.setDisabled(true); |
|||
} else if (j === count - 1 && !cycle) { |
|||
rightlink.setDisabled(true); |
|||
} |
|||
$('<div/>') |
|||
.addClass('selection-box') |
|||
.append(leftlink.$element) |
|||
.append(label.$element) |
|||
.append(rightlink.$element) |
|||
.prependTo($(currentimage)); |
|||
if (j !== 0) { |
|||
$(currentimage).hide().addClass('noprint'); |
|||
} |
|||
}); |
|||
}); |
|||
}); |
|||
}); |
|||
// Wikiplus blocked by this site |
|||
//mw.loader.load('https://wikiplus-app.com/Main.js'); |
|||
//mw.loader.using(['mediawiki.util', 'ext.gadget.site-lib'], function () { |
|||
/* 當需要時載入對應的 scripts */ |
|||
/* |
|||
var importScriptRL=function(page){ |
|||
mw.loader.load(mw.config.get('wgScript')+'?title='+mw.util.wikiUrlencode(page)+'&action=raw&ctype=text/javascript&_='+Math.floor((new Date())/1000/60/60/24/7)); |
|||
}; |
|||
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // scripts specific to editing pages |
|||
console.log('A'); |
|||
importScriptRL('User:Huawei251/edit.js'); |
|||
} else { |
|||
mw.loader.using('ext.visualEditor.desktopArticleTarget.init', function () { |
|||
console.log('ext.visualEditor.desktopArticleTarget.init'); |
|||
mw.libs.ve.addPlugin(function () { |
|||
importScriptRL('User:Huawei251/edit.js'); |
|||
}); |
|||
}); |
|||
} |
|||
*/ |
|||
//}); |
|||
// </pre> |
// </pre> |