Guest User

Untitled

a guest
Apr 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. function customcode() {
  2. Drupal.editor.editor.on('toolbarLoaded',function() {
  3. var customcodeButton = {type: 'push',label: 'Insert Custom code', value: 'insertcustomcode'};
  4. this.toolbar.addButtonToGroup(customcodeButton,'specialbuttons');
  5.  
  6. var Dom = YAHOO.util.Dom,
  7. Event = YAHOO.util.Event,
  8. Lang = YAHOO.lang;
  9.  
  10. var _handleWindowClose = function() {
  11. var el = this.currentElement[0];
  12. //set the attribute on the element so we can parse it out afterward.
  13. var textarea = document.getElementById('embedcustomcode');
  14. var val = textarea.value;
  15. el.setAttribute('embeddedcode',encodeURIComponent(textarea.value));
  16. textarea.value = '';
  17.  
  18. this.nodeChange();
  19. };
  20.  
  21. var _handleMediaWindow = function() {
  22. var el = this.currentElement[0];
  23. var win = new YAHOO.widget.EditorWindow('insertcustomcode',{width: '625px'});
  24. var bFlag = false;
  25. win.setHeader(Drupal.t('Edit Custom code'));
  26. this.openWindow(win);
  27.  
  28. this.on('afterOpenWindow',function() {
  29. this.get('panel').syncIframe();
  30. }, this, true);
  31.  
  32. if (null != el.getAttribute('embeddedcode')) {
  33. var textarea = document.getElementById('embedcustomcode');
  34.  
  35. if(null != textarea) {
  36. textarea.value = decodeURIComponent(el.getAttribute('embeddedcode'));
  37. } else {
  38. bFlag = true;
  39. }
  40. }
  41. };
  42.  
  43. this.toolbar.on('insertcustomcodeClick',function() {
  44. var el = this._getSelectedElement();
  45.  
  46. if(Dom.hasClass(el, 'yui-customcode')) {
  47. this.currentElement = [el];
  48. handleInsertIcon.call(this);
  49. return false;
  50. }
  51. },this, true);
  52.  
  53. this.cmd_insertcustomcode = function() {
  54. if (!Dom.hasClass(this._getSelectedElement(), 'yui-customcode')) {
  55. this.execCommand('insertimage', 'none');
  56. var el = this._swapEl(this.currentElement[0], 'div', function(el) {
  57. el.className = 'yui-customcode';
  58. el.innerHTML = ' ';
  59. });
  60. this.currentElement = [el];
  61. }
  62. _handleMediaWindow.call(this);
  63. return [false];
  64. }
  65.  
  66. this.on('editorDoubleClick',function () {
  67. var el = this._getSelectedElement();
  68. if (Dom.hasClass(el, 'yui-customcode')) {
  69. this.currentElement = [el];
  70. _handleMediaWindow.call(this);
  71. return false;
  72. }
  73. },
  74. this,true);
  75.  
  76. this.on('afterNodeChange',function() {
  77. if (this._hasSelection()) {
  78. this.toolbar.disableButton('insertcustomcode');
  79. } else {
  80. this.toolbar.enableButton('insertcustomcode');
  81. var el = this._getSelectedElement();
  82. if (Dom.hasClass(el, 'yui-customcode')) {
  83. this.toolbar.selectButton('insertcustomcode');
  84. } else {
  85. this.toolbar.deselectButton('insertcustomcode');
  86. }
  87. }
  88. },
  89. this,true);
  90.  
  91. this.on('windowinsertcustomcodeClose', function() {
  92. _handleWindowClose.call(this);
  93. },
  94. this, true);
  95.  
  96. this.on('windowRender', function() {
  97. var body = document.createElement('div');
  98. body.innerHTML = '<div style="margin-left: 5px">' + Drupal.t('Paste your custom code here:') +
  99. '</div><textarea id="embedcustomcode" style="width: 95%; margin-left: 5px" rows="10"></textarea>';
  100. this._windows.insertcustomcode = {
  101. body: body
  102. };
  103. });
  104. },
  105. Drupal.editor.editor, true);
  106. }
Add Comment
Please, Sign In to add comment