什么是TinyMCE.dom.Event.add的最佳替代品?

时间:2015-05-18 18:36:20

标签: javascript jquery dom tinymce

我在TinyMCE中将旧的自定义3.2.5主题迁移到4.1.10。 在TinyMCE 3.X中,有一个函数将事件附加到元素

<?php // full path to text file define("TEXT_FILE", "C:\Users\Alvaro\Documents\NetBeansProjects\ManejaLog\log2.txt"); // number of lines to read from the end of file define("LINES_COUNT", 500); function read_file($file, $lines) { //global $fsize; $handle = fopen($file, "r"); $linecounter = $lines; $pos = -2; $beginning = false; $text = array(); while ($linecounter > 0) { $t = " "; while ($t != "\n") { if(fseek($handle, $pos, SEEK_END) == -1) { $beginning = true; break; } $t = fgetc($handle); $pos --; } $linecounter --; if ($beginning) { rewind($handle); } // Estoy en una linea //Atributos de cada linea (DIA/HORA/NASID). $nada = strtok($handle,":"); $dia = strtok(" "); $hora = strtok("-"); $nada2 = strtok(" "); $id = strtok(","); $cadena = $dia." ".$hora." ".$id; //Hora actual, a la que restamos 2, para comprobar los actualizados hasta 2 horas. $now = new DateTime(); $now->format("Y-m-d H:i:s"); $now->modify("-2 hours"); //Se busca hacia arriba en el fichero mientras que el valor de horascomprobar <= currentline.gethora (pseucodigo) $horascomprobar = $now->format('H'); $date = new DateTime(dia." ".hora); $date->format("Y-m-d H:i:s"); $horaslinea = $date->format('H'); while (horascomprobar <= horaslinea) { $t = " "; while ($t != "\n") { if(fseek($handle, $pos, SEEK_END) == -1) { $beginning = true; break; } $t = fgetc($handle); $pos --; } $linecounter --; if ($beginning) { rewind($handle); } //Estoy en una linea //Atributos de cada linea (DIA/HORA/NASID). $auxnada = strtok($handle,":"); $auxdia = strtok(" "); $auxhora = strtok("-"); $auxnada2 = strtok(" "); $auxid = strtok(","); $datelinea = new DateTime(auxdia." ".auxhora); $datelinea->format("Y-m-d H:i:s"); $horaslinea = $datelinea->format('H'); if(strnatcasecmp ($id, $auxid)) { echo $cadena; } // if ($beginning) break; } // //$text[$lines-$linecounter-1] = fgets($handle); if ($beginning) break; } fclose ($handle); return array_reverse($text); } ?>

现在在4.1.10中,不推荐使用Event.add。我读到我应该使用DOM.bind,但在 TinyMCE旧主题(3.X)中,我看到,他们正在传递editor.id +&#39; _path_row&#39; (除其他外)而不仅仅是编辑器ID。这是为什么?当我试图在DOM中搜索这些对象时,它们并不存在。

为什么他们会尝试通过传递一个不存在的元素来附加事件?

我尝试过做DOM.bind(editor.id,&#39;点击&#39;,callbackFn);但没有工作得到以下错误:

  

无法分配给只读属性...

唯一可行的方法是传递整个编辑器对象。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

实现类似功能的最佳和最安全的方法可能是直接将eventListener分配给编辑器主体:

editor.getBody().addEventListener('click', callbackFn, false);

对于那些使用jQuery的人:

$(editor.getBody()).bind('click', callbackFn);
相关问题