Editor Stable

Link to code

/**********************************************
/* Wikidot Extension
/* Copyright (c) Kenneth Tsang 2013
/* All rights reserved.
/*
/* No part of the code below can be reproduced
/* for any purpose without the permission of
/* the author(s)
/*********************************************/
(function(a){a.jxeenoEditor=function(d,j,m,n){var o=a(d);if(typeof(j)!="string"){j="true"}if(typeof(m)!="string"){m="true"}if(typeof(n)!="string"){n="true"}a('<div id="wdEditor-suggest"/>').appendTo(document.body);var e="";var l={elId:"#wdEditor-suggest",type:"",showing:false,replaceLocation:{start:0,end:0},list:[],selected:0,select:function(s){if(typeof(s)=="undefined"){s=this.selected}var t=this.list[s];i(o[0],t.replacement,this.replaceLocation.start,this.replaceLocation.end,false);this.hideSuggest();if(typeof(t.select)=="object"){var r=h(o[0]);p(o[0],r+t.select[0]+t.select[1],r+t.select[0])}else{f(o[0])}},setHover:function(r){if(typeof(r)=="undefined"){r=this.selected}a(l.elId+" li a").removeClass("hover");a(l.elId+" li a#ui-"+r+"-id").addClass("hover")},showSuggest:function(){if(this.list.length==0){this.hideSuggest();return}var r=o.getCaretPosition();var s={};s.left=o.offset().left+r.left;s.top=o.offset().top+r.top;var t="";a.each(this.list,function(w,u){t+='<li class="ui-menu-item" role="presentation"><a id="ui-'+w+'-id" class="ui-corner-all" tabindex="-1">'+u.label+"</a></li>"});a(l.elId).html(t);a(l.elId+" .ui-menu-item a").click(function(){l.selected=this.id.match(/ui-([0-9]+)-id/)[1];l.select()}).hover(function(){l.selected=this.id.match(/ui-([0-9]+)-id/)[1];l.setHover()});a(l.elId).css({top:s.top,left:s.left}).show();this.selected=0;this.setHover();this.showing=true},hideSuggest:function(){this.type="";this.showing=false;this.replaceLocation={start:0,end:0};this.list=[];this.selected=0;a(l.elId).hide()}};var h=function(t){if(t.selectionStart){return t.selectionStart}else{if(document.selection){t.focus();var u=document.selection.createRange();if(u==null){return 0}var s=t.createTextRange(),v=s.duplicate();s.moveToBookmark(u.getBookmark());v.setEndPoint("EndToStart",s);return v.text.length}}return 0};var b=function(w,y,x){var r=w.scrollTop;var t=0;if(typeof(x)=="undefined"){var x=true}var z=((w.selectionStart||w.selectionStart=="0")?"ff":(document.selection?"ie":false));if(z=="ie"){w.focus();var v=document.selection.createRange();v.moveStart("character",-w.value.length);t=v.text.length}else{if(z=="ff"){t=w.selectionStart}}var s=(w.value).substring(0,t);var u=(w.value).substring(t,w.value.length);w.value=s+y+u;t=t;if(!x){t+=y.length}if(z=="ie"){w.focus();var v=document.selection.createRange();v.moveStart("character",-w.value.length);v.moveStart("character",t);v.moveEnd("character",0);v.select()}else{if(z=="ff"){w.selectionStart=t;w.selectionEnd=t;w.focus()}}w.scrollTop=r};var i=function(y,A,r,v,z){var s=y.scrollTop;var u=r;var B=((y.selectionStart||y.selectionStart=="0")?"ff":(document.selection?"ie":false));var t=(y.value).substring(0,r);var w=(y.value).substring(v,y.value.length);y.value=t+A+w;u=u;if(!z){u+=A.length}if(B=="ie"){y.focus();var x=document.selection.createRange();x.moveStart("character",-y.value.length);x.moveStart("character",u);x.moveEnd("character",0);x.select()}else{if(B=="ff"){y.selectionStart=u;y.selectionEnd=u;y.focus()}}y.scrollTop=s};var g=function(x,w,y){var r=x.scrollTop;var t=0;if(typeof(y)=="undefined"){var y=true}var z=((x.selectionStart||x.selectionStart=="0")?"ff":(document.selection?"ie":false));if(z=="ie"){x.focus();var v=document.selection.createRange();v.moveStart("character",-x.value.length);t=v.text.length}else{if(z=="ff"){t=x.selectionStart}}var s=(x.value).substring(0,t);var u=(x.value).substring(t,x.value.length);if(y){s=s.substring(-w,w);t-=w}else{u=u.substr(0,w)}x.value=s+u;if(z=="ie"){x.focus();var v=document.selection.createRange();v.moveStart("character",-x.value.length);v.moveStart("character",t);v.moveEnd("character",0);v.select()}else{if(z=="ff"){x.selectionStart=t;x.selectionEnd=t;x.focus()}}x.scrollTop=r};function p(s,t,r){s.focus();if(s.setSelectionRange){s.setSelectionRange(t,r)}else{if(s.createTextRange){s=s.createTextRange();s.collapse(true);s.moveEnd("character",r);s.moveStart("character",t);s.select()}}}var f=function(s,F){var J=a(s);var u=J.val();if(F==undefined){F=event}var I=F.keyCode;var y=true;if(u==e){y=false;if(l.showing){switch(I){case 13:l.select();return;break;case 27:l.hideSuggest();return;break;case 38:if((l.selected-1)>=0){l.selected-=1;l.setHover()}return;break;case 40:if((l.selected+1)<=(l.list.length-1)){l.selected+=1;l.setHover()}return;break}}}e=u;var G=h(s);var x=true;var A=u.substr(0,G);var C=u.substr(G);var H=A.match(/([\n\r]|^)(.*?)$/);if(H!=null){H=H[2]}else{H=""}var v=C.match(/^(.*?)([\n\r]|$)/);if(v!=null){v=v[1]}else{v=""}var E=H+v;var r=false;if(C.length==0||C.match(/^[\n\r]/)){r=true}var z=function(U,V,N,S){var Q=U.split("");var K=U.regexEscape();var M=1;while(M<U.length){K+="|"+U.substr(0,(U.length-M)).regexEscape()+"(?:[^a-zA-Z0-9]|$)";M++}var O="(())";if(V){O="(( [a-zA-Z0-9]*){0,1})"}var T=S.match(new RegExp("^"+N[0]+"("+K+")"+O+"(("+N[1]+")| .+("+N[1]+"))?"));if(!T){return[false,"","",false]}var R=(typeof(T[4])!="undefined");if(R){F=T[4]}else{F=""}var L="";if(R){var P=T[4].match(new RegExp("^(.*?)"+N[1]+"$"));if(P){L=P[1]}}if(T[1].match(/[^a-zA-Z0-9]$/)){T[2]=T[1].match(/[^a-zA-Z0-9]$/)[0]+T[2];T[1]=T[1].replace(/[^a-zA-Z0-9]$/,"")}return[T[1],T[2],L,R,F]};l.list=[];if(n=="true"){var t=[{blockName:"module",brackets:["[[","]]"],closeBlock:"[[/module]]",dual:true,dataVar:[jxeeno.moduleList,jxeeno.moduleListArr]},{blockName:"collapsible",brackets:["[[","]]"],dual:false,dataVar:[{"":{params:{show:"str",hide:"str",folded:"no|yes",hideLocation:"both|bottom|top"},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"code",brackets:["[[","]]"],dual:false,dataVar:[{"":{params:{type:"lang"},singleLine:true,onlySingleLine:true,importance:0}},[]]},{blockName:"iftags",brackets:["[[","]]"],closeBlock:"[[/iftags]]",dual:false,dataVar:[{"":{params:{},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"toc",brackets:["[[","]]"],dual:false,dataVar:[{},[]]},{blockName:"include",brackets:["[[","]]"],dual:false,dataVar:[{},[]]},{blockName:"user",brackets:["[[","]]"],dual:false,dataVar:[{},[]]},{blockName:"*user",brackets:["[[","]]"],dual:false,dataVar:[{},[]]},{blockName:"gallery",brackets:["[[","]]"],closeBlock:"[[/gallery]]",dual:false,dataVar:[{"":{params:{size:"square|thumbnail|small|medium",order:"name|created_at [desc]",viewer:"true|false"},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"div",brackets:["[[","]]"],closeBlock:"[[/div]]",dual:false,dataVar:[{"":{params:{style:"css: code;","class":"css-class"},singleLine:true,onlySingleLine:false,importance:0}},[]]},{blockName:"span",brackets:["[[","]]"],closeBlock:"[[/span]]",dual:false,dataVar:[{"":{params:{style:"css: code;","class":"css-class"},singleLine:true,onlySingleLine:true,importance:0}},[]]},{blockName:"table",brackets:["[[","]]"],closeBlock:"[[/table]]",dual:false,dataVar:[{"":{params:{style:"css: code;","class":"css-class"},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"row",brackets:["[[","]]"],closeBlock:"[[/row]]",dual:false,dataVar:[{"":{params:{style:"css: code;","class":"css-class"},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"cell",brackets:["[[","]]"],closeBlock:"[[/cell]]",dual:false,dataVar:[{"":{params:{style:"css: code;","class":"css-class"},singleLine:false,onlySingleLine:false,importance:0}},[]]},{blockName:"image",brackets:["[[","]]"],dual:true,dataVar:[{"":{params:{link:"uri",alt:"str",title:"str",width:"px|em|%",height:"px|em|%",style:"css","class":"css-class",size:"square|thumbnail|small|medium|large"},singleLine:true,onlySingleLine:true,importance:0}},[]]}];a.each(t,function(M,L){var K=c(L.blockName,L.dual,L.brackets,L.dataVar,E,A,H,C,v,G,I,z);if(!K){x=false}})}if(m=="true"){if(I==13&&A.match(/([\n\r])$/)){var B=A.substr(0,A.length-H.length);var w=B.match(/([\n\r]|^)(.*?)[\n\r]$/);if(w!=null){w=w[2]}else{w=""}a.each(t,function(M,L){var O=[L.brackets[0].regexEscape(),L.brackets[1].regexEscape()];var N=z(L.blockName,L.dual,O,w);if(N[0]){if(typeof(L.dataVar[0][a.trim(N[1])])!="undefined"||typeof(L.dataVar[0]["*"])!="undefined"){if(typeof(L.dataVar[0]["*"])!="undefined"){var K=L.dataVar[0]["*"]}else{var K=L.dataVar[0][a.trim(N[1])]}if(!K.onlySingleLine&&!w.match(new RegExp(L.closeBlock.regexEscape()))){b(o[0],"\n"+L.closeBlock,true)}}}})}}if(j=="true"){var D=[{opening:"[!--",closing:"--",multiple:false},{opening:"[",closing:"]",multiple:true},{opening:"//",closing:"//",multiple:false},{opening:"**",closing:"**",multiple:false},{opening:"__",closing:"__",multiple:false},{opening:"@@",closing:"@@",multiple:false},{opening:"@<",closing:">@",multiple:false},{opening:"##",closing:"|text##",multiple:false},{opening:"%%",closing:"%%",multiple:false},{opening:"{$",closing:"}",multiple:false},{opening:"%%form_data{",closing:"}",multiple:false},{opening:"%%form_raw{",closing:"}",multiple:false},{opening:"%%form_hint{",closing:"}",multiple:false},{opening:"%%form_label{",closing:"}",multiple:false},{opening:"%%content{",closing:"}",multiple:false}]}else{var D=[]}if(y){a.each(D,function(L,K){q(K.opening,K.closing,K.multiple,E,H,v,I)})}if(!x){l.showSuggest()}else{l.hideSuggest()}};var q=function(r,w,F,A,y,u,C){var v=r.regexEscape();var s=w.regexEscape();var E="";if(F){E="+"}var z=function(H){var G=H.match(new RegExp("("+v+E+")"));if(!G){return 0}return G[1].length};var x=z(y);if(!u.match(new RegExp("[^("+v+"{"+x+"})]"+s+x))){var t=y.match(new RegExp("("+v+E+")$"));if(!t){t=""}else{t=t[1]}var B=u.match(new RegExp("^("+s+E+")"));if(!B){B=""}else{B=B[1]}if(t.length>0){if(F){var D=t.length-B.length}else{if(t==""){t=0}else{t=1}if(B==""){B=0}else{B=1}var D=t-B}if(D<0){}else{if(C!=8){b(o[0],w.repeat(D))}}}}};var c=function(M,u,x,r,N,F,S,L,y,R,U,E){var D=r[0];var z=r[1];var I=[x[0].regexEscape(),x[1].regexEscape()];var A=true;var G=E(M,u,I,N);if(G[0].length){if(new RegExp("^"+G[0].regexEscape()).test(M)&&M!=a.trim(G[0])){A=false;var C=new RegExp("^("+G[0].html_entities().regexEscape()+")");var s=M.html_entities().match(C);var w=x[0];w+=M.html_entities().replace(C,"<b>$1</b>");w+="..."+x[1];var J=x[0]+M+" ";l.list.push({label:w,replacement:J});l.replaceLocation={start:R-(x[0]+G[0]).length,end:R}}else{if(typeof(D[a.trim(G[1])])!="undefined"||typeof(D["*"])!="undefined"){if(typeof(D["*"])!="undefined"){var H=D["*"]}else{var H=D[a.trim(G[1])]}var v=(a.map(H.params,function(X,W){return W}).length>0);if(v){A=false;var O=R-S.length;var t=G[2].substr(0,S.length-(x[0]+G[0]+G[1]).length);if(S.length>(x[0]+G[0]+G[1]+(G[2]?"":" ")+G[2]).length){t="a"}var K=t.match(/[^\\]["]/g);if(K){var B=((K.length%2)==0)}else{var B=false}if(t==""){t=" "}if(a.trim(t)==""||(B&&t.match(/ $/))){var Q="";if(!S.match(/ $/)){Q=" "}a.each(H.params,function(X,W){l.list.push({label:Q+X+'="'+W+'"',replacement:Q+X+'="'+W+'"',select:[-1,-W.length]})});l.replaceLocation={start:R,end:R}}else{if(t.match(/ ([a-zA-Z]+)$/)){var P=t.match(/ ([a-zA-Z]+)$/)[1];var T=P.regexEscape();var V=new RegExp("^"+T,"i");a.each(H.params,function(X,W){if(X.match(V)){l.list.push({label:X+'="'+W+'"',replacement:X+'="'+W+'"',select:[-1,-W.length]})}});l.replaceLocation={start:R-P.length,end:R}}}l.list=l.list.slice(0,10)}}else{A=false;var T=a.trim(G[1]).regexEscape();var V=new RegExp("^"+T,"i");a.each(D,function(Z,W){if(Z.match(V)){var Y=(objLen(W.params)>0);var X=x[0]+M+" ";X=X.replace(new RegExp("^("+I[0]+G[0]+")"),"<b>$1</b>");X+=Z.replace(new RegExp("^("+T+")"),"<b>$1</b>");if(Y){X+="..."}if(G[3]){X+="<b>"+x[1]+"</b>"}else{X+=x[1]}var aa=x[0]+M+" "+Z+" ".repeat(Y);l.list.push({label:X,replacement:aa,meta:W})}});l.list=l.list.sort(function(X,W){return W.meta.importance-X.meta.importance}).slice(0,10);var O=R-S.length;l.replaceLocation={start:R-S.length,end:O+(x[0]+G[0]+G[1]).length}}}}return A};o.keydown(function(r){if(l.showing){switch(r.which){case 13:case 27:case 38:case 40:r.preventDefault();return false;break}}});o.keyup(function(r){if(a(this).hasClass("wdeditor-enabled")){f(this,r)}});o.addClass("wdeditor-enabled");var k="(function($){var a=$('#edit-page-textarea');var b=$('#wE-status');if(a.hasClass('wdeditor-enabled')){a.removeClass('wdeditor-enabled');b.text('disabled')}else{a.addClass('wdeditor-enabled');b.text('enabled')}})(jQuery)";a('<div id="wdEditor-message">Autocomplete <span id="wE-status">enabled</span>! (<a href="javascript:;" onclick="'+k+'">Toggle</a>)</div>').css({color:"#333","font-family":"monospace","font-weight":"bold"}).prependTo(a(".edit-help-34"));String.prototype.repeat=function(r){return new Array(r+1).join(this)};String.prototype.regexEscape=function(){return this.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")};String.prototype.html_entities=function(){return String(this).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")};objLen=function(r){var t=0;var s;for(s in r){if(r.hasOwnProperty(s)){t++}}return t}};a.jxeenoFM=function(h,c){var f=a(h),g=f[0];if(typeof(c)!="string"){c="true"}if(!c=="false"){return}if(window.jxeeno==undefined){window.jxeeno={}}jxeeno=window.jxeeno;jxeeno.ajaxReady=true;jxeeno.fileman={categoryObj:{},tmp:{},curPageID:"",loadingHTML:'<img src="../common--images/301.gif" style="margin: 0 auto;">',path:"#",loadData:function(e,j){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;if(typeof(e)=="undefined"){e=jxeeno.fileman.path}jxeeno.fileman.path=e;var e=e.replace(/^#/,"");if(e==""){a("#fileman-upload-block").hide();a("#fileman-file-list").html("");a("#fileman-page-list").html("");a("#fileman-category-list").html(jxeeno.fileman.loadingHTML);OZONE.ajax.requestModule("list/WikiCategoriesModule",{},function(k){jxeeno.fileman.categoryObj={};a("#fileman-category-list").html('<ul class="nav nav-pills nav-stacked"></ul>');a("<div />").html(k.body).find("div[id^=category-pages]").parent().each(function(){var m=a(this).find("h3").text().toLowerCase();var l=a(this).find("div").attr("id").match(/^category\-pages\-([0-9]+)$/)[1];jxeeno.fileman.categoryObj[m]=l;a("#fileman-category-list ul").append('<li><a href="javascript:;" onclick="jxeeno.fileman.loadData(\'#'+m+'\', this);"><i class="icon-folder-close"></i> '+m+"</a></li>")});jxeeno.ajaxReady=true})}else{if(e.indexOf(":")==-1){a("#fileman-upload-block").hide();a("#fileman-file-list").html("");a("#fileman-page-list").html(jxeeno.fileman.loadingHTML);if(typeof(jxeeno.fileman.categoryObj[e])!="undefined"){var i=jxeeno.fileman.categoryObj[e]}else{alert("Error! Invalid or unknown category selected!");jxeeno.ajaxReady=true;return}a("#fileman-category-list a.active").removeClass("active");a(j).addClass("active");OZONE.ajax.requestModule("list/WikiCategoriesPageListModule",{category_id:i,includeHidden:"true"},function(k){a("#fileman-page-list").html('<ul class="nav nav-pills nav-stacked"></ul>');a(k.body).find("a").each(function(n,o){var l=a(o).attr("href").replace(/^\//,"");var m=l.replace(/^[a-zA-Z0-9\-]+:/,"");var p=l.match(/^([a-zA-Z0-9\-]+):/,"");if(!p){p="_default"}else{p=p[1]}a("#fileman-page-list ul").append('<li><a href="javascript:;" onclick="jxeeno.fileman.loadData(\'#'+p+":"+m+'\', this);"><i class="icon-file"></i> '+m+"</a></li>")});jxeeno.ajaxReady=true})}else{if(e.indexOf("/")==-1){a("#fileman-upload-block").hide();a("#fileman-file-list").html(jxeeno.fileman.loadingHTML);a("#fileman-page-list a.active").removeClass("active");a(j).addClass("active");a.get("/"+e+"/noredirect/true/norender/true",function(l){var k=l.match(/WIKIREQUEST\.info\.pageId = ([0-9]+);/)[1];jxeeno.fileman.curPageID=k;OZONE.ajax.requestModule("files/PageFilesModule",{page_id:k},function(o){a("#fileman-upload-block").fadeIn();var m='<ul class="nav nav-pills nav-stacked">';var n=false;a("<div />").html(o.body).find("tr[id^=file-row-]").each(function(){n=true;var r=a(this).attr("id").replace(/^file-row-/,"");var t=a.trim(a(this).find("td:nth-child(1)").text());var s=a.trim(a(this).find("td:nth-child(2)").text());var q=a.trim(a(this).find("td:nth-child(3)").text());var p="icon-file";if(t.match(/\.(jpe?g|png|gif|tiff|raw)$/i)){p="icon-picture"}if(t.match(/\.(docx?|dotx?)$/i)){p="icon-file"}if(t.match(/\.(xlsx?)$/i)){p="icon-table"}if(t.match(/\.(pptx?)$/i)){p="icon-th"}if(t.match(/\.(pdf)$/i)){p="icon-file"}if(t.match(/\.(zip|rar|7z|tar|gz|bzip2|apk|deb|gzip|jar|lz|lzip|iso)$/i)){p="icon-folder"}if(t.match(/\.(xml|rss)$/i)){p="icon-file"}if(t.match(/\.(css)$/i)){p="icon-file"}if(t.match(/\.(mp3|wma|wav|m4a|aiff|flac|aac)$/i)){p="icon-music"}m+='<li><span class="toolbar btn-group pull-right"><button class="btn" onclick="jxeeno.fileman.download(\''+t+'\');"><i class="icon-search"></i></button><button class="btn" onclick="jxeeno.fileman.del(\''+r+"','"+t+'\');"><i class="icon-trash"></i></button></span><a href="javascript:;" class="jxeeno-tooltip-require" data-toggle="tooltip" title="File Name: '+t+"<br />File Size: "+q+"<br />File Type: "+s+'">'+t+"</a></li>"});if(!n){m='<div class="alert alert-info">This page does not have any files to display :(</div>'}else{m+="</ul>"}a("#fileman-file-list").html(m);a("a.jxeeno-tooltip-require").tooltip({html:true,placement:"left"});jxeeno.ajaxReady=true})}).error(function(){alert("Error! Invalid page requested!");jxeeno.ajaxReady=true;return});jxeeno.ajaxReady=true}else{alert("Error! Unable to interpret meta data!");jxeeno.ajaxReady=true}}}}},search:function(i,e){e=a.trim(e.toLowerCase());if(i=="category"){a("#fileman-category-list a").each(function(j,k){if(a(k).text().toLowerCase().indexOf(e)==-1){a(k).hide()}else{a(k).show()}})}else{if(i=="page"){a("#fileman-page-list a").each(function(j,k){if(a(k).text().toLowerCase().indexOf(e)==-1){a(k).hide()}else{a(k).show()}})}}},searchClear:function(i,e){jxeeno.fileman.search(i,"");a(e).parent().find("input").val("")},del:function(i,e){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;if(confirm("Are you sure you want to delete "+e+"?")){OZONE.ajax.requestModule("Empty",{file_id:i,action:"FileAction",event:"deleteFile"},function(j){if(j.status=="ok"){alert("File "+e+" was successfully deleted!")}else{alert("Oh no! We were unable to delete this file :(")}jxeeno.ajaxReady=true;jxeeno.fileman.loadData()})}}},download:function(e){var i=jxeeno.fileman.path.replace(/^#/,"");var j=e;window.open("/local--files/"+i+"/"+j,"_blank")},uploadInternal:function(e,l){var k=e;var j=l[e];OZONE.ajax.requestModule("Empty",{filename:j.name,action:"FileAction",event:"checkFileExists",pageId:jxeeno.fileman.curPageID},function(i){var n=true;if(i.exists){n=confirm("Oh no, it appears that "+j.name+" already exists!\n\rAre you sure you want to overwrite this file?")}if(!n){jxeeno.fileman.tmp.completedUploads++;a(".fileman-upload-uploading").text(jxeeno.fileman.tmp.completedUploads+1);a(".fileman-upload-percentage").text(Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100));a("#fileman-upload-progress-bar").css({width:Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100)+"%"});if(jxeeno.fileman.tmp.totalUploads==jxeeno.fileman.tmp.completedUploads){a("#fileman-upload-loading").fadeOut(function(){a("#file-upload-form").fadeIn()});jxeeno.ajaxReady=true;jxeeno.fileman.loadData()}else{jxeeno.fileman.uploadInternal(e+1,l)}return}else{var m=new FormData();m.append("action","FileAction");m.append("event","uploadFile");m.append("page_id",jxeeno.fileman.curPageID);m.append("MAX_FILE_SIZE","209715200");m.append("userfile",j);m.append("dfilename","");m.append("comments","");if(i.exists){m.append("force","true")}a.ajax({xhr:function(){var o=new window.XMLHttpRequest();o.upload.addEventListener("progress",function(p){if(p.lengthComputable){var r=p.loaded/p.total;var q=Math.ceil(((jxeeno.fileman.tmp.completedUploads+r)/jxeeno.fileman.tmp.totalUploads)*100);a(".fileman-upload-percentage").text(q);a("#fileman-upload-progress-bar").css({width:q+"%"})}},false);return o},url:"/default--flow/files__UploadTarget",data:m,cache:false,contentType:false,processData:false,type:"POST",success:function(o){if(o.match(/fileUploaded\("ok"/)){jxeeno.fileman.tmp.completedUploads++;a(".fileman-upload-uploading").text(jxeeno.fileman.tmp.completedUploads+1);a(".fileman-upload-percentage").text(Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100));a("#fileman-upload-progress-bar").css({width:Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100)+"%"});if(jxeeno.fileman.tmp.totalUploads==jxeeno.fileman.tmp.completedUploads){a("#fileman-upload-loading").fadeOut(function(){a("#file-upload-form").fadeIn()});a("#fileman-upload-file").val("");jxeeno.ajaxReady=true;jxeeno.fileman.loadData()}else{jxeeno.fileman.uploadInternal(e+1,l)}}else{alert(j.name+" could not be uploaded because of an unknown error!");jxeeno.fileman.tmp.completedUploads++;a(".fileman-upload-uploading").text(jxeeno.fileman.tmp.completedUploads+1);a(".fileman-upload-percentage").text(Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100));a("#fileman-upload-progress-bar").css({width:Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100)+"%"});if(jxeeno.fileman.tmp.totalUploads==jxeeno.fileman.tmp.completedUploads){a("#fileman-upload-loading").fadeOut(function(){a("#file-upload-form").fadeIn()});jxeeno.ajaxReady=true;jxeeno.fileman.loadData()}else{jxeeno.fileman.uploadInternal(e+1,l)}return}}})}})},upload:function(){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;a("#file-upload-form").hide();a("#fileman-upload-loading").fadeIn();if(a("#fileman-upload-file").val()==""){return}jxeeno.fileman.tmp.totalUploads=a("#fileman-upload-file")[0].files.length;jxeeno.fileman.tmp.completedUploads=0;a(".fileman-upload-count").text(jxeeno.fileman.tmp.totalUploads);a(".fileman-upload-uploading").text(jxeeno.fileman.tmp.completedUploads+1);a(".fileman-upload-percentage").text(Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100));a("#fileman-upload-progress-bar").css({width:Math.ceil((jxeeno.fileman.tmp.completedUploads/jxeeno.fileman.tmp.totalUploads)*100)+"%"});jxeeno.fileman.uploadInternal(0,a("#fileman-upload-file")[0].files)}}};var b="<h1>File Manager</h1>";b+='<div class="row-fluid">';b+='<div class="span3">';b+="    <h3>Categories</h3>";b+='    <div class="input-append">';b+='        <input type="text" class="text span12" onkeyup="jxeeno.fileman.search(\'category\',this.value);" placeholder="Filter" />';b+='        <button class="btn" type="button" onclick="jxeeno.fileman.searchClear(\'category\',this);">&times;</button>';b+="    </div>";b+='    <div class="" id="fileman-category-list">';b+="";b+="    </div>";b+="";b+="</div>";b+='<div class="span3">';b+="    <h3>Pages</h3>";b+='    <div class="input-append">';b+='        <input type="text" class="text span12" onkeyup="jxeeno.fileman.search(\'page\',this.value);" placeholder="Filter" />';b+='        <button class="btn" type="button" onclick="jxeeno.fileman.searchClear(\'page\',this);">&times;</button>';b+="    </div>";b+='    <div class="" id="fileman-page-list">';b+="    </div>";b+="</div>";b+='<div class="span6">';b+="    <h3>Files</h3>";b+='    <div class="" id="fileman-file-list">';b+="    </div>";b+=' <div id="fileman-upload-block">';b+="        <h3>Upload Files</h3>";b+="        <i>Select one or more files to upload.</i>";b+='        <form id="file-upload-form" enctype="multipart/form-data" action="/default--flow/files__UploadTarget" target="_upload_iframe" method="POST">';b+='            <input class="text" id="fileman-upload-file" name="userfile" type="file" multiple="multiple" />';b+="            <br /><br />";b+='            <input type="button" class="btn" value="Upload" onclick="jxeeno.fileman.upload()">';b+="        </form>";b+='        <div id="fileman-upload-loading" style="display: none;">';b+='            Uploading <span class="fileman-upload-uploading">0</span> of <span class="fileman-upload-count">0</span> files (<span class="fileman-upload-percentage">0</span>%)';b+='            <div class="progress progress-striped active">';b+='                <div class="bar" id="fileman-upload-progress-bar" style="width: 0%"></div>';b+="            </div>";b+="        </div>";b+="    </div>";b+="</div>";b+="</div>";f.html(b);var d=a("#fileman-upload-block")[0];d.ondragover=d.ondragenter=function(i){i.preventDefault();i.dataTransfer.dropEffect="copy";return false};d.ondragleave=d.ondragexit=d.ondragend=function(i){};d.ondrop=function(i){a("#fileman-upload-file")[0].files=i.dataTransfer.files;return false};jxeeno.fileman.loadData("#")};a.jxeenoMD=function(g,c){var d=a(g),f=d[0];if(typeof(c)!="string"){c="true"}if(!c){return}if(window.jxeeno==undefined){window.jxeeno={}}jxeeno=window.jxeeno;if(typeof(jxeeno.ajaxReady)=="undefined"){jxeeno.ajaxReady=true}jxeeno.utils={massdelete:{}};jxeeno.utils.massdelete.loadingHTML='<img src="../common--images/301.gif" style="margin: 0 auto;">';jxeeno.utils.massdelete.confirm=function(){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;if(a.trim(document.getElementById("page-list").value)==""){alert("Whoops!  You haven't entered any pages to delete!");jxeeno.ajaxReady=true;return}var e=a.trim(document.getElementById("page-list").value.replace("\r","\n")).split("\n");if(confirm("Are you REALLY sure you want to delete "+e.length+" pages?")){a("#md-progress").slideDown();a("#md-settings").slideUp();jxeeno.utils.massdelete.internal(0,e)}else{jxeeno.ajaxReady=true}}};jxeeno.utils.massdelete.internal=function(e,h){if(e<h.length){a.get("/"+h[e]+"/noredirect/true/norender/true",function(i){if(i.match(/WIKIREQUEST\.info\.pageId = ([0-9]+);/)){pageid=i.match(/WIKIREQUEST\.info\.pageId = ([0-9]+);/)[1];var j={action:"WikiPageAction",event:"deletePage",page_id:pageid};OZONE.ajax.requestModule("Empty",j,function(k){a(".md-count").text(h.length);a(".md-completed").text(e+1);a(".md-percentage").text(Math.ceil(((e+1)/h.length)*100));a("#md-progress-bar").css({width:Math.ceil(((e+1)/h.length)*100)+"%"});jxeeno.utils.massdelete.internal(e+1,h)})}else{alert("Unknown error with "+h[e]+"! Page is not formatted correctly.");a(".md-count").text(h.length);a(".md-completed").text(e+1);a(".md-percentage").text(Math.ceil(((e+1)/h.length)*100));a("#md-progress-bar").css({width:Math.ceil(((e+1)/h.length)*100)+"%"})}}).error(function(){alert("Error! Could not delete "+h[e]+"! Page does not exist.");jxeeno.utils.massdelete.internal(e+1,h);a(".md-count").text(h.length);a(".md-completed").text(e+1);a(".md-percentage").text(Math.ceil(((e+1)/h.length)*100));a("#md-progress-bar").css({width:Math.ceil(((e+1)/h.length)*100)+"%"})})}else{a("#md-settings").slideDown();a("#md-progress").slideUp();a("#md-info").fadeIn();alert("Task Complete: "+h.length+" pages have been deleted from "+WIKIREQUEST.info.domain);jxeeno.ajaxReady=true;WIKIDOT.modules.ManagerSiteModule.utils.loadModule("sm-massdelete")}};jxeeno.utils.massdelete.count=function(){if(a.trim(document.getElementById("page-list").value)==""){a(".md-count").text(0);return}var e=a.trim(document.getElementById("page-list").value.replace("\r","\n")).split("\n");a(".md-count").text(e.length)};jxeeno.utils.massdelete.getCategories=function(){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;OZONE.ajax.requestModule("list/WikiCategoriesModule",{},function(e){jxeeno.utils.massdelete.categoryObj={};a("<div />").html(e.body).find("div[id^=category-pages]").parent().each(function(){var i=a(this).find("h3").text().toLowerCase();var h=a(this).find("div").attr("id").match(/^category\-pages\-([0-9]+)$/)[1];jxeeno.utils.massdelete.categoryObj[i]=h;a("select#category-list").append('<option value="'+i+'">'+i+"</option>")});jxeeno.ajaxReady=true})}};jxeeno.utils.massdelete.category=function(h){if(jxeeno.ajaxReady){jxeeno.ajaxReady=false;if(typeof(h)=="undefined"){h=a("select#category-list").val()}a("#md-autofill-content").hide();a("#md-autofill-loading").show();var e="";var i={limit:"999999",perPage:"250",category:h,module_body:"%%title_linked%%",separate:"no",pagetype:a("#md-pagetype").val()};if(a.trim(a("#md-tags").val())!=""){i.tags=a.trim(a("#md-tags").val())}OZONE.ajax.requestModule("list/ListPagesModule",i,function(m){var l=function(){a("#page-list").val(a.trim(e));jxeeno.utils.massdelete.count();a("#md-autofill-content").show();a("#md-autofill-loading").hide();jxeeno.ajaxReady=true};var k=function(p,n){if(p>n){l();return}var o=i;o.p=p;OZONE.ajax.requestModule("list/ListPagesModule",o,function(q){a(q.body).find("a").each(function(s,t){if(!a(t).parent().hasClass("target")){var r=a(t).attr("href").replace(/^\//,"");e+=r+"\n"}});k(p+1,n)})};a(m.body).find("a").each(function(o,p){if(!a(p).parent().hasClass("target")){var n=a(p).attr("href").replace(/^\//,"");e+=n+"\n"}});if(a(m.body).find(".pager").length>0){var j=a(m.body).find(".pager .pager-no").text().match(/page [0-9]+ of ([0-9]+)/);k(2,(j[1]*1))}else{l()}})}};var b='<div class="massdeletetable"><h1>Mass Delete Tool</h1>';b+='<div class="row-fluid"><div class="span6">';b+="The Mass Delete tool allows administrators to rapidly and effeciently <b>permanently</b> delete a large number of Wikidot pages.";b+="This can be an extremely deadly piece of software and all actions performed here are irreversible.";b+='</div><div class="span6">';b+="Because of the amount of destruction this piece of software can cause, there are a couple of requirements for using this script:";b+="<ul><li>You must be an admin of the site</li>";b+="</ul>";b+="</div></div>";b+='<div class="row-fluid" id="md-settings">';b+=' <div class="span6">';b+="     <h2>List of pages</h2>";b+='  <textarea id="page-list" onkeyup="jxeeno.utils.massdelete.count()" style="width: 100%; height: 200px;"></textarea>';b+='  <div style="font-size: 80%;">A new-line separated list of pages for deletion</div>';b+=" </div>";b+=' <div class="span6">';b+='  <div id="md-autofill-content">';b+="      <h2>Autofill</h2>";b+="   <div>This will fill the textbox on the left with pages under your criteria set below:</div>";b+='   <form class="form-horizontal" action="javascript:;" onsubmit="jxeeno.utils.massdelete.category();">';b+='    <div class="control-group"><label class="control-label" for="md-pagetype">Pagetype:</label><div class="controls"><select id="md-pagetype"><option value="*">All</option><option value="normal">normal</option><option value="hidden">hidden</option></select></div></div>';b+='    <div class="control-group"><label class="control-label" for="md-tags">Tags:</label><div class="controls"><input id="md-tags" type="text" placeholder="ListPages tags selector" style="width: 100%;" /></div></div>';b+='    <div class="control-group"><label class="control-label" for="category-list">Category:</label><div class="controls"><select id="category-list"></select></div></div>';b+='    <div class="control-group"><div class="controls"><button type="submit" class="btn">Fill pages</button></div></div>';b+="   </form>";b+='   <div style="font-size: 80%;">N.B. Autofill clears and replaces previous data in list</div>';b+="  </div>";b+='  <div id="md-autofill-loading" style="display: none;">'+jxeeno.utils.massdelete.loadingHTML+"</div>";b+=" </div>";b+="</div>";b+='<div class="alert alert-info">';b+='    <p>By proceeding with the delete process, you understand that you alone are responsible for the <strong>permanent and irreversible</strong> removal of <span class="md-count">0</span> pages on your site.</p>';b+="    <p>We recommend you creating a backup your Wikidot site (search 'Backup' in the Admin Panel) so that you can recover your pages in the case of unintentional deletion</p>";b+="</div>";b+='    <label class="checkbox"><input type="checkbox" onclick="jQuery(this).is(\':checked\') ? jQuery(\'#md-activate\').fadeIn() : jQuery(\'#md-activate\').fadeOut();"><span class="helper">I understand the risks associated and have recently created a backup in case of accidental page deletion</span></label>';b+=' <br /><div style="text-align: right;"><input type="submit" class="btn" value="Delete pages" id="md-activate" onclick="jxeeno.utils.massdelete.confirm();" style="display: none;" /></div>';b+='<table style="width: 100%;"><tr><td>';b+='<div id="md-progress" style="display: none;">';b+="    <h2>Progress</h2>";b+='    <span class="md-completed">0</span> of <span class="md-count">0</span> pages completed (<span class="md-percentage">0</span>%)';b+='    <div class="progress progress-striped active">';b+='    <div class="bar" id="md-progress-bar" style="width: 0%"></div>';b+="    </div>";b+="</div>";b+="</td></tr></table></div>";d.html(b);jxeeno.utils.massdelete.getCategories()}})(jQuery);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License