User:Emma/common.js: Difference between revisions

Want an adless experience? Log in or Create an account.
Didn't work right, replaced with another test.
m (Testing script)
(Didn't work right, replaced with another test.)
Line 51: Line 51:
} );
} );


$(document).ready(function() {
$( function($) {
  $('body').append('<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999"></div>');
    if((wgNamespaceNumber != 0) && (wgNamespaceNumber != 2)) {
  $('a.image').click(function(e) {
        // only check links in mainspace and userspace (for userspace drafts)
    e.preventDefault();
        return;
      if ($(this).find('img').attr('src').match('/thumb/')) {
    }
      var src = 'http:' + $(this).find('img').attr('src').replace('/thumb','').replace(/\/[\-_.%\w]*$/, '');
    var portletlink = mw.util.addPortletLink('p-tb', '#', 'Highlight duplicate links', 'ca-findduplicatelinks');
      } else {
    $(portletlink).click( function(e) {
        var src = $(this).find('img').attr('src');
        e.preventDefault();
      }
        // create a separate div surrounding the lead
    $('#lightbox')
        // first get the element immediately surrounding the article text. Unfortunately, MW doesn't seem to provide a non-fragile way for that.
      .html('<img src="'+src+'" style="background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />')
        var content = ".mw-content-ltr";
      .css('line-height', $(window).height()+'px')
        $(content).prepend(document.createElement('div'));
      .fadeIn('fast')
        var lead = $(content).children()[0];
      .live('click', function() {
        $(lead).attr('id', 'lead');
         $(this).fadeOut('fast');
        $(content).children().each( function() {
            if(this.nodeName.toLowerCase() == 'h2') {
                return false;
            }
            if($(this).attr('id') != 'lead') {
                $(lead).append(this);
            }
            return true;
        });
     
        // detect duplicate links
        mw.util.addCSS(".duplicate-link { border: 1px solid red; }");
        var finddups = function() {
            var href = $(this).attr('href');
            if(href != undefined && href.indexOf('#') != 0) {
                if(seen[href]) {
                    $(this).addClass("duplicate-link");
                }
                else {
                    seen[href] = true;
                }
            }
            return true;
        };
        // array to keep track of whether we've seen a link before
        var seen = [];
        mw.util.$content.find('p a').not('#lead *, .infobox *, .navbox *').each(finddups);
        var seen = [];
         mw.util.$content.find('#lead p a').not('.infobox *, .navbox *').each(finddups);
     });
     });
  });
});
});