FANDOM


//
/*
 Rangy Text Inputs, a cross-browser textarea and text input library plug-in for jQuery.
 
 Part of Rangy, a cross-browser JavaScript range and selection library
 http://code.google.com/p/rangy/
 
 Depends on jQuery 1.0 or later.
 
 Copyright 2010, Tim Down
 Licensed under the MIT license.
 Version: 0.1.205
 Build date: 5 November 2010
*/
(function(n){function o(e,g){var a=typeof e[g];return a==="function"||!!(a=="object"&&e[g])||a=="unknown"}function p(e,g,a){if(g<0)g+=e.value.length;if(typeof a=="undefined")a=g;if(a<0)a+=e.value.length;return{start:g,end:a}}function k(){return typeof document.body=="object"&&document.body?document.body:document.getElementsByTagName("body")[0]}var i,h,q,l,r,s,t,u,m;n(document).ready(function(){function e(a,b){return function(){var c=this.jquery?this[0]:this,d=c.nodeName.toLowerCase();if(c.nodeType==
1&&(d=="textarea"||d=="input"&&c.type=="text")){c=[c].concat(Array.prototype.slice.call(arguments));c=a.apply(this,c);if(!b)return c}if(b)return this}}var g=document.createElement("textarea");k().appendChild(g);if(typeof g.selectionStart!="undefined"&&typeof g.selectionEnd!="undefined"){i=function(a){return{start:a.selectionStart,end:a.selectionEnd,length:a.selectionEnd-a.selectionStart,text:a.value.slice(a.selectionStart,a.selectionEnd)}};h=function(a,b,c){b=p(a,b,c);a.selectionStart=b.start;a.selectionEnd=
b.end};m=function(a,b){if(b)a.selectionEnd=a.selectionStart;else a.selectionStart=a.selectionEnd}}else if(o(g,"createTextRange")&&typeof document.selection=="object"&&document.selection&&o(document.selection,"createRange")){i=function(a){var b=0,c=0,d,f,j;if((j=document.selection.createRange())&&j.parentElement()==a){f=a.value.length;d=a.value.replace(/\r\n/g,"\n");c=a.createTextRange();c.moveToBookmark(j.getBookmark());j=a.createTextRange();j.collapse(false);if(c.compareEndPoints("StartToEnd",j)>
-1)b=c=f;else{b=-c.moveStart("character",-f);b+=d.slice(0,b).split("\n").length-1;if(c.compareEndPoints("EndToEnd",j)>-1)c=f;else{c=-c.moveEnd("character",-f);c+=d.slice(0,c).split("\n").length-1}}}return{start:b,end:c,length:c-b,text:a.value.slice(b,c)}};h=function(a,b,c){b=p(a,b,c);c=a.createTextRange();var d=b.start-(a.value.slice(0,b.start).split("\r\n").length-1);c.collapse(true);if(b.start==b.end)c.move("character",d);else{c.moveEnd("character",b.end-(a.value.slice(0,b.end).split("\r\n").length-
1));c.moveStart("character",d)}c.select()};m=function(a,b){var c=document.selection.createRange();c.collapse(b);c.select()}}else{k().removeChild(g);window.console&&window.console.log&&window.console.log("TextInputs module for Rangy not supported in your browser. Reason: No means of finding text input caret position");return}k().removeChild(g);l=function(a,b,c,d){var f;if(b!=c){f=a.value;a.value=f.slice(0,b)+f.slice(c)}d&&h(a,b,b)};q=function(a){var b=i(a);l(a,b.start,b.end,true)};u=function(a){var b=
i(a),c;if(b.start!=b.end){c=a.value;a.value=c.slice(0,b.start)+c.slice(b.end)}h(a,b.start,b.start);return b.text};r=function(a,b,c,d){var f=a.value;a.value=f.slice(0,c)+b+f.slice(c);if(d){b=c+b.length;h(a,b,b)}};s=function(a,b){var c=i(a),d=a.value;a.value=d.slice(0,c.start)+b+d.slice(c.end);c=c.start+b.length;h(a,c,c)};t=function(a,b,c){var d=i(a),f=a.value;a.value=f.slice(0,d.start)+b+d.text+c+f.slice(d.end);b=d.start+b.length;h(a,b,b+d.length)};n.fn.extend({getSelection:e(i,false),setSelection:e(h,
true),collapseSelection:e(m,true),deleteSelectedText:e(q,true),deleteText:e(l,true),extractSelectedText:e(u,false),insertText:e(r,true),replaceMatchText:e(s,true),surroundSelectedText:e(t,true)})})})(jQuery);
 
