ElementPath.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * ElementPath.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * This control creates an path for the current selections parent elements in TinyMCE.
  12. *
  13. * @class tinymce.ui.ElementPath
  14. * @extends tinymce.ui.Path
  15. */
  16. define("tinymce/ui/ElementPath", [
  17. "tinymce/ui/Path",
  18. "tinymce/EditorManager"
  19. ], function(Path, EditorManager) {
  20. return Path.extend({
  21. /**
  22. * Post render method. Called after the control has been rendered to the target.
  23. *
  24. * @method postRender
  25. * @return {tinymce.ui.ElementPath} Current combobox instance.
  26. */
  27. postRender: function() {
  28. var self = this, editor = EditorManager.activeEditor;
  29. function isHidden(elm) {
  30. if (elm.nodeType === 1) {
  31. if (elm.nodeName == "BR" || !!elm.getAttribute('data-mce-bogus')) {
  32. return true;
  33. }
  34. if (elm.getAttribute('data-mce-type') === 'bookmark') {
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40. self.on('select', function(e) {
  41. var parents = [], node, body = editor.getBody();
  42. editor.focus();
  43. node = editor.selection.getStart();
  44. while (node && node != body) {
  45. if (!isHidden(node)) {
  46. parents.push(node);
  47. }
  48. node = node.parentNode;
  49. }
  50. editor.selection.select(parents[parents.length - 1 - e.index]);
  51. editor.nodeChanged();
  52. });
  53. editor.on('nodeChange', function(e) {
  54. var parents = [], selectionParents = e.parents, i = selectionParents.length;
  55. while (i--) {
  56. if (selectionParents[i].nodeType == 1 && !isHidden(selectionParents[i])) {
  57. var args = editor.fire('ResolveName', {
  58. name: selectionParents[i].nodeName.toLowerCase(),
  59. target: selectionParents[i]
  60. });
  61. parents.push({name: args.name});
  62. }
  63. }
  64. self.data(parents);
  65. });
  66. return self._super();
  67. }
  68. });
  69. });