Matthias Mullie has uploaded a new change for review. (
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 Hooks.php
M extension.json
A modules/mmv.3d.head.js
A modules/mmv.3d.head.less
4 files changed, 117 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/3D
refs/changes/67/365967/1
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..a63f821 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..a38207d
--- /dev/null
+++ b/modules/mmv.3d.head.js
@@ -0,0 +1,83 @@
+/*
+ * 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 );
+
+ // disable default "clicking on image results in
download" behavior
+ $link
+ .addClass( 'mw-3d-disabled' )
+ .on( 'click', function ( e ) {
+ e.preventDefault();
+ } );
+ },
+
+ /**
+ * @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( $( '#file img[src$=".stl.png"]' ), $(
'#file a' ) );
+}( mediaWiki, jQuery, OO ) );
diff --git a/modules/mmv.3d.head.less b/modules/mmv.3d.head.less
new file mode 100644
index 0000000..38bb622
--- /dev/null
+++ b/modules/mmv.3d.head.less
@@ -0,0 +1,9 @@
+.mw-3d-control-wrapper {
+ position: absolute;
+ top: 11px;
+ right: 11px;
+}
+
+#file a.mw-3d-disabled {
+ cursor: default;
+}
--
To view, visit https://gerrit.wikimedia.org/r/365967
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0acb4b448251e9b8efc1435a84e35b18fc10f92e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/3D
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits