User:KenSWebb/monobook.js

// This script replaces PNG/GIF/JPG with SVG images in a wikipedia article, // when an SVG image is available. // It currently works correctly with some pages, but not with others, // although it's only been tested with a few articles. // It works to varying degrees with Firefox 3.6, Opera, and Chrome 14. // This is only an initial version for experimentation. // Some pages that it does work with are: //  [] //  [] //  []

function outerFunction { resizeSvg = function resizeSvg { $('.thumbinner object').each(function {     var w = $(this)[0].clientWidth;      var thumbinner = $(this).parent;      thumbinner.css("width",w);    }); }; function replaceWithSvg { $('.thumbinner .image > img').each(function(index){     var src = $(this).attr('src');      var pos = src.indexOf('.svg');      if (pos != -1) {        var svgUrl = src.substring(0, pos+4);        svgUrl = svgUrl.replace(/thumb\//, '');        if (svgUrl.charAt(0) == '/') {          svgUrl = "http:" + svgUrl;        };        svgUrl = "http://www.primordion.com/Xholon/wikEdition/proxyBA.php?url=" + svgUrl;        var a = $(this).parent;        var newHtml = " ";        a.replaceWith(newHtml);      }    }); }; function makeContentEditable { $('span.texhtml').each(function{     $(this).attr('contenteditable','true');    }); }; // will only work for the Addition article updateSvg = function updateSvg(term1, term2, sum) { var svgdoc = null; var object = document.getElementById('svg2'); if (object.contentDocument) svgdoc = object.contentDocument; else { try { svgdoc = object.getSVGDocument; }     catch(exception) {} }   var text6 = svgdoc.getElementById('text6'); var text8 = svgdoc.getElementById('text8'); var text12 = svgdoc.getElementById('text12'); text6.firstChild.nodeValue = term1; text8.firstChild.nodeValue = term2; text12.firstChild.nodeValue = sum; }; function handleEvents { $('[contenteditable]').live('focus', function {     var $this = $(this);      $this.data('before', $this.html);      return $this;    }).live('blur', function {      var $this = $(this);      if ($this.data('before') !== $this.html) {          $this.data('before', $this.html);          $this.trigger('change');      }      return $this;    }).live('change', function {      var $this = $(this);      var a = $this.data('before').split(' ');      if (wgPageName == "Addition") {        updateSvg(a[0], a[2], a[4]);      }      return $this;    }); }; replaceWithSvg; makeContentEditable; handleEvents; }; $(outerFunction);