Разлика между версии на „МедияУики:Common.js“
(call updateTextboxHeight() on start after a small timeout) |
|||
(Не са показани 15 междинни версии от същия потребител) | |||
Ред 1: | Ред 1: | ||
− | // Dynamic layouts | + | var wgAbsoluteScript = mw.config.get("wgServer")+mw.config.get("wgScript"); |
− | if ( !self.ws_layouts ) { | + | |
− | + | var enhancePageViewing = function() { | |
− | } | + | // Dynamic layouts |
− | self.ws_layouts['Layout 1'] = { | + | if ( !self.ws_layouts ) { |
− | + | self.ws_layouts = {}; | |
− | + | } | |
− | + | self.ws_layouts['Layout 1'] = { | |
− | + | '#text-wrap':"", | |
− | + | '#text-container':"", | |
− | + | '#text':"", | |
− | + | '.sidenote-right':"float:right; margin:0.5em; padding:3px; border:solid 1px gray; max-width:9em; text-indent:0em; text-align:left;", | |
+ | '.sidenote-left':"float:left; margin:0.5em; padding:3px; border:solid 1px gray; max-width:9em; text-indent:0em; text-align:left;", | ||
+ | '.mw-editsection':"display:none;", | ||
+ | '#headertemplate':"" | ||
+ | }; | ||
+ | self.ws_layouts['Layout 2'] = { | ||
+ | '#text-wrap':"position:relative; margin-left:3.0em; margin-right:3.0em;", | ||
+ | '#text-container':"width:40em; margin:0 auto;", | ||
+ | '#text':"text-align:justify;", | ||
+ | '.sidenote-right':"position:absolute; left:37em; width:16em; text-indent:0em; text-align:left;", | ||
+ | '.sidenote-left':"position:absolute; left:37em; width:16em; text-indent:0em; text-align:left;", | ||
+ | '.mw-editsection':"display:none;", | ||
+ | '#headertemplate':"" | ||
+ | }; | ||
+ | self.ws_layouts['Layout 3'] = { | ||
+ | '#text-wrap':"margin-left:3.0em;", | ||
+ | '#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;", | ||
+ | '#text':"position:relative; text-align:justify; margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px; width:auto;", | ||
+ | '.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee; text-indent:0em; text-align:left;", | ||
+ | '.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee; text-indent:0em; text-align:left;", | ||
+ | '.mw-editsection':"display:none;", | ||
+ | '#headertemplate':"position:absolute; top:0em; right:-23em; width:21em; float:right; text-align:left;" | ||
+ | }; | ||
+ | self.proofreadpage_add_container = true; | ||
+ | |||
+ | mw.loader.load(wgAbsoluteScript+'?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript'); | ||
+ | |||
+ | var $pagetext = $("#bodyContent").find(".pagetext"); | ||
+ | if ($pagetext.length) { | ||
+ | $pagetext.html( $pagetext.html().replace(/`/g, "̀").replace(/´/g, "́") ); | ||
+ | } | ||
}; | }; | ||
− | + | ||
− | + | var enhanceDiffs = function() { | |
− | + | importScript("МедияУики:Gadget-Quick diff.js"); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}; | }; | ||
− | + | var enhancePageEditing = function() { | |
− | + | var extraSymbolMaps = { | |
− | + | symbols: [ | |
− | + | { | |
− | + | action: { type: "encapsulate", options: { pre: "⟨", post: "⟩" } }, | |
− | var | + | label: "⟨⟩" |
− | + | }, | |
− | + | "△", "▽", "◇", "`", "{{* * *}}", "{{?}}", "{{+}}" | |
− | + | ], | |
− | + | greek: [ | |
− | + | "ἀ", "ὰ", "ᾰ", "ᾱ", "ᾶ", "ἐ", "ὐ", "ῡ", "ῦ", "ῐ", "ῑ", "ῖ", "ῶ", "ω̄" | |
− | + | ], | |
− | var addExtraSymbols = function(pages, symbols) { | + | cyrillic: [ |
− | + | "Ѣ", "ѣ", "Ѥ", "ѥ", "Ѧ", "ѧ", "Ѩ", "ѩ", "Ѫ", "ѫ", "Ѭ", "ѭ", "Ѯ", "ѯ", "Ѱ", "ѱ", "Ѳ", "ѳ", "Ѵ", "ѵ" | |
− | + | ], | |
+ | Ударения: [ | ||
+ | '\u0300', '\u0301', '\u0306' | ||
+ | ] | ||
+ | }; | ||
+ | var addExtraSymbols = function(pages) { | ||
+ | $.each(extraSymbolMaps, function(key, symbols){ | ||
+ | if (!pages[key]) { | ||
+ | pages[key] = { | ||
+ | labelMsg: key, | ||
+ | layout: "characters", | ||
+ | characters: [] | ||
+ | }; | ||
+ | } | ||
+ | $.each(symbols, function(i, symbol){ | ||
+ | pages[key].characters.push(symbol); | ||
+ | }); | ||
}); | }); | ||
}; | }; | ||
Ред 51: | Ред 83: | ||
var newPages = {}; | var newPages = {}; | ||
newPages = { | newPages = { | ||
− | + | symbols: pages.symbols, | |
− | + | greek: pages.greek, | |
− | + | cyrillic: pages.cyrillic, | |
+ | Ударения: pages.Ударения | ||
}; | }; | ||
$.each(pages, function(i, v){ | $.each(pages, function(i, v){ | ||
Ред 60: | Ред 93: | ||
return newPages; | return newPages; | ||
}; | }; | ||
− | + | var putPageFormattingButtons = function(tools) { | |
− | + | tools.htmlbold = { | |
− | |||
− | |||
− | |||
− | |||
action: { type: "encapsulate", options: { pre: "<b>", post: "</b>" } }, | action: { type: "encapsulate", options: { pre: "<b>", post: "</b>" } }, | ||
label: "Получер текст чрез маркер <b>", | label: "Получер текст чрез маркер <b>", | ||
Ред 71: | Ред 100: | ||
group: "format", section: "main", type: "button" | group: "format", section: "main", type: "button" | ||
}; | }; | ||
− | + | tools.htmlitalic = { | |
action: { type: "encapsulate", options: { pre: "<i>", post: "</i>" } }, | action: { type: "encapsulate", options: { pre: "<i>", post: "</i>" } }, | ||
label: "Курсивен текст чрез маркер <i>", | label: "Курсивен текст чрез маркер <i>", | ||
Ред 77: | Ред 106: | ||
type: "button" | type: "button" | ||
}; | }; | ||
+ | tools.htmlspaced = { | ||
+ | action: { type: "encapsulate", options: { pre: "<em>", post: "</em>" } }, | ||
+ | label: "Текст с разредка", | ||
+ | icon: '//upload.wikimedia.org/wikipedia/commons/3/3b/Toolbaricon_regular_a_to_b.png', | ||
+ | type: "button" | ||
+ | }; | ||
+ | |||
+ | delete tools.bold; | ||
+ | delete tools.italic; | ||
+ | }; | ||
+ | $('#wpTextbox1').on('wikiEditor-toolbar-buildSection-characters', function (event, section) { | ||
+ | addExtraSymbols(section.pages); | ||
+ | section.pages = reorderPages(section.pages); | ||
+ | }); | ||
+ | $('#wpTextbox1').on('wikiEditor-toolbar-buildSection-main', function (event, section) { | ||
+ | if (mw.config.get("wgCanonicalNamespace") == "Page") { | ||
+ | putPageFormattingButtons(section.groups.format.tools); | ||
+ | } | ||
section.groups.insert.tools.horizline = { | section.groups.insert.tools.horizline = { | ||
action: { type: "encapsulate", options: { pre: "----\n" } }, | action: { type: "encapsulate", options: { pre: "----\n" } }, | ||
Ред 84: | Ред 131: | ||
}; | }; | ||
}); | }); | ||
+ | |||
+ | var insertTab = function(textarea) { | ||
+ | // get caret position/selection | ||
+ | var start = textarea.selectionStart; | ||
+ | var end = textarea.selectionEnd; | ||
+ | |||
+ | var $textarea = $(textarea); | ||
+ | var value = $textarea.val(); | ||
+ | |||
+ | // set textarea value to: text before caret + tab + text after caret | ||
+ | $textarea.val(value.substring(0, start) | ||
+ | + "\t" | ||
+ | + value.substring(end)); | ||
+ | |||
+ | // put caret at right position again (add one for the tab) | ||
+ | textarea.selectionStart = textarea.selectionEnd = start + 1; | ||
+ | }; | ||
+ | var updateTextboxHeight = function(textbox) { | ||
+ | $textbox = textbox ? $(textbox) : $("#wpTextbox1"); | ||
+ | $textbox.height($(".prp-page-image:eq(0)").height()); | ||
+ | }; | ||
+ | |||
+ | $("#wpTextbox1").on("keydown", function(e) { | ||
+ | if(e.keyCode === 9 && !e.shiftKey) { | ||
+ | insertTab(this); | ||
+ | e.preventDefault(); | ||
+ | } | ||
+ | }); | ||
+ | $("#wpTextbox1").on("focus", function() { | ||
+ | updateTextboxHeight(this); | ||
+ | }); | ||
+ | |||
+ | mw.loader.using( 'jquery.prpZoom', function() { | ||
+ | $.widget( "mw.prpZoom", $.mw.prpZoom, { | ||
+ | options: { | ||
+ | zoomStep: 10 | ||
+ | }, | ||
+ | _zoom: function( proportion ) { | ||
+ | var position = this._getPosition(); | ||
+ | if (!window.stickyTopByZoom) { | ||
+ | position.left -= proportion * this.zoomStep.width; | ||
+ | position.top -= proportion * this.zoomStep.height; | ||
+ | } | ||
+ | position.width += 2 * proportion * this.zoomStep.width; | ||
+ | position.height += 2 * proportion * this.zoomStep.height; | ||
+ | |||
+ | var scaleFactor = this._getScaleFactor( position ); | ||
+ | if( this.options.minScaleFactor > scaleFactor || scaleFactor > this.options.maxScaleFactor ) { | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | this._applyPosition( position ); | ||
+ | } | ||
+ | }); | ||
+ | setTimeout(updateTextboxHeight, 2000); | ||
+ | }); | ||
+ | |||
+ | }; | ||
+ | |||
+ | jQuery(function($) { | ||
+ | switch (mw.config.get("wgCanonicalNamespace")) { | ||
+ | case "Page": | ||
+ | switch (mw.config.get("wgAction")) { | ||
+ | case "edit": | ||
+ | enhancePageEditing(); | ||
+ | break; | ||
+ | case "view": | ||
+ | enhancePageViewing(); | ||
+ | break; | ||
+ | } | ||
+ | break; | ||
+ | } | ||
}); | }); | ||
+ | |||
+ | switch (mw.config.get("wgCanonicalSpecialPageName")) { | ||
+ | case "Recentchanges": | ||
+ | case "Contributions": | ||
+ | enhanceDiffs(); | ||
+ | break; | ||
+ | default: | ||
+ | if (mw.config.get("wgAction") == "history") { | ||
+ | enhanceDiffs(); | ||
+ | } | ||
+ | } |
Текуща версия към 17:11, 2 април 2014
var wgAbsoluteScript = mw.config.get("wgServer")+mw.config.get("wgScript"); var enhancePageViewing = function() { // Dynamic layouts if ( !self.ws_layouts ) { self.ws_layouts = {}; } self.ws_layouts['Layout 1'] = { '#text-wrap':"", '#text-container':"", '#text':"", '.sidenote-right':"float:right; margin:0.5em; padding:3px; border:solid 1px gray; max-width:9em; text-indent:0em; text-align:left;", '.sidenote-left':"float:left; margin:0.5em; padding:3px; border:solid 1px gray; max-width:9em; text-indent:0em; text-align:left;", '.mw-editsection':"display:none;", '#headertemplate':"" }; self.ws_layouts['Layout 2'] = { '#text-wrap':"position:relative; margin-left:3.0em; margin-right:3.0em;", '#text-container':"width:40em; margin:0 auto;", '#text':"text-align:justify;", '.sidenote-right':"position:absolute; left:37em; width:16em; text-indent:0em; text-align:left;", '.sidenote-left':"position:absolute; left:37em; width:16em; text-indent:0em; text-align:left;", '.mw-editsection':"display:none;", '#headertemplate':"" }; self.ws_layouts['Layout 3'] = { '#text-wrap':"margin-left:3.0em;", '#text-container':"position:relative; min-width:60em; float:left; width:100%; margin-right:-23em;", '#text':"position:relative; text-align:justify; margin-right:23em; text-indent:0em; padding-left:0px; padding-right:0px; width:auto;", '.sidenote-right':"position:absolute; right:-10em; width:9em; background-color:#eeeeee; text-indent:0em; text-align:left;", '.sidenote-left':"position:absolute; right:-10em; width:9em; background-color:#eeeeee; text-indent:0em; text-align:left;", '.mw-editsection':"display:none;", '#headertemplate':"position:absolute; top:0em; right:-23em; width:21em; float:right; text-align:left;" }; self.proofreadpage_add_container = true; mw.loader.load(wgAbsoluteScript+'?title=MediaWiki:PageNumbers.js&action=raw&ctype=text/javascript'); var $pagetext = $("#bodyContent").find(".pagetext"); if ($pagetext.length) { $pagetext.html( $pagetext.html().replace(/`/g, "̀").replace(/´/g, "́") ); } }; var enhanceDiffs = function() { importScript("МедияУики:Gadget-Quick diff.js"); }; var enhancePageEditing = function() { var extraSymbolMaps = { symbols: [ { action: { type: "encapsulate", options: { pre: "⟨", post: "⟩" } }, label: "⟨⟩" }, "△", "▽", "◇", "`", "{{* * *}}", "{{?}}", "{{+}}" ], greek: [ "ἀ", "ὰ", "ᾰ", "ᾱ", "ᾶ", "ἐ", "ὐ", "ῡ", "ῦ", "ῐ", "ῑ", "ῖ", "ῶ", "ω̄" ], cyrillic: [ "Ѣ", "ѣ", "Ѥ", "ѥ", "Ѧ", "ѧ", "Ѩ", "ѩ", "Ѫ", "ѫ", "Ѭ", "ѭ", "Ѯ", "ѯ", "Ѱ", "ѱ", "Ѳ", "ѳ", "Ѵ", "ѵ" ], Ударения: [ '\u0300', '\u0301', '\u0306' ] }; var addExtraSymbols = function(pages) { $.each(extraSymbolMaps, function(key, symbols){ if (!pages[key]) { pages[key] = { labelMsg: key, layout: "characters", characters: [] }; } $.each(symbols, function(i, symbol){ pages[key].characters.push(symbol); }); }); }; var reorderPages = function(pages) { var newPages = {}; newPages = { symbols: pages.symbols, greek: pages.greek, cyrillic: pages.cyrillic, Ударения: pages.Ударения }; $.each(pages, function(i, v){ newPages[i] = pages[i]; }); return newPages; }; var putPageFormattingButtons = function(tools) { tools.htmlbold = { action: { type: "encapsulate", options: { pre: "<b>", post: "</b>" } }, label: "Получер текст чрез маркер <b>", icon: '//upload.wikimedia.org/wikipedia/commons/a/ae/Toolbaricon_bold_b.png', group: "format", section: "main", type: "button" }; tools.htmlitalic = { action: { type: "encapsulate", options: { pre: "<i>", post: "</i>" } }, label: "Курсивен текст чрез маркер <i>", icon: '//upload.wikimedia.org/wikipedia/commons/c/c4/Toolbaricon_italic_i.png', type: "button" }; tools.htmlspaced = { action: { type: "encapsulate", options: { pre: "<em>", post: "</em>" } }, label: "Текст с разредка", icon: '//upload.wikimedia.org/wikipedia/commons/3/3b/Toolbaricon_regular_a_to_b.png', type: "button" }; delete tools.bold; delete tools.italic; }; $('#wpTextbox1').on('wikiEditor-toolbar-buildSection-characters', function (event, section) { addExtraSymbols(section.pages); section.pages = reorderPages(section.pages); }); $('#wpTextbox1').on('wikiEditor-toolbar-buildSection-main', function (event, section) { if (mw.config.get("wgCanonicalNamespace") == "Page") { putPageFormattingButtons(section.groups.format.tools); } section.groups.insert.tools.horizline = { action: { type: "encapsulate", options: { pre: "----\n" } }, label: "Хоризонтална линия", icon: '//upload.wikimedia.org/wikipedia/commons/b/b4/Toolbaricon_rule.png', type: "button" }; }); var insertTab = function(textarea) { // get caret position/selection var start = textarea.selectionStart; var end = textarea.selectionEnd; var $textarea = $(textarea); var value = $textarea.val(); // set textarea value to: text before caret + tab + text after caret $textarea.val(value.substring(0, start) + "\t" + value.substring(end)); // put caret at right position again (add one for the tab) textarea.selectionStart = textarea.selectionEnd = start + 1; }; var updateTextboxHeight = function(textbox) { $textbox = textbox ? $(textbox) : $("#wpTextbox1"); $textbox.height($(".prp-page-image:eq(0)").height()); }; $("#wpTextbox1").on("keydown", function(e) { if(e.keyCode === 9 && !e.shiftKey) { insertTab(this); e.preventDefault(); } }); $("#wpTextbox1").on("focus", function() { updateTextboxHeight(this); }); mw.loader.using( 'jquery.prpZoom', function() { $.widget( "mw.prpZoom", $.mw.prpZoom, { options: { zoomStep: 10 }, _zoom: function( proportion ) { var position = this._getPosition(); if (!window.stickyTopByZoom) { position.left -= proportion * this.zoomStep.width; position.top -= proportion * this.zoomStep.height; } position.width += 2 * proportion * this.zoomStep.width; position.height += 2 * proportion * this.zoomStep.height; var scaleFactor = this._getScaleFactor( position ); if( this.options.minScaleFactor > scaleFactor || scaleFactor > this.options.maxScaleFactor ) { return; } this._applyPosition( position ); } }); setTimeout(updateTextboxHeight, 2000); }); }; jQuery(function($) { switch (mw.config.get("wgCanonicalNamespace")) { case "Page": switch (mw.config.get("wgAction")) { case "edit": enhancePageEditing(); break; case "view": enhancePageViewing(); break; } break; } }); switch (mw.config.get("wgCanonicalSpecialPageName")) { case "Recentchanges": case "Contributions": enhanceDiffs(); break; default: if (mw.config.get("wgAction") == "history") { enhanceDiffs(); } }