Fckeditor Plugin

Cannot invoke FCK editor as a method properly.

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: Grails-Fckeditor 0.9.2
  • Fix Version/s: Grails-Fckeditor 0.9.4
  • Component/s: None
  • Labels:
    None
  • Patch Submitted:
    Yes

Description

It is not currently possible to invoke the FCK editor as a function call, which is needed if for example you are wrapping the tag with another taglib. Due to a bug in Grails the initialValue of the editor is immediately output to the response before the fck editor HTML is written.

I have a patch:

1) Change editor tag's last line to not do out << editor.createEditor() - instead just do editor.renderEditor (no out <<)
2) Remove createEditor from FckEditor.groovy and replace it with:

def renderEditor(out) {
        def skipBrowserCheck = ConfigurationHolder.config.fckeditor.skipBrowserCheck ?: false

		def userAgent = request.getHeader("user-agent")
		def bd = new BrowserDetector(userAgent)
		
		if (skipBrowserCheck || bd.isCompatible(COMPATIBLE_BROWSERS)) {
    		out << "<div><input type=\"hidden\" id=\"${instanceName}\" name=\"${instanceName}\" value=\""
    		if (!(initialValue instanceof String)) {
    		    initialValue() // Grails 1.1.x bugs write out immediately without encodeAsHTML support 
    		} else {
    		    out << initialValue.encodeAsHTML()
    		}
    		out << """
    		"><input type="hidden" id="${instanceName}___Config" value="${configField}"/>
    			<iframe id="${instanceName}___Frame" src="${basePath}/js/fckeditor/editor/fckeditor.html?InstanceName=${instanceName}&Toolbar=${toolbar}" width="${width}" height="${height}" frameborder="no" scrolling="no"></iframe>
    		</div>
    		"""
    	} else {
            out << """
    		<div>
    			<textarea name="${instanceName}" rows="4" cols="40" style="width: 100%; height: 200px; wrap="virtual">
    	    """
    		if (!(initialValue instanceof String)) {
    		    initialValue() // Grails 1.1.x bugs write out immediately without encodeAsHTML support
    		} else {
    		    out << initialValue.encodeAsHTML()
    		}
    		out << """</textarea>
    		    </div>
		    """
		}
	}

This is also better than the existing code that builds both compatible and standard HTML before checking which version the browser wants - a complete waste of processing

Activity

Hide
Stefano Gualdi added a comment -

Hi Marc,

thank you very much for the patch.

I've implemented your solution but with some changes.

The snapshot version can be downloaded from here: http://gualdi.org/grails-fckeditor-0.9.3-SNAPSHOT.zip

To resolve the missing encoding when calling the tag as a function you should use the following code:

class TestTagLib {

    def myeditor = { attrs, body ->
        out << "Before" << fckeditor.editor(attrs, body().encodeAsHTML()) << "After"
    }
}

please let me know if everything works for you so I can release the new version.

Show
Stefano Gualdi added a comment - Hi Marc, thank you very much for the patch. I've implemented your solution but with some changes. The snapshot version can be downloaded from here: http://gualdi.org/grails-fckeditor-0.9.3-SNAPSHOT.zip To resolve the missing encoding when calling the tag as a function you should use the following code:
class TestTagLib {

    def myeditor = { attrs, body ->
        out << "Before" << fckeditor.editor(attrs, body().encodeAsHTML()) << "After"
    }
}
please let me know if everything works for you so I can release the new version.
Hide
Stefano Gualdi added a comment -

In grails 1.2-M1 the workaround for missing encoding is no more necessary, you can write:

class TestTagLib {

    def myeditor = { attrs, body ->
        out << "Before" << fckeditor.editor(attrs, body()) << "After"
    }
}
Show
Stefano Gualdi added a comment - In grails 1.2-M1 the workaround for missing encoding is no more necessary, you can write:
class TestTagLib {

    def myeditor = { attrs, body ->
        out << "Before" << fckeditor.editor(attrs, body()) << "After"
    }
}

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: