Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created June 13, 2012 21:50
Show Gist options
  • Save benfoster/2926701 to your computer and use it in GitHub Desktop.
Save benfoster/2926701 to your computer and use it in GitHub Desktop.
Switching between PageDown and Redactor editors
var editors = {
Markdown: {
name: "Markdown",
select: function() {
$("'.editor").addClass("editor-md");
$("#wmd-button-bar").show();
this.init();
},
init: function () {
if ($(".editor-md").length > 0 && !$(".editor-md").data(this.name)) {
var editor = new Markdown.Editor(
new Markdown.Converter(),
null,
null,
);
editor.run();
$(".editor").data(this.name, true);
}
},
dispose: function () {
$("#wmd-button-bar").hide();
$(".editor").removeClass("editor-md");
}
},
HTML: {
name: "HTML",
select: function() {
$(".editor").addClass("editor-html");
this.init();
},
init: function () {
$(".editor-html textarea").redactor();
},
dispose: function () {
$(".editor textarea").destroyEditor();
$(".editor").removeClass("editor-html");
}
}
};
self.initEditors = function() {
// initialize content editors
$.each(editors, function(key, e) {
e.init();
});
// editor selector
$('select[name="ContentFormat"]').change(function () {
var editor = editors[$(this).val()];
if (editor) {
// dispose other editors
$.each(editors, function (key, e) {
if (key != editor.name) {
e.dispose();
}
});
// run the editor select function
editor.select();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment