Dashboard > People > codesmell > 2008 > Juni > 15 > Another Richtext-editor in Wicket called NicEdit
  codesmell Log In   View a printable version of the current page.  
  Another Richtext-editor in Wicket called NicEdit
Added by Uwe Schaefer, last edited by Uwe Schaefer on Jun 23, 2008  (view change)
Labels: 

Just another Gem from the Wicket-Mailinglist:

[Update: see comments for updated Version]


francisco.treacy wrote:

i thought i'd like to share a simple behaviour for NicEdit
(http://nicedit.com/).

to use it, just download nicedit and modify NICEDIT_JAVASCRIPT and NICEDIT_ICONS accordingly. (i chose to put them together in the same
package). if you download the basic version (without xhtml/ code view), when adding the behaviour pass 'false' into the constructor, in order not
to use the full panel. of course, you can use it with multiple textareas in the same page.

francisco

public class NicEditTextAreaBehavior extends AbstractBehavior {

	private Component<TextArea<String>> textArea;
	private Boolean fullPanel = Boolean.TRUE;
	
	private static final ResourceReference NICEDIT_JAVASCRIPT =
		new JavascriptResourceReference(NicEditTextAreaBehavior.class, "nicEdit.js");
	
	private static final ResourceReference NICEDIT_ICONS = new
ResourceReference(NicEditTextAreaBehavior.class,
		"nicEditorIcons.gif");
	
	public NicEditTextAreaBehavior() {
	}
	
	public NicEditTextAreaBehavior(Boolean fullPanel) {
		this.fullPanel = fullPanel;
	}	
	
	@Override @SuppressWarnings("unchecked")
	public void bind(Component component) {
		this.textArea = component;
		component.setOutputMarkupId(true);
	}
	
	@Override
	public void renderHead(IHeaderResponse response) {
		super.renderHead(response);
		response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
		response.renderOnDomReadyJavascript("new nicEditor({iconsPath : '"+
RequestCycle.get().urlFor(
				NICEDIT_ICONS) +"', fullPanel : "+ fullPanel +"}).panelInstance('"
+ textArea.getMarkupId() + "');");
	}
}

hi uwe,

nice post, but this is a gem that doesn't work

 please follow the thread here: http://www.nabble.com/Re%3A-NicEditTextAreaBehavior-p17917729.html&nbsp; and update the code.

thanks!

francisco

Posted by Anonymous at Jun 23, 2008 01:49 | Permalink | Reply To This

Thx for keeping me updated. I´ll qoute it here for completeness:

so here i came up with a new version that works (i believe with ajax
only, and with one textarea for the moment). i'm by no means an ajax
expert (hmm, in fact, i dislike javascript so this is a call to
wicket ajax gurus: could you help me improve this code?

usage:

(...)
final NicEditTextAreaBehavior behavior = new NicEditTextAreaBehavior();
textarea.add(behavior);
(...)

form.add(new AjaxFallbackButton("submit", form) {
                       
                        @Override
                        protected IAjaxCallDecorator getAjaxCallDecorator() {
                                return behavior.NICEDIT_AJAX_BUTTON_DECORATOR;
                        }

    (...)

});

(...)




public class NicEditTextAreaBehavior extends AbstractAjaxBehavior {

        private Boolean fullPanel = Boolean.TRUE;
       
        private static final ResourceReference NICEDIT_JAVASCRIPT =
                new JavascriptResourceReference(NicEditTextAreaBehavior.class, "nicEdit.js");
       
        private static final ResourceReference NICEDIT_ICONS = new
ResourceReference(NicEditTextAreaBehavior.class,
                "nicEditorIcons.gif");
       
        public static final AjaxCallDecorator NICEDIT_AJAX_BUTTON_DECORATOR =
new AjaxCallDecorator() {
        @Override
        public CharSequence decorateScript(final CharSequence script) {
                return
"wicketNicEditor.nicInstances[0].saveContent();" + script;
        }
        };
       
        public NicEditTextAreaBehavior() {
        }
       
        public NicEditTextAreaBehavior(Boolean fullPanel) {
                this.fullPanel = fullPanel;
        }
       
        @Override
        protected void onBind() {
                super.onBind();
                getComponent().setOutputMarkupId(true);
        }
       
        @Override
        public void onRequest() {
        }
       
        @Override
        public void renderHead(IHeaderResponse response) {
                super.renderHead(response);
                response.renderJavascriptReference(NICEDIT_JAVASCRIPT);
                response.renderJavascript("var wicketNicEditor; function
wicketNicEditorUpdate() {
wicketNicEditor.nicInstances[0].saveContent(); };", null);
                response.renderOnDomReadyJavascript("wicketNicEditor = new
nicEditor({iconsPath : '"+ RequestCycle.get().urlFor(
                                NICEDIT_ICONS) +"', fullPanel : "+ fullPanel +"}).panelInstance('"
+ getComponent().getMarkupId() + "');");
        }

}
Posted by Uwe Schaefer at Jun 23, 2008 08:25 | Permalink | Reply To This
Juni 2008
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

protected Constructors
AnchoredBookmarkablePageLink

This site is powered by a free Atlassian Confluence Personal Server License. Evaluate Confluence for your organisation or read more about Confluence licensing here.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators