Commit 5634bc36 authored by Denis Chenu's avatar Denis Chenu
Browse files

[feature] Fix other for single choice (radio) and multiple choice

[developement] Add SmartDOMDocument
[documentation] Improve README and add LICENCE (GPLv3)
parent fce71db8
[submodule "vendor/archon810/smartdomdocument"]
path = vendor/archon810/smartdomdocument
url = https://bitbucket.org/archon810/smartdomdocument.git
This diff is collapsed.
# More accessibility for LimeSurvey #
Some more accessibility for LimeSurvey, actually:
* Replace the label for single question choice by label to the question (to be included in LimeSurvey core).
* Optionnal: Use a real string for the asterisk in mandatory question type
* Optionnal: Add fieldset for list of answers and subquestion
- Replace the label for single question choice by label to the question
- Fix the other label in single choice (radio) and multiple choice
- Optionnal: Use a real string for the asterisk in mandatory question type
- Optionnal: Add fieldset for list of answers and subquestion
## Installation
### Via GIT
- Go to your LimeSurvey Directory (version up to 2.05)
- Clone in plugins/moreAccessibility directory
- Clone with Submodule in plugins/moreAccessibility directory (git clone --recursive)
### Via ZIP dowload
- Get the file and uncompress it
......@@ -19,4 +20,5 @@ Some more accessibility for LimeSurvey, actually:
- HomePage <http://extensions.sondages.pro/>
- Demonstration <http://accessible.sondages.pro> (WIP :can be broken)
- Copyright © 2015 Denis Chenu <http://sondages.pro>
- Licence : GNU General Public License <https://www.gnu.org/licenses/gpl-3.0.html>
\ No newline at end of file
- Licence : GNU General Public License <https://www.gnu.org/licenses/gpl-3.0.html>
- This plugin use SmartDOMDocument © 2015 Artem Russakovskii <http://beerpla.net>
......@@ -25,6 +25,10 @@ class moreAccessibility extends PluginBase
static protected $description = 'Update HTML for question for better labelling, and other accessibility waiting for CSS Aria';
protected $settings = array(
'infoAlwaysActivate'=>array(
'type' => 'info',
'content' => 'Some system can not be deactivated : use question text for labelling the single question type, fix checkbox with other label and radio with other label.',
),
'updateAsterisk' => array(
'type' => 'select',
'options'=>array(
......@@ -45,14 +49,21 @@ class moreAccessibility extends PluginBase
),
);
public function __construct(PluginManager $manager, $id) {
parent::__construct($manager, $id);
/**
* Add function to be used in beforeQuestionRender event
*/
public function init()
{
$this->subscribe('beforeQuestionRender','questiontextLabel');
$this->subscribe('beforeQuestionRender','mandatoryString');
$this->subscribe('beforeQuestionRender','questionanswersFieldset');
$this->subscribe('beforeQuestionRender','checkboxLabelOther');
$this->subscribe('beforeQuestionRender','radioLabelOther');
}
/**
* Use the question text as label for single question , use aria-labelledby for help and tips
*/
public function questiontextLabel()
{
$oEvent=$this->getEvent();
......@@ -90,7 +101,7 @@ class moreAccessibility extends PluginBase
$aLabelledBy[]="questionhelp-{$sAnswerId}";
$oEvent->set('help',CHtml::tag('span',array('id'=>"help-{$sAnswerId}"),$oEvent->get('help')));
}
if(strip_tags($oEvent->get('valid_message')!=""))
if(strip_tags($oEvent->get('valid_message'))!="")
{
$aLabelledBy[]="vmsg_{$oEvent->get('qid')}";
}
......@@ -98,13 +109,15 @@ class moreAccessibility extends PluginBase
{
$oEvent->set('valid_message','');
}
$dom = new DOMDocument();
Yii::setPathOfAlias('archon810', dirname(__FILE__)."/vendor/archon810/smartdomdocument/src");
Yii::import('archon810.SmartDOMDocument');
$dom = new \archon810\SmartDOMDocument();
@$dom->loadHTML($oEvent->get('answers'));
foreach($dom->getElementsByTagName('label') as $label)
$label->parentNode->removeChild($label);
$input=$dom->getElementById($sAnswerId);
$input->setAttribute("aria-labelledby",implode(" ",$aLabelledBy));
$newHtml = $dom->saveHtml();
$newHtml = $dom->saveHTMLExact();
$oEvent->set('answers',$newHtml);
}
......@@ -112,6 +125,11 @@ class moreAccessibility extends PluginBase
// @todo : list radio with coment with dropdown enabled and list radio with dropdown too sometimes
}
/**
* Add fieldset to multiple question or multiple answers, move quetsion text + help + tip to label
* @todo maybe leave part as place and use aria-labelledby but need a legend
*/
public function questionanswersFieldset()
{
if(!$this->get('addAnswersFieldSet'))
......@@ -145,6 +163,9 @@ class moreAccessibility extends PluginBase
}
}
/**
* Update the mandatory * to a clean string, according to question type
*/
public function mandatoryString()
{
if(!$this->get('updateAsterisk'))
......@@ -193,4 +214,85 @@ class moreAccessibility extends PluginBase
$oEvent->set('mandatory',CHtml::tag('span',array('id'=>"mandatory-{$oEvent->get('qid')}"),$sMandatoryText));
}
}
/*
* On checkbox list, when the "other" option is activated, hidden the checkbox and leave only label for other text
*/
public function checkboxLabelOther()
{
$oEvent=$this->getEvent();
$sType=$oEvent->get('type');
if(in_array($sType,array(
"M", // Input Checkbox List
)))
{
if (strpos( $oEvent->get('answers'), "othercbox") > 0) // Only do it if we have other : can be done with Question::model()->find
{
$sAnswerOtherTextId="answer{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}other";
$sAnswerOtherCboxId="answer{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}othercbox";
Yii::setPathOfAlias('archon810', dirname(__FILE__)."/vendor/archon810/smartdomdocument/src");
Yii::import('archon810.SmartDOMDocument');
$dom = new \archon810\SmartDOMDocument();
$dom->loadHTML($oEvent->get('answers'));
// Update the checkbox
$cbox=$dom->getElementById($sAnswerOtherCboxId);
$cbox->setAttribute("aria-hidden","true");
$cbox->setAttribute("tabindex","-1");
$cbox->setAttribute("readonly","readonly");// disabled broken by survey-runtime
// remove exiting script
while (($r = $dom->getElementsByTagName("script")) && $r->length) {
$r->item(0)->parentNode->removeChild($r->item(0));
}
$newHtml = $dom->saveHTMLExact();
$oEvent->set('answers',$newHtml);
// Add own script
$sMoreAccessibilityCheckboxLabelOtherScript="$(document).on('keyup focusout','#{$sAnswerOtherTextId}',function(){\n"
. " if ($.trim($(this).val()).length>0) { $('#{$sAnswerOtherCboxId}').prop('checked',true); } else { $('#{$sAnswerOtherCboxId}').prop('checked',false); }\n"
." $('#java{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}other').val($(this).val());LEMflagMandOther('{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}other',$('#{$sAnswerOtherCboxId}').is(':checked')); checkconditions($(this).val(), this.name, this.type);\n"
. "});\n"
. "$(document).on('click','#{$sAnswerOtherCboxId}',function(){\n"
. " $('#{$sAnswerOtherTextId}').focus();\n"
. "})\n";
App()->getClientScript()->registerScript('sMoreAccessibilityCheckboxLabelOtherScript',$sMoreAccessibilityCheckboxLabelOtherScript,CClientScript::POS_HEAD);
}
}
}
/*
* Fix labelling on other in radio list : use aria-labelledby for text input
* @link https://www.limesurvey.org/en/forum/plugins/100988-moreaccessibility#127710 Thanks to Alexandre Landry <forXcodeur@gmail.com>
*/
public function radioLabelOther()
{
$oEvent=$this->getEvent();
$sType=$oEvent->get('type');
if(in_array($sType,array(
"L", // Radio Button List
)))
{
if (strpos( $oEvent->get('answers'), 'id="SOTH') > 0) // Only do it if we have other : can be done with Question::model()->find
{
$sAnswerOtherTextId="answer{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}othertext";
$sAnswerOtherRadioId="SOTH{$oEvent->get('surveyId')}X{$oEvent->get('gid')}X{$oEvent->get('qid')}";
Yii::setPathOfAlias('archon810', dirname(__FILE__)."/vendor/archon810/smartdomdocument/src");
Yii::import('archon810.SmartDOMDocument');
$dom = new \archon810\SmartDOMDocument();
$dom->loadHTML($oEvent->get('answers'));
$elOtherText=$dom->getElementById($sAnswerOtherTextId);
$elOtherText->setAttribute("aria-labelledby","label-{$sAnswerOtherRadioId}");
$elOtherText->removeAttribute ('title');
foreach ($dom->getElementsByTagName('label') as $elLabel)
{
if($elLabel->getAttribute("for")==$sAnswerOtherRadioId)
$elLabel->setAttribute('id',"label-{$sAnswerOtherRadioId}");
if($elLabel->getAttribute("for")==$sAnswerOtherTextId)
{
$elLabel->parentNode->replaceChild($elOtherText, $elLabel);
}
}
$newHtml = $dom->saveHTMLExact();
$oEvent->set('answers',$newHtml);
}
}
}
}
smartdomdocument @ fd4c92a8
Subproject commit fd4c92a8e1fac4ce9a89b54ad1a6beafbda27fd9
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment