Andrew-WMDE has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/350826 )

Change subject: Open help dialogue the first time a user sees TwoColConflict
......................................................................

Open help dialogue the first time a user sees TwoColConflict

Bug: T163783
Change-Id: I6e3d90fd574209e7edd645c14a39a1b96695d461
---
M extension.json
A modules/ext.TwoColConflict.Settings.js
M modules/ext.TwoColConflict.init.js
3 files changed, 103 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TwoColConflict 
refs/changes/26/350826/1

diff --git a/extension.json b/extension.json
index c19d1bf..cb9db5f 100644
--- a/extension.json
+++ b/extension.json
@@ -53,10 +53,21 @@
                                "modules/ext.TwoColConflict.init.js"
                        ],
                        "dependencies": [
+                               "ext.TwoColConflict.Settings",
                                "ext.TwoColConflict.AutoScroll",
                                "ext.TwoColConflict.HelpDialog"
                        ]
                },
+               "ext.TwoColConflict.Settings": {
+                       "scripts": [
+                               "modules/ext.TwoColConflict.Settings.js"
+                       ],
+                       "dependencies": [
+                               "mediawiki.storage",
+                               "mediawiki.cookie",
+                               "mediawiki.api.options"
+                       ]
+               },
                "ext.TwoColConflict.filterOptionsJs": {
                        "scripts": [
                                "modules/ext.TwoColConflict.filterOptions.js"
diff --git a/modules/ext.TwoColConflict.Settings.js 
b/modules/ext.TwoColConflict.Settings.js
new file mode 100644
index 0000000..afd4c2e
--- /dev/null
+++ b/modules/ext.TwoColConflict.Settings.js
@@ -0,0 +1,85 @@
+( function ( mw, $ ) {
+       /**
+        * @constructor
+        */
+       var Settings = function () {
+               this.hideHelpDialogue = this.loadBoolean( 'hide-help-dialogue' 
);
+       };
+
+       $.extend( Settings.prototype, {
+               /**
+                * @type {boolean}
+                */
+               hideHelpDialogue: null,
+
+               /**
+                * @return {boolean}
+                */
+               shouldHideHelpDialogue: function () {
+                       return this.hideHelpDialogue;
+               },
+
+               /**
+                * @param {boolean} newSetting
+                */
+               setHideHelpDialogue: function ( newSetting ) {
+                       if ( newSetting !== this.hideHelpDialogue ) {
+                               this.saveBoolean( 'hide-help-dialogue', 
newSetting );
+                               this.hideHelpDialogue = newSetting;
+                       }
+               },
+
+               /**
+                * @param {string} name
+                * @param {string} defaultValue
+                * @return {string|boolean}
+                */
+               loadSetting: function ( name, defaultValue ) {
+                       var setting;
+                       if ( !mw.user.isAnon() ) {
+                               setting = mw.user.options.get( 
'userjs-twocolconflict-' + name );
+                       } else {
+                               setting = mw.storage.get( 'mw-twocolconflict-' 
+ name );
+                               if ( !setting ) {
+                                       setting = mw.cookie.get( 
'-twocolconflict-' + name );
+                               }
+                       }
+
+                       return setting !== null && setting !== false ? setting 
: defaultValue;
+               },
+
+               /**
+                * @param {string} name
+                * @param {boolean} defaultValue
+                * @return {boolean}
+                */
+               loadBoolean: function ( name, defaultValue ) {
+                       return this.loadSetting( name, defaultValue ? '1' : '0' 
) === '1';
+               },
+
+               /**
+                * @param {string} name
+                * @param {string} value
+                */
+               saveSetting: function ( name, value ) {
+                       if ( !mw.user.isAnon() ) {
+                               ( new mw.Api() ).saveOption( 
'userjs-twocolconflict-' + name, value );
+                       } else {
+                               if ( !mw.storage.set( 'mw-twocolconflict-' + 
name, value ) ) {
+                                       mw.cookie.set( '-twocolconflict-' + 
name, value ); // use cookie when localStorage is not available
+                               }
+                       }
+               },
+
+               /**
+                * @param {string} name
+                * @param {boolean} value
+                */
+               saveBoolean: function ( name, value ) {
+                       this.saveSetting( name, value ? '1' : '0' );
+               }
+       } );
+
+       mw.libs.twoColConflict = mw.libs.twoColConflict || {};
+       mw.libs.twoColConflict.Settings = Settings;
+}( mediaWiki, jQuery ) );
diff --git a/modules/ext.TwoColConflict.init.js 
b/modules/ext.TwoColConflict.init.js
index b54469f..f88513f 100644
--- a/modules/ext.TwoColConflict.init.js
+++ b/modules/ext.TwoColConflict.init.js
@@ -1,5 +1,6 @@
 ( function ( mw, $ ) {
-       var autoScroll = new mw.libs.twoColConflict.AutoScroll(),
+       var settings = new mw.libs.twoColConflict.Settings(),
+               autoScroll = new mw.libs.twoColConflict.AutoScroll(),
                helpDialog = mw.libs.twoColConflict.HelpDialog;
 
        function selectText( element ) {
@@ -134,5 +135,10 @@
                        adjustEditorColSpacing();
                } );
 
+               if ( !settings.shouldHideHelpDialogue() ) {
+                       helpDialog.show();
+                       settings.setHideHelpDialogue( true );
+               }
+
        } );
 }( mediaWiki, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e3d90fd574209e7edd645c14a39a1b96695d461
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TwoColConflict
Gerrit-Branch: master
Gerrit-Owner: Andrew-WMDE <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to