Created
May 11, 2013 20:25
-
-
Save thaniaclair/5561310 to your computer and use it in GitHub Desktop.
Editor tinyMCE JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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