14.602
redaktə
Redaktənin izahı yoxdur |
k (WikiSysop (Müzakirə) tərəfindən edilmiş dəyişikliklər Tofiq Kərimli tərəfindən edilmiş dəyişikliklərə qaytarıldı.) Teq: Geri qaytarma |
||
Sətir 1: | Sətir 1: | ||
/* Burada redaktorların hamısı üçün bütün səhifələrdə istənilən JavaScript yüklənəcək */ | |||
// Switch language variants of messages (from zh) | // Switch language variants of messages (from zh) | ||
function wgULS(latn,arab){ | function wgULS(latn,arab){ | ||
Sətir 96: | Sətir 97: | ||
} | } | ||
}); | }); | ||
/* Test if an element has a certain class ************************************** | |||
* | |||
* Description: Uses regular expressions and caching for better performance. | |||
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]] | |||
*/ | |||
var hasClass = (function () { | |||
var reCache = {}; | |||
return function (element, className) { | |||
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | |||
}; | |||
})(); | |||
/** Interwiki links to featured articles *************************************** | /** Interwiki links to featured articles *************************************** | ||
Sətir 104: | Sətir 119: | ||
* Maintainers: [[User:R. Koot]] | * Maintainers: [[User:R. Koot]] | ||
*/ | */ | ||
//Messages | //Messages | ||
Sətir 117: | Sətir 128: | ||
var zeroSectionTip = 'Girişi redaktə et'; | var zeroSectionTip = 'Girişi redaktə et'; | ||
var NavigationBarHide = '[ | var NavigationBarHide = '[bağla]'; | ||
var NavigationBarShow = '[ | var NavigationBarShow = '[bax]'; | ||
var NavigationBarShowDefault = 2; | var NavigationBarShowDefault = 2; | ||
Sətir 152: | Sətir 163: | ||
var | /** Collapsible tables ********************************************************* | ||
if ( | * | ||
* Description: Allows tables to be collapsed, showing only the header. See | |||
} | * [[Wikipedia:NavFrame]]. | ||
* Maintainers: [[User:R. Koot]] | |||
*/ | |||
var autoCollapse = 2; | |||
var collapseCaption = "bağla"; | |||
var expandCaption = "bax"; | |||
function collapseTable( tableIndex ) | |||
{ | |||
var Button = document.getElementById( "collapseButton" + tableIndex ); | |||
var Table = document.getElementById( "collapsibleTable" + tableIndex ); | |||
var i; | |||
if ( !Table || !Button ) { | |||
return false; | |||
} | |||
var Rows = Table.getElementsByTagName( "tr" ); | |||
if ( Button.firstChild.data == collapseCaption ) { | |||
for ( i = 1; i < Rows.length; i++ ) { | |||
Rows[i].style.display = "none"; | |||
} | |||
Button.firstChild.data = expandCaption; | |||
} else { | |||
for ( i = 1; i < Rows.length; i++ ) { | |||
Rows[i].style.display = Rows[0].style.display; | |||
} | |||
Button.firstChild.data = collapseCaption; | |||
} | |||
} | |||
function createCollapseButtons() | |||
{ | |||
var tableIndex = 0; | |||
var NavigationBoxes = {}; | |||
var Tables = document.getElementsByTagName( "table" ); | |||
var i; | |||
for ( i = 0; i < Tables.length; i++ ) { | |||
if ( hasClass( Tables[i], "collapsible" ) ) { | |||
NavigationBoxes[ tableIndex ] = Tables[i]; | |||
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); | |||
var Button = document.createElement( "span" ); | |||
var ButtonLink = document.createElement( "a" ); | |||
var ButtonText = document.createTextNode( collapseCaption ); | |||
Button.style.styleFloat = "right"; | |||
Button.style.cssFloat = "right"; | |||
Button.style.fontWeight = "normal"; | |||
Button.style.textAlign = "right"; | |||
Button.style.width = "6em"; | |||
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); | |||
ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" ); | |||
ButtonLink.appendChild( ButtonText ); | |||
Button.appendChild( document.createTextNode( "[" ) ); | |||
Button.appendChild( ButtonLink ); | |||
Button.appendChild( document.createTextNode( "]" ) ); | |||
var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0]; | |||
/* only add button and increment count if there is a header row to work with */ | |||
if (Header) { | |||
Header.insertBefore( Button, Header.childNodes[0] ); | |||
tableIndex++; | |||
} | |||
} | |||
} | |||
for ( i = 0; i < tableIndex; i++ ) { | |||
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { | |||
collapseTable( i ); | |||
} | |||
} | |||
} | |||
$( createCollapseButtons ); | |||
/ | /** Dynamic Navigation Bars (experimental) ************************************* | ||
* | |||
* Description: See [[Wikipedia:NavFrame]]. | |||
* Maintainers: UNMAINTAINED | |||
*/ | |||
// set up the words in your language | |||
var NavigationBarHide = '[' + collapseCaption + ']'; | |||
var NavigationBarShow = '[' + expandCaption + ']'; | |||
// | |||
var | // set up max count of Navigation Bars on page, | ||
var | // if there are more, all will be hidden | ||
// NavigationBarShowDefault = 0; // all bars will be hidden | |||
/ | // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden | ||
var NavigationBarShowDefault = autoCollapse; | |||
// shows and hides content and picture (if available) of navigation bars | |||
// Parameters: | |||
function toggleNavigationBar( indexNavigationBar | // indexNavigationBar: the index of navigation bar to be toggled | ||
function toggleNavigationBar(indexNavigationBar) | |||
{ | |||
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); | |||
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); | |||
if (!NavFrame || !NavToggle) { | |||
return false; | |||
} | |||
// if shown now | |||
if (NavToggle.firstChild.data == NavigationBarHide) { | |||
for ( | |||
var NavChild = NavFrame.firstChild; | |||
NavChild != null; | |||
NavChild = NavChild.nextSibling | |||
) { | |||
if ( hasClass( NavChild, 'NavPic' ) ) { | |||
NavChild.style.display = 'none'; | |||
} | |||
if ( hasClass( NavChild, 'NavContent') ) { | |||
NavChild.style.display = 'none'; | |||
} | |||
} | |||
NavToggle.firstChild.data = NavigationBarShow; | |||
// if hidden now | |||
} else if (NavToggle.firstChild.data == NavigationBarShow) { | |||
for ( | |||
} | var NavChild = NavFrame.firstChild; | ||
NavChild != null; | |||
/ | NavChild = NavChild.nextSibling | ||
) { | |||
if (hasClass(NavChild, 'NavPic')) { | |||
NavChild.style.display = 'block'; | |||
} | |||
function createNavigationBarToggleButton( | if (hasClass(NavChild, 'NavContent')) { | ||
NavChild.style.display = 'block'; | |||
} | |||
} | |||
NavToggle.firstChild.data = NavigationBarHide; | |||
} | |||
} | |||
// adds show/hide-button to navigation bars | |||
function createNavigationBarToggleButton() | |||
{ | |||
var indexNavigationBar = 0; | |||
// iterate over all < div >-elements | |||
var divs = document.getElementsByTagName("div"); | |||
for( | |||
var i=0; | |||
NavFrame = divs[i]; | |||
i++ | |||
) { | |||
// if found a navigation bar | |||
if (hasClass(NavFrame, "NavFrame")) { | |||
indexNavigationBar++; | |||
var NavToggle = document.createElement("a"); | |||
NavToggle.className = 'NavToggle'; | |||
NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); | |||
NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); | |||
var NavToggleText = document.createTextNode(NavigationBarHide); | |||
NavToggle.appendChild(NavToggleText); | |||
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) | |||
for( | |||
var j=0; | |||
j < NavFrame.childNodes.length; | |||
j++ | |||
) { | |||
if (hasClass(NavFrame.childNodes[j], "NavHead")) { | |||
NavFrame.childNodes[j].appendChild(NavToggle); | |||
} | |||
} | |||
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); | |||
} | |||
} | |||
// if more Navigation Bars found than Default: hide all | |||
if (NavigationBarShowDefault < indexNavigationBar) { | |||
for( | |||
var i=1; | |||
i<=indexNavigationBar; | |||
i++ | |||
) { | |||
toggleNavigationBar(i); | |||
} | |||
} | |||
} | |||
$( createNavigationBarToggleButton ); | |||
/** "Technical restrictions" title fix ***************************************** | /** "Technical restrictions" title fix ***************************************** | ||
Sətir 533: | Sətir 571: | ||
var searchEngines = { | var searchEngines = { | ||
mediawiki: { | mediawiki: { | ||
ShortName: " | ShortName: "Şəki Ensiklopediyasında axtarış", | ||
Template: "/ | Template: "/encyclopedia/index.php?search={searchTerms}" | ||
}, | }, | ||
globalwpsearch: { | globalwpsearch: { | ||
Sətir 542: | Sətir 580: | ||
google: { | google: { | ||
ShortName: "Google", | ShortName: "Google", | ||
Template: "http://www.google.cat/search?as_sitesearch= | Template: "http://www.google.cat/search?as_sitesearch=sheki.wiki&hl={language}&q={searchTerms}" | ||
}, | }, | ||
wikiwix: { | wikiwix: { | ||
Sətir 550: | Sətir 588: | ||
yahoo: { | yahoo: { | ||
ShortName: "Yahoo!", | ShortName: "Yahoo!", | ||
Template: "http://search.yahoo.com/search?p={searchTerms}&vs= | Template: "http://search.yahoo.com/search?p={searchTerms}&vs=sheki.wiki" | ||
}, | }, | ||
wlive: { | wlive: { | ||
ShortName: "Windows Live", | ShortName: "Windows Live", | ||
Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http:// | Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://sheki.wiki" | ||
} | } | ||
}; | }; | ||
Sətir 738: | Sətir 776: | ||
} | } | ||
/** | /** | ||
* imgToggle | * imgToggle | ||
Sətir 782: | Sətir 812: | ||
} ); | } ); | ||
} | } | ||
$(function() { | |||
var | |||
//add this class to all elements created by the script. the reason is that we call the script again on | |||
//window resize, and use the class to remove all the "artefacts" we created in the previous run. | |||
myClassName = 'imageMapHighlighterArtefacts', | |||
liHighlightClass = 'liHighlighting', | |||
specialAreaMark = 'area_mark', | |||
specialLiClassesMark = 'list_classes', | |||
specialAreaMarkFile = 'area_mark_file', | |||
// "2d context" attributes used for highlighting. | |||
areaHighLighting = { | |||
fillStyle: 'rgba(0,0,0,0.35)', | |||
strokeStyle: 'yellow', | |||
lineJoin: 'round', | |||
lineWidth: 2 | |||
}, | |||
//every imagemap that wants highlighting, should reside in a div of this 'class': | |||
hilightDivMarker = '.imageMapHighlighter', | |||
// specifically for wikis - redlinks tooltip adds this message | |||
ru = mw && mw.config && mw.config.get('wgUserLanguage') == 'ru', | |||
expandLegend = ru ? 'показать ссылки текстом' : 'sıyahını aç', | |||
collapseLegend = ru ? 'скрыть ссылки текстом' : 'siyahını bağla', | |||
files = []; | |||
function drawMarker(context, areas) { // this is where the magic is done. | |||
function drawPoly(coords) { | |||
context.moveTo(coords.shift(), coords.shift()); | |||
while (coords.length) | |||
context.lineTo(coords.shift(), coords.shift()); | |||
} | |||
for (var i in areas) { | |||
var coords = areas[i].coords.split(','); | |||
context.beginPath(); | |||
switch (areas[i].shape) { | |||
case 'rect': | |||
drawPoly([coords[0], coords[1], coords[0], coords[3], coords[2], coords[ | |||
3], coords[2], coords[1]]); | |||
break; | |||
case 'circle': | |||
context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2); | |||
break; //x,y,r,startAngle,endAngle | |||
case 'poly': | |||
drawPoly(coords); | |||
break; | |||
} | |||
context.closePath(); | |||
context.stroke(); | |||
context.fill(); | |||
} | |||
} | |||
function mouseAction(e) { | |||
var $this = $(this), | |||
activate = e.type == 'mouseover', | |||
caption = $this.text(), | |||
ol = $this.parent(), | |||
context = ol.data('context'), | |||
special = ol.data(specialAreaMark), | |||
specialFile = ol.data(specialAreaMarkFile); //read JSON file addition | |||
if (specialFile) { | |||
if (files[specialFile]) { | |||
$.extend(special, files[specialFile]); | |||
always(activate, caption, context, ol, special, $this); | |||
} else { | |||
$.get(mw.util.wikiScript(), { | |||
title: specialFile, | |||
action: 'raw' | |||
}) | |||
.done(function(data) { | |||
files[specialFile] = JSON.parse(data); | |||
$.extend(special, files[specialFile]); | |||
}) | |||
.always(function() { | |||
always(activate, caption, context, ol, special, $this); | |||
}); | |||
} | |||
} else | |||
always(activate, caption, context, ol, special, $this); | |||
} | |||
function always(activate, caption, context, ol, special, $this) { | |||
$this.toggleClass(liHighlightClass, activate); // mark/unmark the list item. | |||
context.clearRect(0, 0, context.canvas.width, context.canvas.height); // prepare for a new day. | |||
ol.find('li') | |||
.each(function() { | |||
var $li = $(this); | |||
var licap = $li.text(); | |||
var param; | |||
if (activate && licap === caption) { // highlight!!! | |||
param = special && (special.hover && special.hover[licap] | |||
|| getblocks(special, licap)) || areaHighLighting; | |||
} else { | |||
param = special && special.nover && (special.nover[licap] || special.nover | |||
.default); | |||
} | |||
if (param) { | |||
$.extend(context, param); | |||
drawMarker(context, $li.data('areas')); | |||
} | |||
}); | |||
} | |||
function getblocks(special, licap) { | |||
if (special.hoverblocks) { | |||
if (special.hoverblocks[licap]) | |||
return special.hoverblocks[licap].value; | |||
for (var key in special.hoverblocks) | |||
if (special.hoverblocks[key] && special.hoverblocks[key].list.indexOf(licap) >=0 ) | |||
return special.hoverblocks[key].value; | |||
} | |||
if (special.hover) | |||
return special.hover.default; | |||
} | |||
function handleOneMap() { | |||
var img = $(this), | |||
w = img.width(), | |||
h = img.height(), | |||
infoIcon = img.next(), | |||
parent = img.parent(), | |||
map = img.siblings('map:first'), | |||
dims = { | |||
position: 'absolute', | |||
width: w + 'px', | |||
height: h + 'px', | |||
border: 0, | |||
top: 0, | |||
left: 0 | |||
}, | |||
specialHighlight = img.closest(hilightDivMarker) | |||
.data(specialAreaMark), | |||
specialLiClasses = img.closest(hilightDivMarker) | |||
.data(specialLiClassesMark), | |||
specialHover = img.closest(hilightDivMarker) | |||
.data(specialAreaMarkFile); | |||
if (!('area', map) | |||
.length) | |||
return; //not an imagemap. inside "each" anonymous function, 'return' means "continue". | |||
var jcanvas = $('<canvas>', { | |||
'class': myClassName | |||
}) | |||
.css(dims) | |||
.attr({ | |||
width: w, | |||
height: h | |||
}); | |||
var bgimg = $('<img>', { | |||
'class': myClassName, | |||
src: img.attr('src') | |||
}) | |||
.css(dims); //completely inert image. this is what we see. | |||
var context = $.extend(jcanvas[0].getContext("2d"), areaHighLighting); | |||
// this is where the magic is done: prepare a sandwich of the inert bgimg at the bottom, | |||
// the canvas above it, and the original image on top, | |||
// so canvas won't steal the mouse events. | |||
// pack them all TIGHTLY in a newly minted "relative" div, so when page chnage | |||
// (other scripts adding elements, window resize etc.), canvas and imagese remain aligned. | |||
var div = $('<div>') | |||
.css({ | |||
position: 'relative', | |||
width: w + 'px', | |||
height: h + 'px' | |||
}); | |||
img.before(div); // put the div just above the image, and ... | |||
div.append(bgimg) // place the background image in the div | |||
.append(jcanvas) // and the canvas. both are "absolute", so they don't occupy space in the div | |||
.append(img); // now yank the original image from the window and place it on the div. | |||
img.fadeTo(1, 0); // make the image transparent - we see canvas and bgimg through it. | |||
// the original, now transparent image is creating our mouse events | |||
infoIcon.css({ | |||
position: 'relative' | |||
}); // set position to info icon | |||
var ol = $('<ol>', { | |||
'class': myClassName | |||
}) | |||
.css({ | |||
clear: 'both', | |||
margin: 0, | |||
listStyle: 'none', | |||
maxWidth: w + 'px', | |||
position: 'relative' | |||
}) | |||
.data(specialAreaMark, specialHighlight) | |||
.data(specialAreaMarkFile, specialHover) | |||
.data('context', context); | |||
var oldiv = $('<div>') | |||
.html(ol) | |||
.css({ | |||
clear: 'both', | |||
margin: 0, | |||
listStyle: 'none', | |||
maxWidth: w + 'px', | |||
position: 'relative' | |||
}) | |||
.attr({ | |||
'data-expandtext': expandLegend, | |||
'data-collapsetext': collapseLegend | |||
}); | |||
// ol below image parent, hr below ol. original caption pushed below hr. | |||
parent.after($('<hr>', { | |||
'class': myClassName | |||
}) | |||
.css('clear', 'both')) | |||
.after(oldiv); | |||
$('<hr>', { | |||
'class': myClassName | |||
}) | |||
.css('clear', 'both') | |||
.insertBefore($(oldiv)); | |||
var lis = {}; //collapse areas with same caption to one list item | |||
var someli; // select arbitrary one | |||
$('area', map) | |||
.each(function() { | |||
var text = this.title; | |||
var li = lis[text]; // title already met? use the same li | |||
if (!li) { //no? create a new one. | |||
var href = this.href; | |||
lis[text] = li = $('<li>', { | |||
'class': myClassName | |||
}) | |||
.append($('<a>', { | |||
href: href, | |||
text: text | |||
})) | |||
.on('mouseover mouseout', mouseAction) | |||
.data('areas', []) | |||
.addClass(specialLiClasses && (specialLiClasses[text] || | |||
specialLiClasses['default'])) | |||
.appendTo(ol); | |||
if (specialLiClasses && specialLiClasses[text + ' super']) | |||
li.find('a') | |||
.addClass(specialLiClasses[text + ' super']); | |||
} | |||
li.data('areas') | |||
.push(this); //add the area to the li | |||
someli = li; // whichever - we just want one... | |||
$(this) | |||
.on('mouseover mouseout', function(e) { | |||
li.trigger(e); | |||
}); | |||
}); | |||
if (someli) someli.trigger('mouseout'); | |||
oldiv.addClass('mw-collapsed') | |||
.makeCollapsible(); | |||
ol.attr('style', ol.attr('style') | |||
.replace('none', 'disc')); | |||
} | |||
function init() { | |||
mw.util.addCSS('li.' + myClassName + | |||
'{white-space:nowrap; font-size:88.36%;}\n' + //css for li element | |||
'li.' + liHighlightClass + '{background-color:yellow;}\n' + //css for highlighted li element. | |||
'.rtl li.' + myClassName + '{float: right; margin-left: 1.5em;}\n' + | |||
'.ltr li.' + myClassName + '{float: left; margin-right: 1.5em;}\n' + | |||
hilightDivMarker + ' .mw-collapsible-toggle {float: none}'); | |||
$(hilightDivMarker + ' img') | |||
.each(handleOneMap); | |||
} | |||
//has at least one "imagehighlight" div, and canvas-capable browser: | |||
if ($(hilightDivMarker) | |||
.length && $('<canvas>')[0].getContext) | |||
mw.loader.using(['jquery.makeCollapsible', 'mediawiki.util']) | |||
.done(init); | |||
}); |