/modules/mod_base/lib/js/modules/tinymce3.4.3.2/themes/advanced/js/anchor.js

https://code.google.com/p/zotonic/ · JavaScript · 42 lines · 31 code · 11 blank · 0 comment · 6 complexity · 2b42ffb8931cdef586d744e4eadc1abc 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');
  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, elm, name = document.forms[0].anchorName.value;
  16. if (!name || !/^[a-z][a-z0-9\-\_:\.]*$/i.test(name)) {
  17. tinyMCEPopup.alert('advanced_dlg.anchor_invalid');
  18. return;
  19. }
  20. tinyMCEPopup.restoreSelection();
  21. if (this.action != 'update')
  22. ed.selection.collapse(1);
  23. elm = ed.dom.getParent(ed.selection.getNode(), 'A');
  24. if (elm)
  25. elm.name = name;
  26. else
  27. ed.execCommand('mceInsertContent', 0, ed.dom.createHTML('a', {name : name, 'class' : 'mceItemAnchor'}, ''));
  28. tinyMCEPopup.close();
  29. }
  30. };
  31. tinyMCEPopup.onInit.add(AnchorDialog.init, AnchorDialog);