diff options
-rw-r--r-- | askbot/skins/common/media/js/post.js | 52 | ||||
-rw-r--r-- | askbot/skins/common/media/js/wmd/wmd.css | 22 | ||||
-rw-r--r-- | askbot/skins/common/media/js/wmd/wmd.js | 343 | ||||
-rw-r--r-- | askbot/skins/common/templates/widgets/edit_post.html | 6 | ||||
-rw-r--r-- | askbot/skins/default/media/style/style.less | 59 | ||||
-rw-r--r-- | askbot/views/writers.py | 1 |
6 files changed, 296 insertions, 187 deletions
diff --git a/askbot/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js index c597e84c..9f417642 100644 --- a/askbot/skins/common/media/js/post.js +++ b/askbot/skins/common/media/js/post.js @@ -1914,24 +1914,44 @@ QASwapper.prototype.startSwapping = function(){ var WMD = function(){ WrappedElement.call(this); this._markdown = undefined; + this._enabled_buttons = 'bold italic link blockquote code ' + + 'image ol ul heading hr'; + this._is_previewer_enabled = true; }; inherits(WMD, WrappedElement); +WMD.prototype.setEnabledButtons = function(buttons){ + this._enabled_buttons = buttons; +}; + +WMD.prototype.setPreviewerEnabled = function(state){ + this._is_previewer_enabled = state; + if (this._previewer){ + this._previewer.hide(); + } +}; + WMD.prototype.setEscapeHandler = function(handler){ this._escape_handler = handler; }; WMD.prototype.createDom = function(){ this._element = this.makeElement('div'); + var clearfix = this.makeElement('div').addClass('clearfix'); + this._element.append(clearfix); + + var wmd_container = this.makeElement('div'); + wmd_container.addClass('wmd-container'); + this._element.append(wmd_container); var wmd_buttons = this.makeElement('div') .attr('id', 'wmd-button-bar') .addClass('wmd-panel'); - this._element.append(wmd_buttons); + wmd_container.append(wmd_buttons); var editor = this.makeElement('textarea') .attr('id', 'editor'); - this._element.append(editor); + wmd_container.append(editor); this._textarea = editor; if (this._markdown){ @@ -1941,8 +1961,11 @@ WMD.prototype.createDom = function(){ var previewer = this.makeElement('div') .attr('id', 'previewer') .addClass('wmd-preview'); - - this._element.append(previewer); + wmd_container.append(previewer); + this._previewer = previewer; + if (this._is_previewer_enabled === false) { + previewer.hide(); + } }; WMD.prototype.setMarkdown = function(text){ @@ -1957,7 +1980,7 @@ WMD.prototype.getMarkdown = function(){ }; WMD.prototype.start = function(){ - Attacklab.Util.startEditor(true); + Attacklab.Util.startEditor(true, this._enabled_buttons); this._textarea.keyup(makeKeyHandler(27, this._escape_handler)); }; @@ -1969,6 +1992,8 @@ var TagWikiEditor = function(){ this._state = 'display';//'edit' or 'display' this._content_backup = ''; this._is_editor_loaded = false; + this._enabled_editor_buttons = null; + this._is_previewer_enabled = false; }; inherits(TagWikiEditor, WrappedElement); @@ -1976,6 +2001,17 @@ TagWikiEditor.prototype.backupContent = function(){ this._content_backup = this._content_box.contents(); }; +TagWikiEditor.prototype.setEnabledEditorButtons = function(buttons){ + this._enabled_editor_buttons = buttons; +}; + +TagWikiEditor.prototype.setPreviewerEnabled = function(state){ + this._is_previewer_enabled = state; + if (this.isEditorLoaded()){ + this._editor.setPreviewerEnabled(this._is_previewer_enabled); + } +}; + TagWikiEditor.prototype.setContent = function(content){ this._content_box.empty(); this._content_box.append(content); @@ -2095,6 +2131,10 @@ TagWikiEditor.prototype.decorate = function(element){ var me = this; var editor = new WMD(); + if (this._enabled_editor_buttons){ + editor.setEnabledButtons(this._enabled_editor_buttons); + } + editor.setPreviewerEnabled(this._is_previewer_enabled); editor.setEscapeHandler(function(){me.cancelEdit()}); this._editor = editor; setupButtonEventHandlers(edit_btn, function(){ me.startActivatingEditor() }); @@ -2268,6 +2308,8 @@ UserGroupProfileEditor.prototype.toggleEmailModeration = function(){ }; UserGroupProfileEditor.prototype.decorate = function(element){ + this.setEnabledEditorButtons('bold italic link ol ul'); + this.setPreviewerEnabled(false); UserGroupProfileEditor.superClass_.decorate.call(this, element); var change_logo_btn = element.find('.change-logo'); this._change_logo_btn = change_logo_btn; diff --git a/askbot/skins/common/media/js/wmd/wmd.css b/askbot/skins/common/media/js/wmd/wmd.css index 3ad615e7..678d70f3 100644 --- a/askbot/skins/common/media/js/wmd/wmd.css +++ b/askbot/skins/common/media/js/wmd/wmd.css @@ -10,12 +10,9 @@ #wmd-button-bar { background: url(images/editor-toolbar-background.png) repeat-x bottom; - height:36px; - border-left:#cce6ec 3px solid; - border-top:#cce6ec 3px solid; - border-right:#cce6ec 3px solid; - float:left; - width:730px; + height: 30px; + border: 0; + display: block; } #wmd-input @@ -39,10 +36,7 @@ #wmd-button-row { position: relative; - margin-left: 5px; - margin-right: 5px; - margin-bottom: 0px; - margin-top: 10px; + margin: 10px 2px 0 2px; padding: 0px; height: 20px; } @@ -51,9 +45,9 @@ { width: 1px; height: 20px; - margin-left: 14px; - - position: absolute; + margin-left: 2px; + margin-right: 4px; + /*position: absolute;*/ background-color: Silver; display: inline-block; list-style: none; @@ -66,7 +60,7 @@ margin-left: 5px; margin-right: 5px; - position: absolute; + /*position: absolute;*/ background-image: url(images/wmd-buttons.png); background-repeat: no-repeat; background-position: 0px 0px; diff --git a/askbot/skins/common/media/js/wmd/wmd.js b/askbot/skins/common/media/js/wmd/wmd.js index 90b59a56..19f32c87 100644 --- a/askbot/skins/common/media/js/wmd/wmd.js +++ b/askbot/skins/common/media/js/wmd/wmd.js @@ -69,7 +69,7 @@ Attacklab.wmdBase = function(){ var helpLink = "http://wmd-editor.com/"; var helpHoverTitle = "WMD website"; var helpTarget = "_blank"; - var localUploadFileName = null; + var localUploadFileName = null; // ------------------------------------------------------------------- // END OF YOUR CHANGES @@ -849,6 +849,11 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ var creationHandle; var undoMgr; // The undo manager + + var isButtonUsed = function(button){ + var buttons = $.trim(wmd.wmd_env.buttons).split(/\s+/); + return $.inArray(button, buttons) !== -1; + }; // Perform the button's action. var doClick = function(button){ @@ -971,159 +976,198 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ buttonRow.id = "wmd-button-row"; buttonRow = buttonBar.appendChild(buttonRow); + if (isButtonUsed('bold')){ + var boldButton = document.createElement("li"); + boldButton.className = "wmd-button"; + boldButton.id = "wmd-bold-button"; + boldButton.title = toolbar_strong_label; + boldButton.XShift = "0px"; + boldButton.textOp = command.doBold; + setupButton(boldButton, true); + buttonRow.appendChild(boldButton); + } - var boldButton = document.createElement("li"); - boldButton.className = "wmd-button"; - boldButton.id = "wmd-bold-button"; - boldButton.title = toolbar_strong_label; - boldButton.XShift = "0px"; - boldButton.textOp = command.doBold; - setupButton(boldButton, true); - buttonRow.appendChild(boldButton); - - var italicButton = document.createElement("li"); - italicButton.className = "wmd-button"; - italicButton.id = "wmd-italic-button"; - italicButton.title = toolbar_emphasis_label; - italicButton.XShift = "-20px"; - italicButton.textOp = command.doItalic; - setupButton(italicButton, true); - buttonRow.appendChild(italicButton); + if (isButtonUsed('italic')){ + var italicButton = document.createElement("li"); + italicButton.className = "wmd-button"; + italicButton.id = "wmd-italic-button"; + italicButton.title = toolbar_emphasis_label; + italicButton.XShift = "-20px"; + italicButton.textOp = command.doItalic; + setupButton(italicButton, true); + buttonRow.appendChild(italicButton); + } - var spacer1 = document.createElement("li"); - spacer1.className = "wmd-spacer"; - spacer1.id = "wmd-spacer1"; - buttonRow.appendChild(spacer1); + if ( + isButtonUsed('link') || + isButtonUsed('blockquote') || + isButtonUsed('code') || + isButtonUsed('image') || + isButtonUsed('attachment') + ) { + var spacer1 = document.createElement("li"); + spacer1.className = "wmd-spacer"; + spacer1.id = "wmd-spacer1"; + buttonRow.appendChild(spacer1); + } - var linkButton = document.createElement("li"); - linkButton.className = "wmd-button"; - linkButton.id = "wmd-link-button"; - linkButton.title = toolbar_hyperlink_label; - linkButton.XShift = "-40px"; - linkButton.textOp = function(chunk, postProcessing){ - return command.doLinkOrImage(chunk, postProcessing, 'link'); - }; - setupButton(linkButton, true); - buttonRow.appendChild(linkButton); + if (isButtonUsed('link')){ + var linkButton = document.createElement("li"); + linkButton.className = "wmd-button"; + linkButton.id = "wmd-link-button"; + linkButton.title = toolbar_hyperlink_label; + linkButton.XShift = "-40px"; + linkButton.textOp = function(chunk, postProcessing){ + return command.doLinkOrImage(chunk, postProcessing, 'link'); + }; + setupButton(linkButton, true); + buttonRow.appendChild(linkButton); + } - var quoteButton = document.createElement("li"); - quoteButton.className = "wmd-button"; - quoteButton.id = "wmd-quote-button"; - quoteButton.title = toolbar_blockquote_label; - quoteButton.XShift = "-60px"; - quoteButton.textOp = command.doBlockquote; - setupButton(quoteButton, true); - buttonRow.appendChild(quoteButton); - - var codeButton = document.createElement("li"); - codeButton.className = "wmd-button"; - codeButton.id = "wmd-code-button"; - codeButton.title = toolbar_code_label; - codeButton.XShift = "-80px"; - codeButton.textOp = command.doCode; - setupButton(codeButton, true); - buttonRow.appendChild(codeButton); + if (isButtonUsed('blockquote')){ + var quoteButton = document.createElement("li"); + quoteButton.className = "wmd-button"; + quoteButton.id = "wmd-quote-button"; + quoteButton.title = toolbar_blockquote_label; + quoteButton.XShift = "-60px"; + quoteButton.textOp = command.doBlockquote; + setupButton(quoteButton, true); + buttonRow.appendChild(quoteButton); + } + + if (isButtonUsed('code')){ + var codeButton = document.createElement("li"); + codeButton.className = "wmd-button"; + codeButton.id = "wmd-code-button"; + codeButton.title = toolbar_code_label; + codeButton.XShift = "-80px"; + codeButton.textOp = command.doCode; + setupButton(codeButton, true); + buttonRow.appendChild(codeButton); + } - var imageButton = document.createElement("li"); - imageButton.className = "wmd-button"; - imageButton.id = "wmd-image-button"; - imageButton.title = toolbar_image_label; - imageButton.XShift = "-100px"; - imageButton.textOp = function(chunk, postProcessing){ - return command.doLinkOrImage(chunk, postProcessing, 'image'); - }; - setupButton(imageButton, true); - buttonRow.appendChild(imageButton); + if (isButtonUsed('image')){ + var imageButton = document.createElement("li"); + imageButton.className = "wmd-button"; + imageButton.id = "wmd-image-button"; + imageButton.title = toolbar_image_label; + imageButton.XShift = "-100px"; + imageButton.textOp = function(chunk, postProcessing){ + return command.doLinkOrImage(chunk, postProcessing, 'image'); + }; + setupButton(imageButton, true); + buttonRow.appendChild(imageButton); + } - var attachmentButton = document.createElement("li"); - attachmentButton.className = "wmd-button"; - attachmentButton.id = "wmd-attachment-button"; - attachmentButton.title = toolbar_attachment_label; - attachmentButton.XShift = "-120px"; - attachmentButton.textOp = function(chunk, postProcessing){ - return command.doLinkOrImage(chunk, postProcessing, 'file'); - }; - setupButton(attachmentButton, true); - buttonRow.appendChild(attachmentButton); + if (isButtonUsed('attachment')){ + var attachmentButton = document.createElement("li"); + attachmentButton.className = "wmd-button"; + attachmentButton.id = "wmd-attachment-button"; + attachmentButton.title = toolbar_attachment_label; + attachmentButton.XShift = "-120px"; + attachmentButton.textOp = function(chunk, postProcessing){ + return command.doLinkOrImage(chunk, postProcessing, 'file'); + }; + setupButton(attachmentButton, true); + buttonRow.appendChild(attachmentButton); + } - var spacer2 = document.createElement("li"); - spacer2.className = "wmd-spacer"; - spacer2.id = "wmd-spacer2"; - buttonRow.appendChild(spacer2); + if ( + isButtonUsed('ol') || + isButtonUsed('ul') || + isButtonUsed('heading') || + isButtonUsed('hr') + ) { + var spacer2 = document.createElement("li"); + spacer2.className = "wmd-spacer"; + spacer2.id = "wmd-spacer2"; + buttonRow.appendChild(spacer2); + } - var olistButton = document.createElement("li"); - olistButton.className = "wmd-button"; - olistButton.id = "wmd-olist-button"; - olistButton.title = toolbar_numbered_label; - olistButton.XShift = "-140px"; - olistButton.textOp = function(chunk, postProcessing){ - command.doList(chunk, postProcessing, true); - }; - setupButton(olistButton, true); - buttonRow.appendChild(olistButton); - - var ulistButton = document.createElement("li"); - ulistButton.className = "wmd-button"; - ulistButton.id = "wmd-ulist-button"; - ulistButton.title = toolbar_bulleted_label; - ulistButton.XShift = "-160px"; - ulistButton.textOp = function(chunk, postProcessing){ - command.doList(chunk, postProcessing, false); - }; - setupButton(ulistButton, true); - buttonRow.appendChild(ulistButton); - - var headingButton = document.createElement("li"); - headingButton.className = "wmd-button"; - headingButton.id = "wmd-heading-button"; - headingButton.title = toolbar_heading_label; - headingButton.XShift = "-180px"; - headingButton.textOp = command.doHeading; - setupButton(headingButton, true); - buttonRow.appendChild(headingButton); - - var hrButton = document.createElement("li"); - hrButton.className = "wmd-button"; - hrButton.id = "wmd-hr-button"; - hrButton.title = toolbar_horizontal_label; - hrButton.XShift = "-200px"; - hrButton.textOp = command.doHorizontalRule; - setupButton(hrButton, true); - buttonRow.appendChild(hrButton); - - var spacer3 = document.createElement("li"); - spacer3.className = "wmd-spacer"; - spacer3.id = "wmd-spacer3"; - buttonRow.appendChild(spacer3); - - var undoButton = document.createElement("li"); - undoButton.className = "wmd-button"; - undoButton.id = "wmd-undo-button"; - undoButton.title = toolbar_undo_label; - undoButton.XShift = "-220px"; - undoButton.execute = function(manager){ - manager.undo(); - }; - setupButton(undoButton, true); - buttonRow.appendChild(undoButton); + if (isButtonUsed('ol')) { + var olistButton = document.createElement("li"); + olistButton.className = "wmd-button"; + olistButton.id = "wmd-olist-button"; + olistButton.title = toolbar_numbered_label; + olistButton.XShift = "-140px"; + olistButton.textOp = function(chunk, postProcessing){ + command.doList(chunk, postProcessing, true); + }; + setupButton(olistButton, true); + buttonRow.appendChild(olistButton); + } - var redoButton = document.createElement("li"); - redoButton.className = "wmd-button"; - redoButton.id = "wmd-redo-button"; - redoButton.title = toolbar_redo_label; - if (/win/.test(nav.platform.toLowerCase())) { - redoButton.title = toolbar_redo_label; - } - else { - // mac and other non-Windows platforms - redoButton.title = gettext('redo') + " - Ctrl+Shift+Z"; - } - redoButton.XShift = "-240px"; - redoButton.execute = function(manager){ - manager.redo(); - }; - setupButton(redoButton, true); - buttonRow.appendChild(redoButton); + if (isButtonUsed('ul')) { + var ulistButton = document.createElement("li"); + ulistButton.className = "wmd-button"; + ulistButton.id = "wmd-ulist-button"; + ulistButton.title = toolbar_bulleted_label; + ulistButton.XShift = "-160px"; + ulistButton.textOp = function(chunk, postProcessing){ + command.doList(chunk, postProcessing, false); + }; + setupButton(ulistButton, true); + buttonRow.appendChild(ulistButton); + } + + if (isButtonUsed('heading')) { + var headingButton = document.createElement("li"); + headingButton.className = "wmd-button"; + headingButton.id = "wmd-heading-button"; + headingButton.title = toolbar_heading_label; + headingButton.XShift = "-180px"; + headingButton.textOp = command.doHeading; + setupButton(headingButton, true); + buttonRow.appendChild(headingButton); + } + + if (isButtonUsed('hr')) { + var hrButton = document.createElement("li"); + hrButton.className = "wmd-button"; + hrButton.id = "wmd-hr-button"; + hrButton.title = toolbar_horizontal_label; + hrButton.XShift = "-200px"; + hrButton.textOp = command.doHorizontalRule; + setupButton(hrButton, true); + buttonRow.appendChild(hrButton); + } + + if (isButtonUsed('undo')){ + var spacer3 = document.createElement("li"); + spacer3.className = "wmd-spacer"; + spacer3.id = "wmd-spacer3"; + buttonRow.appendChild(spacer3); + + var undoButton = document.createElement("li"); + undoButton.className = "wmd-button"; + undoButton.id = "wmd-undo-button"; + undoButton.title = toolbar_undo_label; + undoButton.XShift = "-220px"; + undoButton.execute = function(manager){ + manager.undo(); + }; + setupButton(undoButton, true); + buttonRow.appendChild(undoButton); + + var redoButton = document.createElement("li"); + redoButton.className = "wmd-button"; + redoButton.id = "wmd-redo-button"; + redoButton.title = toolbar_redo_label; + if (/win/.test(nav.platform.toLowerCase())) { + redoButton.title = toolbar_redo_label; + } + else { + // mac and other non-Windows platforms + redoButton.title = gettext('redo') + " - Ctrl+Shift+Z"; + } + redoButton.XShift = "-240px"; + redoButton.execute = function(manager){ + manager.redo(); + }; + setupButton(redoButton, true); + buttonRow.appendChild(redoButton); + setUndoRedoButtonStates(); + } /* var helpButton = document.createElement("li"); helpButton.className = "wmd-button"; @@ -1140,7 +1184,6 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ setupButton(helpButton, true); buttonRow.appendChild(helpButton); */ - setUndoRedoButtonStates(); }; var setupEditor = function(){ @@ -1149,7 +1192,7 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ wmd.nativeUndo = true; } - if (!wmd.nativeUndo) { + if (!wmd.nativeUndo && isButtonUsed('undo')) { undoMgr = new wmd.undoManager(function(){ previewRefreshCallback(); setUndoRedoButtonStates(); @@ -1817,13 +1860,17 @@ util.prompt = function(text, defaultInputText, makeLinkMarkdown, dialogType){ wmd.wmd.previewManager = wmd.previewManager; }; - util.startEditor = function(start_now){ + util.startEditor = function(start_now, buttons){ if (wmd.wmd_env.autostart === false) { util.makeAPI(); return; } + if (buttons){ + wmd.wmd_env.buttons = buttons; + } + var edit; // The editor (buttons + input + outputs) - the main object. var previewMgr; // The preview manager. diff --git a/askbot/skins/common/templates/widgets/edit_post.html b/askbot/skins/common/templates/widgets/edit_post.html index ee84f443..66f79237 100644 --- a/askbot/skins/common/templates/widgets/edit_post.html +++ b/askbot/skins/common/templates/widgets/edit_post.html @@ -7,9 +7,11 @@ </div> </div> {% endif %} -<div id="wmd-button-bar" class="wmd-panel"></div> -<div class="form-item"> +<div class='wmd-container'> + <div id="wmd-button-bar" class="wmd-panel"></div> {{ post_form.text }}{# this element is resizable and will be wrapped by js #} +</div> +<div class="form-item"> <label for="editor" class="form-error">{{ post_form.text.errors }}</label> </div> {# need label element for resizable input, b/c form validation won't find span #} diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less index d97de8ab..43f5be61 100644 --- a/askbot/skins/default/media/style/style.less +++ b/askbot/skins/default/media/style/style.less @@ -1296,11 +1296,11 @@ ul#related-tags li { margin: 0px; padding: 0px 0 0 5px; border:#cce6ec 3px solid; - width:725px; + width:719px; } } -.ask-page, .edit-question-page{ +.ask-page, .edit-question-page { div#question-list { float: none; @@ -1379,18 +1379,37 @@ ul#related-tags li { background: url(../images/medium-button.png) bottom repeat-x; .text-shadow(0px, 1px, 0px, #c6d9dd) } -#editor { /*adjustment for editor preview*/ + +.wmd-container { + border:#cce6ec 3px solid; +} +.users-page .wmd-container { + width: 200px; +} +.ask-page, +.question-page, +.edit-question-page, +.edit-answer-page { + .wmd-container { + width: 723px; + } + #editor { + width: 710px; + padding: 6px; + } +} + +#editor { /* adjustment for editor preview */ + display: block; font-size: 100%; min-height: 200px; line-height: 18px; - margin:0; - border-left:#cce6ec 3px solid; - border-bottom:#cce6ec 3px solid; - border-right:#cce6ec 3px solid; - border-top:0; - padding:10px; - margin-bottom:10px; - width:710px; + margin: 0; + border: 0; +} + +.users-page #editor { + width: 192px; } #id_title { @@ -1398,8 +1417,8 @@ ul#related-tags li { } .wmd-preview { - margin: 3px 0 5px 0; - padding: 6px; + margin: 0; + padding: 5px; background-color: #F5F5F5; min-height: 20px; overflow: auto; @@ -1407,9 +1426,13 @@ ul#related-tags li { font-family:@body-font; p{ - margin-bottom:14px; - line-height:1.4; - font-size:14px; + margin-bottom: 14px; + line-height: 1.4; + font-size: 14px; + } + + p:last-child{ + margin-bottom: 0; } } @@ -1482,7 +1505,7 @@ ul#related-tags li { margin: 0px; padding: 0px 0 0 5px; border:#cce6ec 3px solid; - width:725px; + width: 719px; margin-bottom:10px; } #id_summary{ @@ -3419,7 +3442,7 @@ body.anon.lang-es { .group-wiki { .content { - p:last-child { + > p:last-child { margin-bottom: 5px; } } diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 633c23f2..c77c874f 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -457,6 +457,7 @@ def edit_answer(request, id): revision_form = forms.RevisionForm(answer, latest_revision) form = forms.EditAnswerForm(answer, latest_revision) data = { + 'page_class': 'edit-answer-page', 'active_tab': 'questions', 'answer': answer, 'revision_form': revision_form, |