jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/365967 )
Change subject: Add view/download controls for 3D images
......................................................................
Add view/download controls for 3D images
Bug: T167730
Change-Id: I0acb4b448251e9b8efc1435a84e35b18fc10f92e
---
M .eslintrc.json
M Hooks.php
M extension.json
A modules/mmv.3d.head.js
A modules/mmv.3d.head.less
5 files changed, 113 insertions(+), 0 deletions(-)
Approvals:
MarkTraceur: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.eslintrc.json b/.eslintrc.json
index c2cd2ce..773a955 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -7,6 +7,7 @@
},
"globals": {
"mediaWiki": false,
+ "OO": false,
"TD": true,
"THREE": false
}
diff --git a/Hooks.php b/Hooks.php
index 313b34d..f2816e6 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -28,6 +28,15 @@
public static function onBeforePageDisplay( &$out, &$skin ) {
$out->addModules( [ 'ext.3d' ] );
+ $article = new \ImagePage( $out->getTitle() );
+ if (
+ class_exists( 'MultimediaViewerHooks' ) &&
+ $out->getTitle()->inNamespace( NS_FILE ) &&
+ $article->getFile()->getExtension() === 'stl'
+ ) {
+ $out->addModules( [ 'mmv.3d.head' ] );
+ }
+
return true;
}
}
diff --git a/extension.json b/extension.json
index d2470d6..f7cee3f 100644
--- a/extension.json
+++ b/extension.json
@@ -47,6 +47,22 @@
"mmv",
"ext.3d"
]
+ },
+ "mmv.3d.head": {
+ "scripts": [
+ "mmv.3d.head.js"
+ ],
+ "styles": [
+ "mmv.3d.head.less"
+ ],
+ "messages": [
+ "view",
+ "download"
+ ],
+ "dependencies": [
+ "ext.3d",
+ "oojs-ui"
+ ]
}
},
"ResourceFileModulePaths": {
diff --git a/modules/mmv.3d.head.js b/modules/mmv.3d.head.js
new file mode 100644
index 0000000..2285dcd
--- /dev/null
+++ b/modules/mmv.3d.head.js
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the MediaWiki extension 3D.
+ *
+ * The 3D extension is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The 3D extension is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The 3D extension. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+( function ( mw, $, OO ) {
+ 'use strict';
+
+ mw.threed.mmv = {
+ /**
+ * @param {jQuery} $image
+ * @param {jQuery} $link
+ */
+ attachControls: function ( $image, $link ) {
+ var $wrap = mw.threed.wrap( $image ),
+ view = new OO.ui.ButtonWidget( {
+ icon: 'eye',
+ flags: [ 'progressive' ],
+ title: mw.message( 'view' ).text()
+ } ),
+ download = new OO.ui.ButtonWidget( {
+ icon: 'download',
+ flags: [ 'progressive' ],
+ title: mw.message( 'download' ).text()
+ } ),
+ $buttonWrap = $( '<span>' )
+ .addClass( 'mw-3d-control-wrapper' )
+ .append( view.$element,
download.$element );
+
+ view.on( 'click', this.open.bind( this, $image, $link )
);
+ download.on( 'click', this.download.bind( this, $link )
);
+
+ $wrap.append( $buttonWrap );
+
+ // clicking file should open it in MMV instead of
prompting download
+ $link.on( 'click', function ( e ) {
+ e.preventDefault();
+ this.open( $image, $link );
+ }.bind( this ) );
+ },
+
+ /**
+ * @param {jQuery} $image
+ * @param {jQuery} $link
+ */
+ open: function ( $image, $link ) {
+ mw.loader.using( [ 'mmv.bootstrap' ], function () {
+ var bootstrap, title;
+
+ if ( !mw.mmv.isBrowserSupported() ) {
+ return;
+ }
+
+ title = mw.Title.newFromImg( $image );
+
+ bootstrap = new
mw.mmv.MultimediaViewerBootstrap();
+ bootstrap.openImage( $link, title );
+ } );
+ },
+
+ /**
+ * @param {jQuery} $link
+ */
+ download: function ( $link ) {
+ window.location = $link.attr( 'href' );
+ }
+ };
+
+ mw.threed.mmv.attachControls( $( '.fullImageLink img[src$=".stl.png"]'
), $( '.fullImageLink a' ) );
+}( mediaWiki, jQuery, OO ) );
diff --git a/modules/mmv.3d.head.less b/modules/mmv.3d.head.less
new file mode 100644
index 0000000..b22ecd5
--- /dev/null
+++ b/modules/mmv.3d.head.less
@@ -0,0 +1,5 @@
+.mw-3d-control-wrapper {
+ position: absolute;
+ top: 11px;
+ right: 11px;
+}
--
To view, visit https://gerrit.wikimedia.org/r/365967
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0acb4b448251e9b8efc1435a84e35b18fc10f92e
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/3D
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: MarkTraceur <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits