Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WiktionaryThe Free Dictionary
Search

MediaWiki:Gadget-AjaxEdit.js

    From Wiktionary, the free dictionary

    Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such asMediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

    • Mozilla / Firefox / Safari: holdShift while clickingReload, or press eitherCtrl-F5 orCtrl-R (Command-R on a Macintosh);
    • Konqueror andChrome: clickReload or pressF5;
    • Opera: clear the cache inTools → Preferences;
    • Internet Explorer: holdCtrl while clickingRefresh, or pressCtrl-F5.

    The followingdocumentation is located atMediaWiki:Gadget-AjaxEdit.js/documentation.[edit]
    This script is a part of theAjaxEdit gadget (edit definitions)
    Description (edit): AjaxEdit: add a button "Ædit" which allows one to edit specific sections without reloading the whole page
    Useful links:subpage listlinksredirectstransclusions

    FromUser:Dixtosa/AjaxEdit.js, compiled to ECMAScript version 5 byBabel.

    // AjaxEdit// <nowiki>"use strict";// Description         : With a new button "Ædit" one can edit specific sections without reloading the whole page.//                       Supports TabbedLanguages gadget// Dependencies: mediawiki.util, mediawiki.Uri, mediawiki.user, mediawiki.api/* jshint maxerr:1048576, strict:true, undef:true, latedef:true, sub:true, esversion:5, esnext:false *//* global mw, $ */(functionajaxEditIife(){window.AjaxEdit={};window.AjaxEdit.scriptLink="";if(mw.config.get("wgSiteName")!=="Wiktionary")window.AjaxEdit.scriptLink+="wikt:";if(mw.config.get("wgContentLanguage")!=="en")window.AjaxEdit.scriptLink+="en:";window.AjaxEdit.scriptLink+="MediaWiki:Gadget-AjaxEdit.js";var$document=$(document);window.AjaxEdit.FireEvents=function(){// fire page load events like the [quotations ▼] thing// see https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki.action/mediawiki.action.edit.preview.jsmw.hook("wikipage.content").fire($document);mw.hook("wikipage.categories").fire($document);};window.AjaxEdit.Click=function(ajaxEditAnchor){if(ajaxEditAnchor.hasEditBox){mw.notify("This AjaxEdit edit box is already open.");return;}elseif(document.getElementById("ajaxedit-wrapper")){mw.notify("An AjaxEdit edit box is already open on this page.");return;}else{ajaxEditAnchor.hasEditBox=true;}varelements={};var_query=newURL($(ajaxEditAnchor).parent().find("a[href*='action=edit']").attr("href"),location.href).searchParams,title=_query.get("title"),section=_query.get("section");section=section.replace("T-","");//transclusions...varhdr=$(ajaxEditAnchor).parent().parent();varsectionName=hdr.children(":header").first().text();if(window.tabbedLanguages&&!hdr.is(":header")){sectionName=window.tabbedLanguages[window.currentLanguageTab];}vardata={action:'raw',title:title,section:section};$.get(mw.util.wikiScript('index'),data).then(function(wikitext){varrowHeight=Math.min(15,1+wikitext.split("\n").length);elements.textarea=$("<textarea/>").attr({rows:rowHeight}).addClass("mw-editfont-monospace").text(wikitext);elements.textareaSummary=$("<input/>").attr({type:"text",maxlength:500,spellcheck:true,name:"wpSummary",}).keydown(event,function(){if(event.keyCode==13){// on enterelements.saveButton.click();}});functioncheckboxAndLabel(id,text){varcheckbox=$("<input/>").attr({"id":id,"type":"checkbox",});varlabel=$("<label/>").attr("for",id).text(text);return[checkbox,label];}varminorEdit=checkboxAndLabel("ajaxedit-minor-edit-checkbox","Minor edit");elements.minorEditCheckbox=minorEdit[0],elements.minorEditLabel=minorEdit[1];elements.saveButton=$("<button/>").text("Save").click(function(){elements.textarea.attr('disabled',true);elements.textareaSummary.attr('disabled',true);window.AjaxEdit.Save(section,sectionName,elements.textarea.val(),title,elements.textareaSummary.val(),elements.minorEditCheckbox.prop("checked")).then(function(apiSaveResponse){if(apiSaveResponse.error)return;//if abusefilter was triggerednewmw.Api().get({page:mw.config.get("wgPageName"),action:"parse",prop:"text|categorieshtml"}).then(function(newHtml){$("#ajaxedit-wrapper").remove();$("#mw-content-text").html(newHtml.parse.text["*"]);$("#catlinks").replaceWith(newHtml.parse.categorieshtml["*"]);window.AjaxEdit.FireEvents();mw.loader.moduleRegistry["site"].state="registered";//mw.loader.moduleRegistry["site"].version="generate-unique-guid-here";mw.loader.moduleRegistry["site"].script=undefined;mw.loader.using("site",function(){});window.AjaxEdit.Submain();});});}).css("margin-left","3px");elements.cancelButton=$('<button/>').text("Cancel").click(function(){$("#ajaxedit-wrapper").remove();ajaxEditAnchor.hasEditBox=false;});elements.previewDiv=$("<div/>").css({"border-style":"solid","border-width":"1px 1px 1px 4px","border-radius":"0.33em","border-color":"#a3d3ff",}).hide();functiontimestamp(){returnnewDate().toISOString();}varpreviousText;varpreviousTextTimestamp=timestamp();functionloadPreview(){varnewText=elements.textarea.val();vartextTimestamp=timestamp();if(!previousText||previousText!=newText){newmw.Api().parse(newText,{title:mw.config.get("wgPageName"),pst:"true",preview:"true",sectionpreview:"true",disableeditsection:"true"}).done(function(html){if(textTimestamp>previousTextTimestamp){elements.previewDiv.html(html);window.AjaxEdit.FireEvents();previousTextTimestamp=textTimestamp;}});}previousText=newText;}varlivePreview=checkboxAndLabel("ajaxedit-live-preview-checkbox","Live preview");elements.livePreviewCheckbox=livePreview[0],elements.livePreviewLabel=livePreview[1];elements.livePreviewCheckbox.on("change",function(){if($(this).prop("checked")){elements.previewDiv.show("slow");loadPreview();this.previewIntervalId=setInterval(loadPreview,500);}else{clearInterval(this.previewIntervalId);elements.previewDiv.hide("fast");elements.previewDiv.empty();}});varwrapper=$("<div/>").attr("id","ajaxedit-wrapper").css({width:"auto","margin":0,"overflow":"hidden"}).append(elements.textarea).append(elements.textareaSummary).append(elements.saveButton).append(elements.livePreviewCheckbox).append(elements.livePreviewLabel).append(elements.minorEditCheckbox).append(elements.minorEditLabel).append(elements.cancelButton).append(elements.previewDiv);//tabbed languages supportif($(ajaxEditAnchor).is("#tabstable .editlangsection a")){$(".languageContainer:not(:hidden)").first().prepend(wrapper);}else{hdr.after(wrapper);}});};/* * Define edit summary template with window.AjaxEditSummary. For instance: window.AjaxEditSummary = "Æ $sectionlink $summary"; */window.AjaxEdit.Save=function(sectionID,sectionName,sectionText,title,summary,minorEdit){varfinalSummary;if(typeofwindow.AjaxEditSummary==="string"){varusedSummary=false;finalSummary=window.AjaxEditSummary.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,function(fullMatch,name){switch(name){case"summary":{usedSummary=true;returnsummary;}case"scriptlink":returnwindow.AjaxEdit.scriptLink;case"sectionname":returnsectionText;case"sectionlink":return"/* "+sectionName+" */";default:{mw.notify("Your edit summary template (window.AjaxEditSummary) contains an unknown variable name. Variable name: "+name+". Choose from summary, scriptlink, sectionname, sectionlink.");return"";}}});if(!usedSummary){mw.notify("Your edit summary template (window.AjaxEditSummary) doesn't use the edit summary you supplied, so your edit summary will be appended to the template: "+window.AjaxEditSummary);finalSummary+=" "+summary;}}else{finalSummary="/* "+sectionName+" */ "+summary+" (using [["+window.AjaxEdit.scriptLink+"|AjaxEdit]])";}vardata={format:'json',action:'edit',title:title,section:sectionID,summary:finalSummary,text:sectionText,token:mw.user.tokens.get('csrfToken'),minor:minorEdit,};returnnewmw.Api().post(data).then(function(response){if(response&&response.edit&&response.edit.result=='Success'){mw.notify("successful");}elseif(response&&response.error){mw.notify('Error: API returned error code "'+response.error.code+'": '+response.error.info);}returnresponse;}).fail(function(xhr){mw.notify('Error: Request failed.');$('#ajaxedit-wrapper *').attr('disabled',false);});};window.AjaxEdit.Submain=function(){$(".mw-body-content .mw-editsection > .mw-editsection-bracket:contains(']')").each(function(){varbtn=$('<a/>').text("Ædit").on("click",function(){window.AjaxEdit.Click(this)});$(this).before(", ").before(btn);});};window.AjaxEdit.Main=function(){$(".mw-editsection > .mw-editsection-bracket:contains(']')").each(function(){varbtn=$('<a/>').text("Ædit").on("click",function(){window.AjaxEdit.Click(this)});$(this).before(", ").before(btn);});};if(mw.config.get('wgAction')=="view")$(window.AjaxEdit.Main);})();// </nowiki>
    Retrieved from "https://en.wiktionary.org/w/index.php?title=MediaWiki:Gadget-AjaxEdit.js&oldid=87271514"
    Category:

    [8]ページ先頭

    ©2009-2025 Movatter.jp