Friday, December 31, 2010

Fixing WymEditor from stripping out YouTube embedded links

JavaScript/jQuery doesn't come with a routine to remove elements from an array, so we create one as follows. This code was inspired from the MooTools v1.3 code:
Array.prototype.remove = function(item)
{   
    for(var i = this.length; i--;) {
        if(this[i] === item) this.splice(i,1);
    }
    return this;
};
https://github.com/rogerhu/wymeditor/commit/3cf8fe07f52547056918be6dd8e69fb08da2c60f

We'll later use this remove() function to remove <param> tag from being considered as a block tag, and insert param/embed tags an inline_tags.
var XhtmlSaxListener = WYMeditor.XhtmlSaxListener;
        WYMeditor.XhtmlSaxListener = function () {
            var listener = XhtmlSaxListener.call(this);
            listener.block_tags.remove('param');
            listener.inline_tags.push('param');
            listener.inline_tags.push('embed');
            return listener;
        };
If we really wanted to be consistent, we could also use the following statements with the WymEditor patch, we can do the following:
WYMeditor.XhtmlValidator['_tags']["embed"] = {
            "attributes":[
                "allowscriptaccess",
                "allowfullscreen",
                "height",
                "src",
                "type",
                "wmode",
                "width"
            ],
            "inside":"object"
        };
WYMeditor.XhtmlValidator['_tags']['param'] = {
            "attributes" : ["type", "value", "name"],
            "required" : "name",
            "inside" : "object"
        };

No comments:

Post a Comment