Commit 5ba3acb3 by Waheed Ahmed

Merge pull request #3847 from edx/waheed/cheatsheet-code-refactor

Cheatsheet visibility code refactored.
parents b2656bb2 6ad6f77c
...@@ -132,17 +132,11 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", ...@@ -132,17 +132,11 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal",
}, },
changeMode: function(event) { changeMode: function(event) {
this.removeCheatsheetVisibility();
var parent = $(event.target.parentElement), var parent = $(event.target.parentElement),
mode = parent.data('mode'); mode = parent.data('mode');
event.preventDefault(); event.preventDefault();
this.selectMode(mode); this.selectMode(mode);
var $cheatsheet = $('.simple-editor-cheatsheet');
if ($cheatsheet.length == 0){
$cheatsheet = $('.simple-editor-open-ended-cheatsheet');
}
$(".CodeMirror").css({"overflow": "none"});
$(".modal-content").removeAttr("style");
$cheatsheet.removeClass('shown');
}, },
selectMode: function(mode) { selectMode: function(mode) {
...@@ -204,6 +198,17 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal", ...@@ -204,6 +198,17 @@ define(["jquery", "underscore", "gettext", "js/views/modals/base_modal",
mode: mode, mode: mode,
displayName: displayName displayName: displayName
})); }));
},
removeCheatsheetVisibility: function() {
var cheatsheet = $('article.simple-editor-open-ended-cheatsheet');
if (cheatsheet.length === 0) {
cheatsheet = $('article.simple-editor-cheatsheet');
}
if (cheatsheet.hasClass('shown')) {
cheatsheet.removeClass('shown');
$('.modal-content').removeClass('cheatsheet-is-shown');
}
} }
}); });
......
...@@ -74,3 +74,11 @@ body b { ...@@ -74,3 +74,11 @@ body b {
* use the @include placeholder Bourbon mixin (http://bourbon.io/docs/#placeholder) for any placeholder styling * use the @include placeholder Bourbon mixin (http://bourbon.io/docs/#placeholder) for any placeholder styling
*/ */
.modal-content.cheatsheet-is-shown {
overflow: visible !important;
.CodeMirror {
overflow: visible !important;
}
}
\ No newline at end of file
...@@ -87,8 +87,9 @@ Write a persuasive essay to a newspaper reflecting your views on censorship in l ...@@ -87,8 +87,9 @@ Write a persuasive essay to a newspaper reflecting your views on censorship in l
### ###
onShowXMLButton: (e) => onShowXMLButton: (e) =>
e.preventDefault(); e.preventDefault();
if @cheatsheet != undefined if @cheatsheet && @cheatsheet.hasClass('shown')
@addRemoveCheatsheetCSS() @cheatsheet.toggleClass('shown')
@toggleCheatsheetVisibility()
if @confirmConversionToXml() if @confirmConversionToXml()
@createXMLEditor(OpenEndedMarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue())) @createXMLEditor(OpenEndedMarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue()))
# Need to refresh to get line numbers to display properly (and put cursor position to 0) # Need to refresh to get line numbers to display properly (and put cursor position to 0)
...@@ -133,21 +134,16 @@ Write a persuasive essay to a newspaper reflecting your views on censorship in l ...@@ -133,21 +134,16 @@ Write a persuasive essay to a newspaper reflecting your views on censorship in l
@cheatsheet = $($('#simple-editor-open-ended-cheatsheet').html()) @cheatsheet = $($('#simple-editor-open-ended-cheatsheet').html())
$(@markdown_editor.getWrapperElement()).append(@cheatsheet) $(@markdown_editor.getWrapperElement()).append(@cheatsheet)
@addRemoveCheatsheetCSS() @toggleCheatsheetVisibility()
setTimeout (=> @cheatsheet.toggleClass('shown')), 10 setTimeout (=> @cheatsheet.toggleClass('shown')), 10
### ###
Function to add/remove CSS for cheatsheet. Function to toggle cheatsheet visibility.
### ###
addRemoveCheatsheetCSS: () => toggleCheatsheetVisibility: () =>
if !@cheatsheet.hasClass("shown") $('.modal-content').toggleClass('cheatsheet-is-shown')
$(".CodeMirror").css({"overflow": "visible"})
$(".modal-content").css({"overflow-y": "visible", "overflow-x": "visible"})
else
$(".CodeMirror").css({"overflow": ""})
$(".modal-content").removeAttr("style")
### ###
......
...@@ -48,8 +48,9 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -48,8 +48,9 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
### ###
onShowXMLButton: (e) => onShowXMLButton: (e) =>
e.preventDefault(); e.preventDefault();
if @cheatsheet != undefined if @cheatsheet && @cheatsheet.hasClass('shown')
@addRemoveCheatsheetCSS() @cheatsheet.toggleClass('shown')
@toggleCheatsheetVisibility()
if @confirmConversionToXml() if @confirmConversionToXml()
@createXMLEditor(MarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue())) @createXMLEditor(MarkdownEditingDescriptor.markdownToXml(@markdown_editor.getValue()))
# Need to refresh to get line numbers to display properly (and put cursor position to 0) # Need to refresh to get line numbers to display properly (and put cursor position to 0)
...@@ -96,21 +97,16 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -96,21 +97,16 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
@cheatsheet = $($('#simple-editor-cheatsheet').html()) @cheatsheet = $($('#simple-editor-cheatsheet').html())
$(@markdown_editor.getWrapperElement()).append(@cheatsheet) $(@markdown_editor.getWrapperElement()).append(@cheatsheet)
@addRemoveCheatsheetCSS() @toggleCheatsheetVisibility()
setTimeout (=> @cheatsheet.toggleClass('shown')), 10 setTimeout (=> @cheatsheet.toggleClass('shown')), 10
### ###
Function to add/remove CSS for cheatsheet. Function to toggle cheatsheet visibility.
### ###
addRemoveCheatsheetCSS: () => toggleCheatsheetVisibility: () =>
if !@cheatsheet.hasClass("shown") $('.modal-content').toggleClass('cheatsheet-is-shown')
$(".CodeMirror").css({"overflow": "visible"})
$(".modal-content").css({"overflow-y": "visible", "overflow-x": "visible"})
else
$(".CodeMirror").css({"overflow": "none"})
$(".modal-content").removeAttr("style")
### ###
Stores the current editor and hides the one that is not displayed. Stores the current editor and hides the one that is not displayed.
......
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