Mercurial > libervia-web
diff browser_side/base_panels.py @ 395:98cd5387d291
browser_side: new microblogs are not using the rich text editor by default:
- a button allows to switch from raw to rich text, and vice versa
- raw text microblogs are not submitted anymore when the focus is lost, only when <enter> is pressed
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 10 Mar 2014 22:39:26 +0100 |
parents | 30d03d9f07e4 |
children | 487dd238ab88 |
line wrap: on
line diff
--- a/browser_side/base_panels.py Thu Mar 06 01:06:19 2014 +0100 +++ b/browser_side/base_panels.py Mon Mar 10 22:39:26 2014 +0100 @@ -343,6 +343,20 @@ """ raise NotImplementedError + def setOriginalContent(self, content): + """Use this method with care! Content initialization should normally be + done with self.setContent. This method exists to let you trick the editor, + e.g. for self.modified to return True also when nothing has been modified. + @param content: dict + """ + self._original_content = content + + def getOriginalContent(self): + """ + @return the original content before modification (dict) + """ + return self._original_content + def modified(self, content=None): """Check if the content has been modified. Remark: we don't use the direct comparison because we want to ignore empty elements @@ -424,21 +438,24 @@ class LightTextEditor(BaseTextEditor, HTML, FocusHandler, KeyboardHandler): """Manage a simple text editor whith the HTML 5 "contenteditable" property.""" - def __init__(self, content=None, modifiedCb=None, afterEditCb=None, single_line=False, enhance_display=True): + def __init__(self, content=None, modifiedCb=None, afterEditCb=None, single_line=False, enhance_display=True, listen_focus=None): """ @param content @param modifiedCb @param afterEditCb - @param single_line: set to True to manage a single line editor. In that case - the edition would be terminated when the focus is lost or <enter> key is pressed. + @param single_line: set to True to manage a single line editor. In that + case the edition will be terminated when the <enter> key is pressed. + @param listen_focus: set to True to terminate the edition when the + focus is lost. Leave to None in order to use single_line's value. @param enhance_display: if True, the display text will be enhanced with addURLToText """ HTML.__init__(self) - if single_line: + self.__single_line = single_line + self.__enhance_display = enhance_display + self.__listen_focus = single_line if listen_focus is None else listen_focus + if self.__listen_focus: FocusHandler.__init__(self) KeyboardHandler.__init__(self) - self.__single_line = single_line - self.__enhance_display = enhance_display strproc = lambda text: html_sanitize(html_strip(text)) if self.__single_line else html_strip(text) BaseTextEditor.__init__(self, content, strproc, modifiedCb, afterEditCb) @@ -455,12 +472,12 @@ self.getElement().setAttribute('contenteditable', 'true' if edit else 'false') BaseTextEditor.edit(self, edit) if edit: - if self.__single_line: + if self.__listen_focus: self.addFocusListener(self) self.addKeyboardListener(self) else: self.setDisplayContent() - if self.__single_line: + if self.__listen_focus: if self in self._focusListeners: self.removeFocusListener(self) if self in self._keyboardListeners: @@ -483,8 +500,10 @@ def onKeyPress(self, sender, keycode, modifiers): if not self.__single_line: return - if keycode == KEY_ENTER: - self.setFocus(False) # finish the edition + if keycode == KEY_ENTER: # finish the edition + self.setFocus(False) + if not self.__listen_focus: + self.edit(False) def onLostFocus(self, sender): """Finish the edition when focus is lost"""