|
|
| (4 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| // Twinkle mobile TEST adapter v2 - sirf personal test ke liye | | // Twinkle mobile support is now site-wide via the Twinkle gadget (MediaWiki:Gadget-TwinkleMobile.js). This personal test page is no longer needed. |
| // Jagah: User:Bharatwiki Socrates/minerva.js (sirf Minerva skin me chalega)
| |
| // v1 se seekh: files load ho jati hain, lekin Twinkle ka menu Minerva me
| |
| // kahin dikhai nahi deta, kyunki Minerva me #p-cactions hota hi nahi.
| |
| // Iska overflow (More) menu asal me portlet #p-tb hai.
| |
| // v2 ka kaam: Twinkle ke bane menu ko dhoondh kar use ek panel me rakhna
| |
| // aur More menu (ul#p-tb) me "Twinkle" naam ki entry jodna, jise dabane
| |
| // par woh panel khule. Sath me diagnostic notification bhi aayegi ki
| |
| // menu mila ya nahi, aur kis naam se mila.
| |
| | |
| ( function () {
| |
| if ( mw.config.get( 'skin' ) !== 'minerva' ) {
| |
| return;
| |
| }
| |
| if ( window.twinkleMobileTestLoaded ) {
| |
| return;
| |
| }
| |
| window.twinkleMobileTestLoaded = true;
| |
| | |
| var indexPhp = mw.util.wikiScript( 'index' );
| |
| function rawUrl( title ) {
| |
| return indexPhp + '?title=' + encodeURIComponent( title ) +
| |
| '&action=raw&ctype=text/javascript';
| |
| }
| |
| function rawCss( title ) {
| |
| var link = document.createElement( 'link' );
| |
| link.rel = 'stylesheet';
| |
| link.href = indexPhp + '?title=' + encodeURIComponent( title ) +
| |
| '&action=raw&ctype=text/css';
| |
| document.head.appendChild( link );
| |
| }
| |
| function loadScript( title ) {
| |
| return $.getScript( rawUrl( title ) );
| |
| }
| |
| | |
| mw.util.addCSS(
| |
| '.ui-dialog { max-width: 96vw !important; left: 2vw !important; }' +
| |
| '.morebits-dialog { max-width: 96vw !important; }' +
| |
| '.morebits-dialog-content { overflow-x: auto; }' +
| |
| '.select2-container { max-width: 90vw; }' +
| |
| '#twinkle-mobile-panel { position: fixed; top: 56px; left: 2vw;' +
| |
| ' width: 96vw; max-height: 70vh; overflow-y: auto; z-index: 999;' +
| |
| ' background: #fff; border: 1px solid #a2a9b1; border-radius: 4px;' +
| |
| ' box-shadow: 0 4px 16px rgba(0,0,0,0.3); padding: 6px 0; }' +
| |
| '#twinkle-mobile-panel ul { list-style: none; margin: 0; padding: 0; }' +
| |
| '#twinkle-mobile-panel li a { display: block; padding: 10px 16px;' +
| |
| ' color: #202122; text-decoration: none; font-size: 1em; }' +
| |
| '#twinkle-mobile-panel li a:active { background: #eaecf0; }' +
| |
| '#twinkle-mobile-panel .twinkle-panel-head { padding: 6px 16px;' +
| |
| ' font-weight: bold; border-bottom: 1px solid #eaecf0; }'
| |
| );
| |
| rawCss( 'MediaWiki:Gadget-Twinkle.css' );
| |
| rawCss( 'MediaWiki:Gadget-morebits.css' );
| |
| rawCss( 'MediaWiki:Gadget-select2.min.css' );
| |
| | |
| function findTwinkleList() {
| |
| var sels = [ '#p-twinkle ul', '#p-cactions ul',
| |
| 'ul.twinkle-menu-list' ];
| |
| for ( var i = 0; i < sels.length; i++ ) {
| |
| var el = document.querySelector( sels[ i ] );
| |
| if ( el && el.querySelectorAll( 'li' ).length ) {
| |
| return { list: el, where: sels[ i ] };
| |
| }
| |
| }
| |
| var anyLi = document.querySelector( 'li[id^="ca-twinkle"]' );
| |
| if ( anyLi && anyLi.parentElement ) {
| |
| return { list: anyLi.parentElement, where: 'li#ca-twinkle*' };
| |
| }
| |
| return null;
| |
| }
| |
| | |
| function attachMenu() {
| |
| var found = findTwinkleList();
| |
| if ( !found ) {
| |
| mw.notify( 'Twinkle load huwa, par menu NAHI mila (v2)',
| |
| { type: 'error' } );
| |
| return;
| |
| }
| |
| var panel = document.createElement( 'div' );
| |
| panel.id = 'twinkle-mobile-panel';
| |
| panel.style.display = 'none';
| |
| var head = document.createElement( 'div' );
| |
| head.className = 'twinkle-panel-head';
| |
| head.textContent = 'Twinkle';
| |
| panel.appendChild( head );
| |
| panel.appendChild( found.list );
| |
| document.body.appendChild( panel );
| |
| | |
| var overflow = document.querySelector( 'ul#p-tb' ) ||
| |
| document.querySelector( '.page-actions-overflow-list' );
| |
| if ( overflow ) {
| |
| var li = document.createElement( 'li' );
| |
| li.className = 'toggle-list-item';
| |
| var a = document.createElement( 'a' );
| |
| a.className = 'toggle-list-item__anchor';
| |
| a.href = '#';
| |
| var label = document.createElement( 'span' );
| |
| label.className = 'toggle-list-item__label';
| |
| label.textContent = 'Twinkle';
| |
| a.appendChild( label );
| |
| a.addEventListener( 'click', function ( e ) {
| |
| e.preventDefault();
| |
| var cb = document.getElementById(
| |
| 'page-actions-overflow-checkbox' );
| |
| if ( cb ) { cb.checked = false; }
| |
| panel.style.display =
| |
| panel.style.display === 'none' ? 'block' : 'none';
| |
| } );
| |
| li.appendChild( a );
| |
| overflow.appendChild( li );
| |
| }
| |
| mw.notify( 'Twinkle menu taiyaar: ' + found.where,
| |
| { type: 'info' } );
| |
| }
| |
| | |
| function waitAndAttach( tries ) {
| |
| if ( findTwinkleList() || tries <= 0 ) {
| |
| attachMenu();
| |
| return;
| |
| }
| |
| setTimeout( function () { waitAndAttach( tries - 1 ); }, 500 );
| |
| }
| |
| | |
| mw.loader.using( [
| |
| 'mediawiki.util', 'mediawiki.api', 'mediawiki.storage',
| |
| 'mediawiki.Title', 'mediawiki.user', 'jquery.ui'
| |
| ] ).then( function () {
| |
| return loadScript( 'MediaWiki:Gadget-select2.min.js' );
| |
| } ).then( function () {
| |
| return loadScript( 'MediaWiki:Gadget-morebits.js' );
| |
| } ).then( function () {
| |
| return loadScript( 'MediaWiki:Gadget-Twinkle.js' );
| |
| } ).then( function () {
| |
| waitAndAttach( 20 );
| |
| } ).catch( function ( err ) {
| |
| mw.notify( 'Twinkle mobile test load FAIL: ' + err,
| |
| { type: 'error' } );
| |
| } );
| |
| }() );
| |
// Twinkle mobile support is now site-wide via the Twinkle gadget (MediaWiki:Gadget-TwinkleMobile.js). This personal test page is no longer needed.