var FindReplace = function () {
 
    function loadModules () {
        this.Shadow.load();
    }
 
    return  {
        load: loadModules
    };
}();
 
FindReplace.Shadow = function (namespace) {
 
    function loadShadow () {
 
        module.textarea = $('textarea#wpTextbox1');
        module.textarea.after('<div id="fr-shadow"></div>');
        module.shadow = $('#fr-shadow');
 
        var commonCSS = {
            width: '100%', left: 0, top: 0, border: '0 none', display: 'block',
            height: $(window).height() - module.textarea.offset().top - $('.toolbar').height() + 'px',
            fontFamily: 'Consolas,"Eupheima UCAS",Ayuthaya,Menlo,monospace',
            fontSize: '13.5px', outline: 'medium none', margin: 0, padding: 0, resize: 'none'
        };
 
        module.textarea.css(commonCSS).css({
            position: 'relative', zIndex: '1',
            backgroundColor: 'transparent'
        });
 
        module.shadow.css(commonCSS).css({
            position: 'absolute', zIndex: '0',
            whiteSpace: 'pre-wrap',
            backgroundColor: 'transparent',
            color: 'transparent'
        });
 
        module.textarea.keyup (synchShadow);
        module.textarea.click (synchShadow);
        synchShadow();
        module.textarea.focus();
 
        while (callback = module.ready.pop()) callback();
    }
 
    function synchShadow () {
        findMatches();
        //console.log(module.matches);
        module.shadow.html(function () {
            var s = module.textarea.val();
            var r = '';
            for (var i = 0, start = 0; i < module.matches.length; i++) {
                //console.log('start %u, index %u, s[start->index] %s', start, module.matches[i].index,  s.substr(start, module.matches[i].index - start));
                r += s.substr(start, module.matches[i].index - start);
                //console.log('moving start %u', module.matches[i].index + module.matches[i].term.length);
                start = module.matches[i].index + module.matches[i].term.length;
                r += '<span id="m' + i + '" style="background-color: #700066;">' + module.matches[i].term + '</span>';
            }
            return r.length ? r : s;
        });
    }
 
    var regex;
 
    function findMatches () {
        module.matches = [];
        var regex = getRegex();
        if (regex instanceof RegExp) {
            var s = module.textarea.val();
            regex.lastIndex = 0;
            while (m = regex.exec(s)) {
                module.matches.push({
                    term: m[0], index: m.index
                })
                regex.lastIndex = m.index + m[0].length;
            }
        }
    }
 
    function setRegex (newRegex) {
        regex = newRegex;
        synchShadow();
    }
 
    function getRegex () {
        return regex;
    }
 
    //function highlightAllMatches () {}
    //function selectMatch (match) {}
    //function replaceMatch (replacement) {}
    //function replaceAllMatches (replacement) {}
    //function removeHighlights () {}
    //function unloadShadow () {}
 
    var module = {
 
        ready: [],
 
        //regex: null,
        matches: [],
        current: -1,
 
        textarea: null,
        shadow: null,
 
        load: loadShadow,
        init: setRegex
        //unload: unloadShadow,
        //init: initMatches,
        //reset: resetMatches
        //init: initMatching
        //highlight: highlightAllMatches,
        //dim: removeHighlights,
        //select: selectMatch,
        //replace: replaceMatch,
        //replaceAll: replaceAllMatches
    };
    return module;
 
}(FindReplace);
 
//$.getScript('/index.php?title=textinputs_jquery.js&action=raw&ctype=text/html&usemsgcache=yes&maxage=86400');
 
$(function () {
    if ('edit' != $.getUrlVar('action')) return;
    FindReplace.load();
});
//

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.