Skip to content

Instantly share code, notes, and snippets.

@thaniaclair
Created May 11, 2013 20:25
Show Gist options
  • Select an option

  • Save thaniaclair/5561310 to your computer and use it in GitHub Desktop.

Select an option

Save thaniaclair/5561310 to your computer and use it in GitHub Desktop.
Editor tinyMCE JS
// RICH TEXT EDITOR
var richEditor = {
init: function() {
richEditor.initValidation();
},
/**
* Adiciona uma classe de erro, no caso do campo ter sido invalidado por falta de conteúdo ou
* exceder o tamanho máximo de caracteres.
*/
addErrorClass: function() {
$("textarea.richEditor.error").each(function(idx, element) {
$(this).next("span.mceEditor").find("> table").addClass("error");
});
},
/**
* Seta as URLs como absolutas nas imagens a serem referenciadas no editor.
*/
setAbsoluteURLs: function() {
// Desabilita a URL das imagens como relativas.
tinyMCE.settings.relative_urls = false;
tinyMCE.settings.remove_script_host = false;
// Configura a URL raiz no editor.
var url = $(location).attr("href");
var context = SIS.basics.getPath();
var idx = url.indexOf(context);
var rootURL = url.substring(0, idx) + context;
tinyMCE.settings.document_base_url = rootURL;
},
/**
* Inicializa a validação, adicionando classe de erro para o caso de conteúdos dos editores
* inválidos na submissão do formulário.
*/
initValidation: function() {
if (richEditor.isLoaded()) {
richEditor.addErrorClass();
richEditor.setAbsoluteURLs();
} else setTimeout(richEditor.initValidation, 1000);
},
/**
* Verifica se o componente TinyMCE (editor de texto utilizado) já foi carregado na página ou não.
* @returns {Boolean} <code>true</code> se carregado, <code>false</code> caso contrário.
*/
isLoaded: function() {
return (typeof tinyMCE != 'undefined');
}
};
$(function() {
richEditor.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment