Matthias Mullie has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/365676 )
Change subject: Add '3D' badge to identify 3D files ...................................................................... Add '3D' badge to identify 3D files Bug: T167727 Change-Id: I66394a62439de9aeee4958384ee7162723b737fb --- A Hooks.php M extension.json M i18n/en.json M i18n/qqq.json A modules/ext.3d.js A modules/ext.3d.less M modules/mmv.3d.js 7 files changed, 110 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/3D refs/changes/76/365676/1 diff --git a/Hooks.php b/Hooks.php new file mode 100644 index 0000000..313b34d --- /dev/null +++ b/Hooks.php @@ -0,0 +1,33 @@ +<?php +/** + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + */ + +namespace MediaWiki\Extensions\ThreeD; + +class Hooks { + /** + * @param \OutputPage $out + * @param \Skin $skin + * @return bool + */ + public static function onBeforePageDisplay( &$out, &$skin ) { + $out->addModules( [ 'ext.3d' ] ); + + return true; + } +} diff --git a/extension.json b/extension.json index 2c3fe64..d2470d6 100644 --- a/extension.json +++ b/extension.json @@ -22,6 +22,17 @@ ] }, "ResourceModules": { + "ext.3d": { + "scripts": [ + "ext.3d.js" + ], + "styles": [ + "ext.3d.less" + ], + "messages": [ + "3d-badge-text" + ] + }, "mmv.3d": { "scripts": [ "mmv.3d.js", @@ -33,7 +44,8 @@ "mmv.3d.less" ], "dependencies": [ - "mmv" + "mmv", + "ext.3d" ] } }, @@ -41,7 +53,13 @@ "localBasePath": "modules", "remoteExtPath": "3d/modules" }, + "Hooks": { + "BeforePageDisplay": [ + "MediaWiki\\Extensions\\ThreeD\\Hooks::onBeforePageDisplay" + ] + }, "AutoloadClasses": { + "MediaWiki\\Extensions\\ThreeD\\Hooks": "Hooks.php", "MediaWiki\\Extensions\\ThreeD\\ThreeDHandler": "ThreeDHandler.php" }, "MediaHandlers": { diff --git a/i18n/en.json b/i18n/en.json index aea053b..ae681da 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -5,5 +5,6 @@ ] }, "3d": "3d", - "3d-desc": "Provides support for 3d file formats" + "3d-desc": "Provides support for 3d file formats", + "3d-badge-text": "3D" } diff --git a/i18n/qqq.json b/i18n/qqq.json index 89dbb4c..9f93fb6 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -5,5 +5,6 @@ ] }, "3d": "The name of the extension", - "3d-desc": "{{desc|name=3d|url=https://www.mediawiki.org/wiki/Extension:3d}}" + "3d-desc": "{{desc|name=3d|url=https://www.mediawiki.org/wiki/Extension:3d}}", + "3d-badge-text": "Text for the badge shown in th top left corner of images to identify 3D files" } diff --git a/modules/ext.3d.js b/modules/ext.3d.js new file mode 100644 index 0000000..d3a3c91 --- /dev/null +++ b/modules/ext.3d.js @@ -0,0 +1,35 @@ +/* + * 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, $ ) { + 'use strict'; + + mw.threed = { + /** + * @param {jQuery} $element + */ + attachBadge: function ( $element ) { + var $badge = $( '<span>' ) + .addClass( 'mw-3d-badge' ) + .attr( 'data-3d-badge-text', mw.message( '3d-badge-text' ).text() ); + + $element.wrap( $badge ); + } + }; + + mw.threed.attachBadge( $( 'img[src$=".stl.png"]' ) ); +}( mediaWiki, jQuery ) ); diff --git a/modules/ext.3d.less b/modules/ext.3d.less new file mode 100644 index 0000000..ecb48c0 --- /dev/null +++ b/modules/ext.3d.less @@ -0,0 +1,17 @@ +.mw-3d-badge::before { + /* i18n-ized badge text */ + content: attr(data-3d-badge-text); + + position: absolute; + margin: 11px 0 0 11px; + + color: #1e1f21; + font-size: 14px; + line-height: 19px; + font-weight: bold; + + opacity: 0.8; + padding: 2px 5px; + background-color: #f8f9fa; + border-radius: 2px; +} diff --git a/modules/mmv.3d.js b/modules/mmv.3d.js index 6a891f6..ab1ebb8 100644 --- a/modules/mmv.3d.js +++ b/modules/mmv.3d.js @@ -168,6 +168,8 @@ threed.$container.html( threed.renderer.domElement ); threed.camera.lookAt( threed.scene.position ); threed.render( threed.renderer, threed.scene, threed.camera ); + + mw.threed.attachBadge( threed.$container ); } ).progress( function ( progress ) { threed.progressBar.animateTo( progress ); } ).fail( function ( /* error */ ) { -- To view, visit https://gerrit.wikimedia.org/r/365676 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I66394a62439de9aeee4958384ee7162723b737fb 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
