Sumit has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/218672

Change subject: WikidataPageBanner toc added
......................................................................

WikidataPageBanner toc added

Add option 'toc=yes' to allow passing a parameter to {{PAGEBANNER}} for
rendering a horizontal TOC within the banner. The toc is manipulated from
client-side using jquery, where it is removed from normal location and inserted
into the banner.

Bug: T97839
Change-Id: If8249dfb198b37952f5740f348c48b093ffde5c1
---
M WikidataPageBanner.php
A includes/WikidataPageBanner.functions.php
M includes/WikidataPageBanner.hooks.php
M resources/Resources.php
M resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
A resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.js
A resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.less
M templates/banner.mustache
8 files changed, 133 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataPageBanner 
refs/changes/72/218672/1

diff --git a/WikidataPageBanner.php b/WikidataPageBanner.php
index be3ad4e..f77bc9d 100644
--- a/WikidataPageBanner.php
+++ b/WikidataPageBanner.php
@@ -37,6 +37,8 @@
 /* Setup */
 // autoloader
 $wgAutoloadClasses['WikidataPageBanner'] = __DIR__ . 
'/includes/WikidataPageBanner.hooks.php';
+$wgAutoloadClasses['WikidataPageBannerFunctions'] =
+       __DIR__ . '/includes/WikidataPageBanner.functions.php';
 
 // Register files
 $wgMessagesDirs['WikidataPageBanner'] = __DIR__ . '/i18n';
diff --git a/includes/WikidataPageBanner.functions.php 
b/includes/WikidataPageBanner.functions.php
new file mode 100644
index 0000000..10f4c9c
--- /dev/null
+++ b/includes/WikidataPageBanner.functions.php
@@ -0,0 +1,13 @@
+<?php
+class WikidataPageBannerFunctions {
+       /**
+        * Set bannertoc variable on parser output object
+        * @param ParserOutput $parserOutput ParserOutput object
+        * @param array $options options from parser function
+        */
+       public static function addToc( $parserOutput, $options ) {
+               if ( isset( $options['toc'] ) && $options['toc'] == 'yes' ) {
+                       $parserOutput->setProperty( 'bannertoc', true );
+               }
+       }
+}
diff --git a/includes/WikidataPageBanner.hooks.php 
b/includes/WikidataPageBanner.hooks.php
index ac1c6bf..8f8bac5 100644
--- a/includes/WikidataPageBanner.hooks.php
+++ b/includes/WikidataPageBanner.hooks.php
@@ -48,6 +48,10 @@
                                $article->getParserOutput()->getProperty( 
'articlebanner' )
                        );
                }
+               if ( $article->getParserOutput()->getProperty( 'bannertoc' ) && 
$out->isTOCEnabled() ) {
+                       $out->addJsConfigVars( 'bannertoc', true );
+                       $out->addModules( 'ext.WikidataPageBanner.toc' );
+               }
                return true;
        }
 
@@ -62,7 +66,6 @@
                if ( $out->getProperty( 'articlebanner' ) != null ) {
                        // if articlebanner property is set, we need to add 
banner styles
                        $out->addModuleStyles( 'ext.WikidataPageBanner' );
-                       $out->addModules( 'ext.WikidataPageBanner.loadImage' );
                }
        }
 
@@ -93,6 +96,7 @@
                                $title = $argumentsFromParserFunction['pgname'];
                        }
                        $paramsForBannerTemplate['title'] = $title;
+                       WikidataPageBannerFunctions::addToc( 
$parser->getOutput(), $argumentsFromParserFunction );
                        $banner = self::getBannerHtml( $bannername, 
$paramsForBannerTemplate );
                        // if given banner does not exist, return
                        if ( $banner === null ) {
diff --git a/resources/Resources.php b/resources/Resources.php
index 8a1fc14..03105ec 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -33,3 +33,16 @@
        'targets' => array( 'desktop', 'mobile' ),
        'position' => 'top'
 );
+
+$wgResourceModules['ext.WikidataPageBanner.toc'] = array(
+       'styles' => array(
+               'ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.less',
+       ),
+       'scripts' => array(
+               'ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.js'
+       ),
+       'localBasePath' => __DIR__,
+       'remoteExtPath' => 'WikidataPageBanner/resources',
+       'targets' => array( 'desktop', 'mobile' ),
+       'position' => 'bottom'
+);
diff --git 
a/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less 
b/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
index 185af6d..9355308 100644
--- a/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
+++ b/resources/ext.WikidataPageBanner.styles/ext.WikidataPageBanner.less
@@ -9,7 +9,6 @@
 .topbanner{
        position: relative;
        max-width: 1800px;
-       overflow: hidden;
        height: auto;
 }
 
diff --git a/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.js 
b/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.js
new file mode 100644
index 0000000..555c52a
--- /dev/null
+++ b/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.js
@@ -0,0 +1,6 @@
+( function( mw, $ ) {
+       if ( mw.config.get( 'bannertoc' ) ) {
+               var toc = $( '.toc' ).remove();
+               $( '.topbanner-toc' ).append( toc );
+       }
+}( mediaWiki, jQuery ) );
diff --git 
a/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.less 
b/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.less
new file mode 100644
index 0000000..d0113d6
--- /dev/null
+++ b/resources/ext.WikidataPageBanner.toc/ext.WikidataPageBanner.toc.less
@@ -0,0 +1,93 @@
+/**
+ * Stylesheet for Table Of Contents in Banners displayed by WikidataPageBanner 
extension.
+ */
+@import "mediawiki.mixins";
+// Suppress numbering of items in TOC
+.tocnumber { display: none; }
+
+.topbanner-toc {
+       position: absolute;
+       background: rgba(0, 0, 0, 0.5) none repeat scroll 0% 0%;
+       bottom: 6px;
+       left: 0;
+       z-index: 3;
+       width:100%;
+}
+
+#toc, .toc {
+       display:table;
+       color: white;
+       background: none;
+       border: medium none;
+       line-height: 1.1em;
+       padding: 0 2em 0 2em;
+       margin: 0;
+       width:auto;
+       a {
+               color:white;
+               font-size: 0.85em;
+               font-weight: bold;
+       }
+       a:hover {
+               color: #BDDDFD;
+       }
+       // On hovering over a list item, show the list items which are 
immediate child of this item
+       li:hover {
+               &>ul>li {
+                       display:block;
+               }
+               background: rgba(0, 0, 0, 0.8) none repeat scroll 0% 0%;
+       }
+}
+
+// Prevent display of subheadings in horizontal ToC
+.toclevel-2,
+.toclevel-3,
+.toclevel-4,
+.toclevel-5,
+.toclevel-6 {
+       display:none;
+       position:relative;
+       z-index:4;
+       padding:.5em;
+       margin:0;
+       white-space: nowrap;
+       .transition(all .5s);
+       color:black;
+       a{
+               color:black;
+       }
+}
+
+// Hide TOC title
+#toctitle {
+       display: none;
+}
+
+.toclevel-1 {
+       position:relative;
+       float:left;
+       padding:.5em;
+       margin:0;
+       // position immediate child list of level-1 items as vertical drop-downs
+       &>ul {
+               position:absolute;
+               top:100%;
+               left: 0;
+               margin:0 !important;
+               background: rgba(0, 0, 0, 0.6) none repeat scroll 0% 0%;
+               z-index:4;
+       }
+}
+
+.toclevel-2 {
+       // make immediate children of lists of items beyond level-2 open as 
side lists
+       ul{
+               position:absolute;
+               left: 100%;
+               background: rgba(0, 0, 0, 0.6) none repeat scroll 0% 0%;
+               margin:0 !important;
+               top:0;
+               z-index:4;
+       }
+}
diff --git a/templates/banner.mustache b/templates/banner.mustache
index b72222c..06b9743 100644
--- a/templates/banner.mustache
+++ b/templates/banner.mustache
@@ -4,6 +4,7 @@
                        <div class="name">{{title}}</div>
                        <div class="iconbox"></div>
                        <a title="{{title}}" href={{bannerfile}}><img 
src={{banner}} srcset="{{srcset}}" class="banner-image"></a>
+                       <div class="topbanner-toc"></div>
                </div>
        </div>
 </div>

-- 
To view, visit https://gerrit.wikimedia.org/r/218672
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If8249dfb198b37952f5740f348c48b093ffde5c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataPageBanner
Gerrit-Branch: master
Gerrit-Owner: Sumit <asthana.sumi...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to