jenkins-bot has submitted this change and it was merged.
Change subject: Display cards in desktop view too
......................................................................
Display cards in desktop view too
Depending on the platform, load either Mustache or Hogan
templates and their associated libraries.
Also load the correct module (mw.util rather than mw.Title).
Bug: T116601
Change-Id: I6661527175eb889cec4193b18fa18207f332b4fc
---
M extension.json
A includes/ResourceLoaderMuhoganModule.php
M resources/CardListView.js
M resources/CardView.js
R resources/card.muhogan
R resources/cards.muhogan
A resources/muhogan.js
7 files changed, 65 insertions(+), 6 deletions(-)
Approvals:
Phuedx: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index ca1cc1e..faa6ac7 100644
--- a/extension.json
+++ b/extension.json
@@ -14,6 +14,7 @@
]
},
"AutoloadClasses": {
+ "Cards\\ResourceLoaderMuHoganModule":
"includes/ResourceLoaderMuhoganModule.php",
"Cards\\Hooks": "includes/Cards.hooks.php"
},
"Hooks": {
@@ -26,15 +27,25 @@
"remoteExtPath": "Cards"
},
"ResourceModules": {
+ "mediawiki.template.muhogan": {
+ "class": "Cards\\ResourceLoaderMuHoganModule",
+ "scripts": [
+ "resources/muhogan.js"
+ ],
+ "targets": [
+ "desktop",
+ "mobile"
+ ]
+ },
"ext.cards": {
"targets": [
+ "desktop",
"mobile"
],
"group": "other",
"dependencies": [
"oojs",
- "mediawiki.Title",
- "mediawiki.template.hogan",
+ "mediawiki.util",
"ext.cards.lib"
],
"scripts": [
@@ -48,12 +59,13 @@
"resources/styles.less"
],
"templates": {
- "card.hogan": "resources/card.hogan",
- "cards.hogan": "resources/cards.hogan"
+ "card.muhogan": "resources/card.muhogan",
+ "cards.muhogan": "resources/cards.muhogan"
}
},
"ext.cards.lib": {
"targets": [
+ "desktop",
"mobile"
],
"group": "other",
diff --git a/includes/ResourceLoaderMuhoganModule.php
b/includes/ResourceLoaderMuhoganModule.php
new file mode 100644
index 0000000..9f0f352
--- /dev/null
+++ b/includes/ResourceLoaderMuhoganModule.php
@@ -0,0 +1,26 @@
+<?php
+namespace Cards;
+
+use ResourceLoaderFileModule;
+use ResourceLoaderContext;
+
+/**
+ * A ResourceLoader module that serves Hogan or Mustache depending on the
+ * current target.
+ *
+ * FIXME: this is a copy&paste from the QuickSurveys extension. Find a way to
+ * share the code or use mustache in MobileFrontend too.
+ */
+class ResourceLoaderMuHoganModule extends ResourceLoaderFileModule {
+ public function getDependencies( ResourceLoaderContext $context = null
) {
+ $dependencies = parent::getDependencies( $context );
+
+ if ( $context && $context->getRequest()->getVal( 'target' ) ===
'mobile' ) {
+ $dependencies[] = 'mediawiki.template.hogan';
+ } else {
+ $dependencies[] = 'mediawiki.template.mustache';
+ }
+
+ return $dependencies;
+ }
+}
diff --git a/resources/CardListView.js b/resources/CardListView.js
index 7a54cc1..2726a1b 100644
--- a/resources/CardListView.js
+++ b/resources/CardListView.js
@@ -31,7 +31,7 @@
/**
* @property {Object} compiled template
*/
- CardListView.prototype.template = mw.template.get( 'ext.cards',
'cards.hogan' );
+ CardListView.prototype.template = mw.template.get( 'ext.cards',
'cards.muhogan' );
mw.cards.CardListView = CardListView;
} )( jQuery );
diff --git a/resources/CardView.js b/resources/CardView.js
index e683746..2019f4b 100644
--- a/resources/CardView.js
+++ b/resources/CardView.js
@@ -26,7 +26,7 @@
/**
* @property {Object} compiled template
*/
- CardView.prototype.template = mw.template.get( 'ext.cards',
'card.hogan' );
+ CardView.prototype.template = mw.template.get( 'ext.cards',
'card.muhogan' );
/**
* Replace the html of this.$el with a newly rendered html using the
model
diff --git a/resources/card.hogan b/resources/card.muhogan
similarity index 100%
rename from resources/card.hogan
rename to resources/card.muhogan
diff --git a/resources/cards.hogan b/resources/cards.muhogan
similarity index 100%
rename from resources/cards.hogan
rename to resources/cards.muhogan
diff --git a/resources/muhogan.js b/resources/muhogan.js
new file mode 100644
index 0000000..7379d6e
--- /dev/null
+++ b/resources/muhogan.js
@@ -0,0 +1,21 @@
+/*jshint -W002 */
+// Register the Hogan compiler with MediaWiki.
+( function () {
+ var compiler;
+ /*
+ * Check if muhogan is already registered (by QuickSurveys). If not
+ * register mustache (Desktop) or hogan (Mobile) as muhogan.
+ */
+ try {
+ mw.template.getCompiler( 'muhogan' );
+ } catch ( e ) {
+ try {
+ compiler = mw.template.getCompiler( 'mustache' );
+ } catch ( e ) {
+ compiler = mw.template.getCompiler( 'hogan' );
+ }
+
+ // register hybrid compiler with core
+ mw.template.registerCompiler( 'muhogan', compiler );
+ }
+}() );
--
To view, visit https://gerrit.wikimedia.org/r/252210
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6661527175eb889cec4193b18fa18207f332b4fc
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Cards
Gerrit-Branch: master
Gerrit-Owner: Bmansurov <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jhobs <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits