משתמש:קיפודנחש/hoverShowIntro.js

מתוך ויקיפדיה, האנציקלופדיה החופשית

הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר / אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: ללחוץ על Ctrl-F5.
if (wgAction == 'view' && ! mw.user.options.get('gadget-popup'))
mw.loader.using(['jquery.tipsy', 'mediawiki.api'], function() {
	var
        gravity = function() {
            var loc =
                ($(this).offset().top > ($(document).scrollTop() + $(window).height() - 120) ? 's' : 'n') +
                ($(this).offset().left > ($(document).scrollLeft() + $(window).width() / 4) ? '' : 'w');
            return loc;
        },
        api = new mw.Api(),
        mouseLeft = function() { $(this).data('mouseLeft', true); },
		createHint = function() {
            var $this = $(this);
                
            if ($this.data('beenHere')) // we only need to set tipsy once per link.
                return;
            $this.data('beenHere', true); 
            
            api.get(
                {prop: 'extracts', exchars: 640, exintro: 1, exsectionformat: 'plain', titles: $this.attr('title')}, 
                function(data) {
                    var content;
                    if (data && data.query && data.query.pages)
                        for (var p in data.query.pages) 
                            content = data.query.pages[p].extract;
                    if (content) 
                        $this.tipsy({
                            html: true, 
                            delayOut: 500, 
                            delayIn: 300, 
                            fade: true, 
                            opacity: 1, 
                            gravity: gravity, 
                            title: function() { return content; }
                        });
                    if (! $this.data('mouseLeft')) // if mouse still over element, tipsy won't trigger for the first time.
                        $this.trigger('mouseenter');
                }
            );
        } 
        
	$(function() {$('a[href^="/wiki/"]:not([class]), a.stub', mw.util.$content).hover(createHint, mouseLeft);});
});