Skip to content

Commit

Permalink
New feature: helper library to add contextual help.
Browse files Browse the repository at this point in the history
Dev: documentation will follow shortly. For a first preview go to edit question
  • Loading branch information
lacrioque authored and c-schmitz committed Feb 7, 2018
1 parent a43634a commit 1d3a633
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion application/controllers/admin/questions.php
Expand Up @@ -986,7 +986,7 @@ public function newquestion($surveyid)
Yii::app()->loadHelper('admin/htmleditor');
$aData = [];
$surveyid = $iSurveyID = $aData['surveyid'] = sanitize_int($surveyid);
// App()->getClientScript()->registerPackage('qTip2');
App()->getClientScript()->registerPackage('lshelp');
$survey = Survey::model()->findByPk($iSurveyID);

$aData['title_bar']['title'] = $survey->currentLanguageSettings->surveyls_title." (".gT("ID").":".$iSurveyID.")";
Expand Down
4 changes: 2 additions & 2 deletions application/views/admin/survey/Question/editQuestion_view.php
Expand Up @@ -166,7 +166,7 @@
<input type="hidden" id="question_type" name="type" value="<?php echo $oQuestion->type; ?>" />

<?php if( $activated != "Y" && isset($selectormodeclass) && $selectormodeclass != "none"): ?>
<label class=" control-label" for="question_type_button" title="<?php eT("Question type");?>" data-gethelp='{ "title":"Get help", "text" : "More on questions", "href":"https://manual.limesurvey.org/Questions_-_introduction" }' data-helptitle="<?php eT("Question type");?>" data-help="<?=gT("Select the question type here.")?>">
<label class=" control-label" for="question_type_button" title="<?php eT("Question type");?>" data-gethelp='{ "title":"Get help", "text" : "More on questions", "href":"https://manual.limesurvey.org/Questions_-_introduction" }' data-help="<?=gT("Select the question type here.")?>">
<?php
eT("Question type:");
?>
Expand Down Expand Up @@ -263,7 +263,7 @@
</div>

<div class="form-group">
<label class=" control-label" for='relevance' title="<?php eT("Relevance equation");?>"><?php eT("Relevance equation:"); ?></label>
<label class=" control-label" for='relevance' title="<?php eT("Relevance equation");?>" data-gethelp='{ "title":"Get help", "text" : "More on relevance and the EM", "href":"https://manual.limesurvey.org/Expression_Manager" }' data-help="<?=gT("The relevance equation can be used to add branching logic. This is a rather advanced topic. If you are unsure, just leave it be.")?>"><?php eT("Relevance equation:"); ?></label>
<div class="">
<div class="input-group">
<div class="input-group-addon">{</div>
Expand Down
17 changes: 8 additions & 9 deletions assets/packages/lshelp/build/lshelper.js
Expand Up @@ -27,7 +27,6 @@ var popoverTemplate = function popoverTemplate(replacements) {

/* globals jQuery,ConsoleShim */
var LimeHelper = function LimeHelper(action, options) {
var _this = this;

var settings = {},
getTemplates = {};
Expand All @@ -54,30 +53,30 @@ var LimeHelper = function LimeHelper(action, options) {
return $.extend({}, defaults, options);
},
_addIcon = function _addIcon(element) {
$(element).append($(settings.helpIcon));
$(element).append('&nbsp;').append($(settings.helpIcon));
},
_createPopover = function _createPopover(element) {

var content = $(_this).data(settings.helpTextData);
var content = $(element).data(settings.helpTextData);

if (content == '') {
content = $(_this).attr('title');
content = $(element).attr('title');
}

if ($(_this).data(settings.helpLinkData)) {
content += getTemplates.moreTemplate($(_this).data(settings.helpLinkData));
if ($(element).data(settings.helpLinkData)) {
content += getTemplates.moreTemplate($(element).data(settings.helpLinkData));
}

var popoverObject = {
content: content,
html: true,
template: getTemplates.basicTemplate(),
trigger: (settings.onHover ? 'hover ' : '') + (settings.onClick ? 'click ' : '') + 'manual',
title: $(_this).data(settings.helpTextTitle) || ''
title: $(element).data(settings.helpTextTitle) || $(element).attr('title') || ''
};

logger.log("Popover object", popoverObject);
logger.log("This element", $(_this).data());
logger.log("This element", $(element).data());
$(element).find('.selector__lshelp').popover(popoverObject);
},
_bindActions = function _bindActions(element) {
Expand All @@ -102,7 +101,7 @@ var LimeHelper = function LimeHelper(action, options) {
//define public methods
var init = function init() {
settings = _parseOptions(options);
getTemplates = popoverTemplate();
getTemplates = popoverTemplate({ more: '' });
elements.each(function (i, element) {
_addIcon(element);
_createPopover(element);
Expand Down
2 changes: 1 addition & 1 deletion assets/packages/lshelp/build/lshelper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions assets/packages/lshelp/src/LimeHelper.js
Expand Up @@ -29,30 +29,30 @@ const LimeHelper = function(action, options){
return $.extend({},defaults,options);
},
_addIcon = (element)=>{
$(element).append($(settings.helpIcon));
$(element).append('&nbsp;').append($(settings.helpIcon));
},
_createPopover = (element) => {

let content = $(this).data(settings.helpTextData);
let content = $(element).data(settings.helpTextData);

if(content == '') {
content = $(this).attr('title');
content = $(element).attr('title');
}

if($(this).data(settings.helpLinkData)) {
content += getTemplates.moreTemplate($(this).data(settings.helpLinkData));
if($(element).data(settings.helpLinkData)) {
content += getTemplates.moreTemplate($(element).data(settings.helpLinkData));
}

let popoverObject = {
content: content,
html: true,
template : getTemplates.basicTemplate(),
trigger : (settings.onHover ? 'hover ' : '') + (settings.onClick ? 'click ': '') + 'manual',
title: $(this).data(settings.helpTextTitle) || ''
title: $(element).data(settings.helpTextTitle) || $(element).attr('title') || ''
};

logger.log("Popover object", popoverObject);
logger.log("This element", $(this).data());
logger.log("This element", $(element).data());
$(element).find('.selector__lshelp').popover(popoverObject);
},
_bindActions = (element)=>{
Expand Down Expand Up @@ -81,7 +81,7 @@ const LimeHelper = function(action, options){
const
init = () => {
settings = _parseOptions(options);
getTemplates = popoverTemplate();
getTemplates = popoverTemplate({more: ''});
elements.each((i, element) => {
_addIcon(element);
_createPopover(element);
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/admin/questions.js
Expand Up @@ -181,7 +181,7 @@ function updatequestionattributes() {
success: function (data) {
$('.loader-advancedquestionsettings').before(data);
$('.loader-advancedquestionsettings').addClass("hidden");
$('label[data-help]').limeHelper('init', {onHover: false});
$('label[data-help]').limeHelper('init', {onHover: false, helpIcon: '<i class="fa fa-question-circle text-primary selector__lshelp lshelp-help-icon"></i>'});
renderBootstrapSwitch();
}
});
Expand Down

1 comment on commit 1d3a633

@maziminke
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RE "documentation will follow shortly.": Where can we find more details?

Please sign in to comment.