/static/scripts/tiny_mce/themes/advanced/js/anchor.js

http://n23.googlecode.com/ · JavaScript · 37 lines · 26 code · 10 blank · 1 comment · 4 complexity · b7a24eab2f033a1f5a5e5a1a3038f82c MD5 · raw file

  1. tinyMCEPopup.requireLangPack();
  2. var AnchorDialog = {
  3. init : function(ed) {
  4. var action, elm, f = document.forms[0];
  5. this.editor = ed;
  6. elm = ed.dom.getParent(ed.selection.getNode(), 'A,IMG');
  7. v = ed.dom.getAttrib(elm, 'name');
  8. if (v) {
  9. this.action = 'update';
  10. f.anchorName.value = v;
  11. }
  12. f.insert.value = ed.getLang(elm ? 'update' : 'insert');
  13. },
  14. update : function() {
  15. var ed = this.editor;
  16. tinyMCEPopup.restoreSelection();
  17. if (this.action != 'update')
  18. ed.selection.collapse(1);
  19. // Webkit acts weird if empty inline element is inserted so we need to use a image instead
  20. if (tinymce.isWebKit)
  21. ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('img', {mce_name : 'a', name : document.forms[0].anchorName.value, 'class' : 'mceItemAnchor'}));
  22. else
  23. ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('a', {name : document.forms[0].anchorName.value, 'class' : 'mceItemAnchor'}, ''));
  24. tinyMCEPopup.close();
  25. }
  26. };
  27. tinyMCEPopup.onInit.add(AnchorDialog.init, AnchorDialog);