2014-04-02 09:37:13 +00:00
|
|
|
( function ( $, mw ) {
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* @class mw.popups
|
|
|
|
* @singleton
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups = {};
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* Checks SVG support on the browser
|
|
|
|
* @property {Boolean} supportsSVG
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.supportsSVG = document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' );
|
2014-02-11 09:48:00 +00:00
|
|
|
|
2014-04-22 14:16:54 +00:00
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* The API object used for all this extension's requests
|
|
|
|
* @property {Object} api
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.api = new mw.Api();
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* Whether the page is being scrolled.
|
|
|
|
* @property {Boolean} scrolled
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.scrolled = false;
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* List of classes of which links are ignored
|
|
|
|
* @property {Array} IGNORE_CLASSES
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.IGNORE_CLASSES = [
|
2014-05-19 22:30:29 +00:00
|
|
|
'.extiw',
|
2014-04-25 11:43:42 +00:00
|
|
|
'.image',
|
|
|
|
'.new',
|
|
|
|
'.internal'
|
|
|
|
];
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* If SVG is supported, creates the SVG mask used to create the
|
|
|
|
* the triangle pointer on popups with images
|
|
|
|
*
|
|
|
|
* @method createSVGMask
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.createSVGMask = function () {
|
|
|
|
if ( !mw.popups.supportsSVG ) {
|
2014-04-22 14:16:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-11 09:48:00 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
$( '<div>' )
|
|
|
|
.attr( 'id', 'mwe-popups-svg' )
|
|
|
|
.appendTo( document.body )
|
|
|
|
.html(
|
|
|
|
'<svg width="0" height="0">' +
|
|
|
|
'<defs>' +
|
|
|
|
'<clippath id="mwe-popups-mask">' +
|
|
|
|
'<polygon points="0 8, 10 8, 18 0, 26 8, 1000 8, 1000 1000, 0 1000"/>' +
|
|
|
|
'</clippath>' +
|
|
|
|
'<clippath id="mwe-popups-mask-flip">' +
|
|
|
|
'<polygon points="0 8, 274 8, 282 0, 290 8, 1000 8, 1000 1000, 0 1000"/>' +
|
|
|
|
'</clippath>' +
|
|
|
|
'<clippath id="mwe-popups-landscape-mask">' +
|
|
|
|
'<polygon points="0 8, 174 8, 182 0, 190 8, 1000 8, 1000 1000, 0 1000"/>' +
|
|
|
|
'</clippath>' +
|
2014-04-30 11:13:05 +00:00
|
|
|
'<clippath id="mwe-popups-landscape-mask-flip">' +
|
|
|
|
'<polygon points="0 0, 1000 0, 1000 243, 190 243, 182 250, 174 243, 0 243"/>' +
|
|
|
|
'</clippath>' +
|
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
'</defs>' +
|
|
|
|
'</svg>'
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
};
|
2014-04-22 14:16:54 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-25 11:43:42 +00:00
|
|
|
* Create the element that holds the popups
|
|
|
|
*
|
|
|
|
* @method createPopupElement
|
2014-04-22 14:16:54 +00:00
|
|
|
*/
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.createPopupElement = function () {
|
|
|
|
mw.popups.$popup = $( '<div>' )
|
2014-04-22 14:16:54 +00:00
|
|
|
.attr( 'role', 'tooltip' )
|
2014-04-25 11:43:42 +00:00
|
|
|
.attr( 'aria-hidden', 'true' )
|
2014-04-22 14:16:54 +00:00
|
|
|
.addClass( 'mwe-popups' )
|
|
|
|
.appendTo( document.body );
|
2014-04-25 11:43:42 +00:00
|
|
|
};
|
2014-02-11 09:48:00 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
/**
|
|
|
|
* Temorarily remove tooltips from links on hover
|
|
|
|
*
|
|
|
|
* @method removeTooltips
|
|
|
|
*/
|
|
|
|
mw.popups.removeTooltips = function () {
|
|
|
|
var notSelector = ':not(' + mw.popups.IGNORE_CLASSES.join(', ') + ')';
|
|
|
|
mw.popups.$content.find( 'a' + notSelector + ':not([title=""])' )
|
2014-03-23 02:32:37 +00:00
|
|
|
.on( 'mouseenter focus', function () {
|
|
|
|
$( this )
|
2014-04-25 11:43:42 +00:00
|
|
|
.data( 'title', $( this ).attr( 'title' ) )
|
2014-04-02 09:37:13 +00:00
|
|
|
.attr( 'title', '' );
|
2014-03-23 02:32:37 +00:00
|
|
|
} )
|
|
|
|
.on( 'mouseleave blur', function () {
|
|
|
|
$( this )
|
2014-04-25 11:43:42 +00:00
|
|
|
.attr( 'title', $( this ).data( 'title' ) );
|
2014-03-23 02:32:37 +00:00
|
|
|
} );
|
2014-04-25 11:43:42 +00:00
|
|
|
};
|
2014-02-06 11:15:05 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
/**
|
|
|
|
* Checks if the user is scrolling, sets to false on mousemove
|
|
|
|
*
|
|
|
|
* @method checkScroll
|
|
|
|
*/
|
|
|
|
mw.popups.checkScroll = function () {
|
|
|
|
$( window ).on( 'scroll', function () {
|
|
|
|
mw.popups.scrolled = true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( window ).on( 'mousemove', function () {
|
|
|
|
mw.popups.scrolled = false;
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the hover event on links
|
|
|
|
*
|
|
|
|
* @method setupTriggers
|
|
|
|
*/
|
|
|
|
mw.popups.setupTriggers = function () {
|
|
|
|
var notSelector = ':not(' + mw.popups.IGNORE_CLASSES.join(', ') + ')';
|
|
|
|
|
|
|
|
mw.popups.$content.find( 'a' + notSelector + ':not([title=""])' ).on( 'mouseenter focus', function ( event ) {
|
|
|
|
var
|
|
|
|
$this = $( this ),
|
|
|
|
href = $this.attr( 'href' );
|
2014-02-06 10:49:28 +00:00
|
|
|
|
2014-04-03 21:54:56 +00:00
|
|
|
if (
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.scrolled || // Prevents hovering on popups while scrolling
|
2014-02-06 10:49:28 +00:00
|
|
|
href.indexOf( '?' ) !== -1 ||
|
|
|
|
href.indexOf( location.origin + location.pathname + '#' ) === 0
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.popups.render.render( $this, event );
|
|
|
|
} );
|
|
|
|
};
|
2014-02-06 10:49:28 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
mw.hook( 'wikipage.content').add( function ( $content ) {
|
|
|
|
mw.popups.$content = $content;
|
|
|
|
mw.popups.removeTooltips();
|
|
|
|
mw.popups.setupTriggers();
|
|
|
|
} );
|
2014-02-06 10:49:28 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
$( function () {
|
|
|
|
mw.popups.checkScroll();
|
|
|
|
mw.popups.createSVGMask();
|
|
|
|
mw.popups.createPopupElement();
|
2014-02-06 10:49:28 +00:00
|
|
|
} );
|
2014-02-07 07:35:34 +00:00
|
|
|
|
2014-04-25 11:43:42 +00:00
|
|
|
} ) ( jQuery, mediaWiki );
|