Foxtrott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/119893
Change subject: Select all/Select none links for checkboxes input type
......................................................................
Select all/Select none links for checkboxes input type
This patch will add the parameters 'show select all' and 'show select none' to
the checkboxes input type.
When used links will be attached to the respective field of checkboxes that
allow the selection or deselection of all checkboxes at once.
A JavaScript enabled browser is necessary for this to work. JavaScript disabled
browsers will not see any difference to the current behavior.
Change-Id: I809d10517ab89e38550340779d4415509d77ee63
---
M SemanticForms.php
M includes/SF_AutoeditAPI.php
M includes/SF_Utils.php
M includes/forminputs/SF_CheckboxesInput.php
M languages/SF_Messages.php
A libs/SF_checkboxes.js
A skins/SF_checkboxes.css
7 files changed, 95 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticForms
refs/changes/93/119893/1
diff --git a/SemanticForms.php b/SemanticForms.php
index ab80aa6..a12a5a4 100644
--- a/SemanticForms.php
+++ b/SemanticForms.php
@@ -296,8 +296,16 @@
),
),
'ext.semanticforms.imagepreview' => $sfgResourceTemplate +
array(
- 'scripts' => 'libs/SF_imagePreview.js',
- ),
+ 'scripts' => 'libs/SF_imagePreview.js',
+ ),
+ 'ext.semanticforms.checkboxes' => $sfgResourceTemplate + array(
+ 'scripts' => 'libs/SF_checkboxes.js',
+ 'styles' => 'skins/SF_checkboxes.css',
+ 'messages' => array(
+ 'sf_forminputs_checkboxes_select_all',
+ 'sf_forminputs_checkboxes_select_none',
+ ),
+ ),
);
}
diff --git a/includes/SF_AutoeditAPI.php b/includes/SF_AutoeditAPI.php
index 2933a8d..9018b4d 100644
--- a/includes/SF_AutoeditAPI.php
+++ b/includes/SF_AutoeditAPI.php
@@ -355,7 +355,7 @@
'wpSummary' => '',
'wpStarttime' => wfTimestampNow(),
'wpEdittime' => '',
- 'wpEditToken' => $wgUser->isLoggedIn()
? $wgUser->editToken() : EDIT_TOKEN_SUFFIX,
+// 'wpEditToken' => $wgUser->isLoggedIn()
? $wgUser->editToken() : EDIT_TOKEN_SUFFIX,
'action' => 'submit',
),
$this->mOptions
diff --git a/includes/SF_Utils.php b/includes/SF_Utils.php
index c59bb6d..dfb8cf1 100644
--- a/includes/SF_Utils.php
+++ b/includes/SF_Utils.php
@@ -313,6 +313,7 @@
$output->addModules( 'ext.semanticforms.imagepreview' );
$output->addModules( 'ext.semanticforms.autogrow' );
$output->addModules( 'ext.semanticforms.submit' );
+ $output->addModules( 'ext.semanticforms.checkboxes' );
$output->addModules( 'ext.smw.tooltips' );
$output->addModules( 'ext.smw.sorttable' );
diff --git a/includes/forminputs/SF_CheckboxesInput.php
b/includes/forminputs/SF_CheckboxesInput.php
index 09cd340..e042cdb 100644
--- a/includes/forminputs/SF_CheckboxesInput.php
+++ b/includes/forminputs/SF_CheckboxesInput.php
@@ -90,6 +90,15 @@
$outerSpanClass .= ' mandatoryFieldSpan';
}
+ if ( array_key_exists( 'show select all', $other_args ) ) {
+ $outerSpanClass .= ' select-all';
+ }
+
+ if ( array_key_exists( 'show select none', $other_args ) ) {
+ $outerSpanClass .= ' select-none';
+ }
+
+
if ( array_key_exists( 'show on select', $other_args ) ) {
$outerSpanClass .= ' sfShowIfChecked';
foreach ( $other_args['show on select'] as $div_id =>
$options ) {
diff --git a/languages/SF_Messages.php b/languages/SF_Messages.php
index ec15d81..a3684e9 100644
--- a/languages/SF_Messages.php
+++ b/languages/SF_Messages.php
@@ -83,6 +83,8 @@
'sf_forminputs_depth' => 'The number of levels of
categories to show initially',
'sf_forminputs_height' => 'The height of this input, in
pixels',
'sf_forminputs_width' => 'The width of this input, in
pixels',
+ 'sf_forminputs_checkboxes_select_all' => 'Select all',
+ 'sf_forminputs_checkboxes_select_none' => 'Select none',
'createform' => 'Create a form',
'sf-createform-with-name' => 'Create form: $1',
'sf_createform_nameinput' => 'Form name',
@@ -310,6 +312,8 @@
** C
*** D
* E',
+ 'sf_forminputs_checkboxes_select_all' => 'This is used for a field of
checkboxes. It is as a label for a link that triggers the selection of all
checkboxes.',
+ 'sf_forminputs_checkboxes_select_none' => 'This is used for a field of
checkboxes. It is as a label for a link that triggers the deselection of all
checkboxes.',
'createform' => '{{doc-special|CreateForm}}
Title below, create link. If you enter, include ".".',
'sf-createform-with-name' => 'Used as page title. Parameters:
diff --git a/libs/SF_checkboxes.js b/libs/SF_checkboxes.js
new file mode 100644
index 0000000..63519f2
--- /dev/null
+++ b/libs/SF_checkboxes.js
@@ -0,0 +1,58 @@
+/**
+ * Javascript handler for the checkboxes input type
+ *
+ * @author Stephan Gambke
+ */
+
+/*global jQuery, mediaWiki */
+
+( function ( $, mw ) {
+
+ 'use strict';
+
+ // jQuery plugin that will attach a select all/select none switch to
all checkboxes in "this" element
+ $.fn.appendSelectionSwitch = function ( label, checked ) {
+
+ this.each( function ( index, element ) {
+
+ var $element = $(element);
+
+ // create a wrapper for the selection/deselection
elements if necessary
+ var switchesWrapper = $element.children(
'span.checkboxSwitches' );
+
+ if ( switchesWrapper.length == 0 ) {
+ switchesWrapper = $( '<span
class="checkboxSwitches">' ).prependTo( element );
+ }
+
+ // create a link element that will trigger the
selection of all checkboxes
+ var link = $( '<a href="#">' + label + '</a>' );
+
+ // will be initialized later when the event is
triggered to avoid lag during page loading
+ var $checkboxes;
+
+ // attach an event handler
+ link.click( function ( event ) {
+
+ event.preventDefault();
+
+ // store checkboxes during first method call so
the DOM is not searched on every click on the link
+ $checkboxes = $checkboxes || $element.find(
'input[type="checkbox"]' );
+
+ $checkboxes.prop( 'checked', checked );
+ } );
+
+ // wrap the link into a span to simplify styling
+ var switchWrapper = $('<span class="checkboxSwitch">'
).append( link );
+
+ // insert the complete switch into the DOM
+ switchesWrapper.append( switchWrapper );
+
+ } );
+ }
+
+ $().ready( function ( $ ) {
+ $( '.checkboxesSpan.select-all' ).appendSelectionSwitch(
mw.message( 'sf_forminputs_checkboxes_select_all' ), true );
+ $( '.checkboxesSpan.select-none' ).appendSelectionSwitch(
mw.message( 'sf_forminputs_checkboxes_select_none' ), false );
+ } );
+
+}( jQuery, mediaWiki ) );
diff --git a/skins/SF_checkboxes.css b/skins/SF_checkboxes.css
new file mode 100644
index 0000000..a7c38f1
--- /dev/null
+++ b/skins/SF_checkboxes.css
@@ -0,0 +1,12 @@
+.checkboxSwitches {
+ display: block;
+ font-size: small;
+}
+
+.checkboxSwitch::before {
+ content: "[ ";
+}
+
+.checkboxSwitch::after {
+ content: " ]";
+}
--
To view, visit https://gerrit.wikimedia.org/r/119893
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I809d10517ab89e38550340779d4415509d77ee63
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticForms
Gerrit-Branch: master
Gerrit-Owner: Foxtrott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits