Repository URL to install this package:
Version:
0.4.0 ▾
|
//= require redactor
var getSelectionParentElement = function() {
var parentEl = null;
if (window.getSelection) {
var sel = window.getSelection();
if (sel.rangeCount) {
parentEl = sel.getRangeAt(0).commonAncestorContainer;
if (parentEl.nodeType != 1) {
parentEl = parentEl.parentNode;
}
}
} else if (document.selection && document.selection.type != "Control") {
parentEl = document.selection.createRange().parentElement();
}
return parentEl;
};
$(document).ready(function() {
var csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content'),
params;
if (csrf_param !== undefined && csrf_token !== undefined) {
params = csrf_param + "=" + encodeURIComponent(csrf_token);
}
$('textarea').not('.plaintext').redactor({
imageUpload: "/redactor_rails/pictures?" + params,
imageGetJson: "/redactor_rails/pictures",
fileUpload: "/redactor_rails/documents?" + params,
fileGetJson: "/redactor_rails/documents",
path: "/assets/redactor-rails",
fixed: true,
buttonsAdd: ["|", "addAttributes"],
buttonsCustom: {
addAttributes: {
title: "Add Attributes",
dropdown: {
addId: {
title: "Add id",
callback: function(obj, e, key) {
obj.$el.setFocus();
var $el = $(getSelectionParentElement());
curr_id = $el.attr('id'),
id = prompt("Enter id attribute", curr_id);
if (id) {
$el.attr('id', id);
}
}
},
addClass: {
title: "Add class",
callback: function(obj, e, key) {
obj.$el.setFocus();
var $el = $(getSelectionParentElement());
curr_class = $el.attr('class'),
klass = prompt("Enter class attribute", curr_class);
if (klass) {
$el.attr('class', klass);
}
}
}
}
}
}
});
});