Skip to content

Commit

Permalink
Merge pull request #3 from squizlabs/MATRIX-702-lwr-insert-keyword
Browse files Browse the repository at this point in the history
MATRIX-702: Reinstate old method of enabling Keywords button as a backup for Select2-based method
  • Loading branch information
chiranjivi authored Feb 19, 2019
2 parents 8450d51 + 2224860 commit 69a46c1
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Plugins/MatrixKeywordsPlugin/MatrixKeywordsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,22 @@
var selectField = tools.getItem(prefix + ':insertKeywordSelect');
var select = document.getElementById(keywordSelectorElement);
tools.getItem(prefix + ':insertKeywordSelect').setHtml(select);
}
} else {
// Select2 isn't available (such as in Edit+). Go back to the
// old method, using the data-keywords array.
var datasetKeywords = ViperUtil.$(editableElement).data('keywords');
if (typeof datasetKeywords !== 'undefined' && datasetKeywords !== '') {
// make sure it's valid JSON associative array, not an array object.
if (typeof datasetKeywords.length === 'undefined') {
// enable button and insert those keywords as options
tools.enableButton('insertKeywords');
var selectField = tools.getItem(prefix + ':insertKeywordSelect');
if (selectField.getValue() === null) {
tools.getItem(prefix + ':insertKeywordSelect').setValue(datasetKeywords);
}
}
}
}

// get snippet for current div
var datasetSnippets = ViperUtil.$(editableElement).data('snippets');
Expand All @@ -109,7 +124,20 @@
var selectField = tools.getItem(prefix + ':insertSnippetSelect');
var select = document.getElementById(snippetSelectorElement);
tools.getItem(prefix + ':insertSnippetSelect').setHtml(select);
}
} else {
// Select2 not available.
var datasetSnippets = ViperUtil.$(editableElement).data('snippets');
if (typeof datasetSnippets !== 'undefined' && datasetSnippets !== '') {
if (typeof datasetSnippets.length === 'undefined') {
// enable button and insert those snippets as options
tools.enableButton('insertSnippets');
var selectField = tools.getItem(prefix + ':insertSnippetSelect');
if (selectField.getValue() === null) {
tools.getItem(prefix + ':insertSnippetSelect').setValue(datasetSnippets);
}
}
}
}
});

/** Fix for an issue where clicking on the Select2 scrollbar was
Expand Down

0 comments on commit 69a46c1

Please sign in to comment.