I have been using the CodePress code editor for some time, so I thought that it would be cool to create a jQuery interface for it. At the time when I am writing this post, there is already similar plugging released, however the site seems to be down, so not sure if the author is still supporting it.
What I did was just slightly modified the existing code, while giving it the full power of jQuery:
// plugin definition
$.fn.codePress = function(op) {
// build main options before element iteration
var _op = $.extend({}, $.fn.codePress.defaults, op);
//set path
CodePress.path = _op.path;
var iframe = {};
// iterate and reformat each matched element
return this.each(function() {
var elm = $(this); //selected element
elm.addClass( _op.language);
//get id
var id = elm.attr("id");
//change id to tep id
elm.attr("id", id + "_cp");
iframe[id] = CodePress(elm[0]);
//insert masking iframe
elm.before(iframe[id]);
});
};
//obtions object
$.fn.codePress.defaults = {
path: "/content/js/framework/codepress/",
language: "html"
};
The full modified codepress code can be downloaded here.