HTMLEditor.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. SC.loadPackage({ 'HTMLEditor': {
  2. comment: 'This is the HTML editor.',
  3. traits: ['Window'],
  4. properties: {
  5. html: { comment: 'I hold the html which the user wants to edit' },
  6. callback: { comment: 'I hold the callback function, which takes as its single argument the edited HTMLString.' }
  7. },
  8. methods: {
  9. init: {
  10. comment: 'I start a new HTMLEditor. My argument is '+
  11. '{ html: aHTMLString, callback: function(aHTMLString){},'+
  12. ' top: anInt, left: anInt, width: anInt, height: anInt }.',
  13. code: function(startConfig){
  14. var self = this;
  15. self.delegate('Window', 'init', startConfig);
  16. self.set({
  17. callback: startConfig.callback,
  18. html: startConfig.html
  19. });
  20. var editTextarea = document.createElement('textarea');
  21. editTextarea.classList.add('sg-editing-superuser-textarea');
  22. editTextarea.value = self.get('html');
  23. self.get('content').appendChild(editTextarea);
  24. editTextarea.focus();
  25. var modalButtonContainer = document.createElement('div');
  26. modalButtonContainer.classList.add('sg-editing-superuser-modal-container');
  27. var modalButtonConfirm = document.createElement('button');
  28. modalButtonConfirm.classList.add('confirm');
  29. modalButtonConfirm.addEventListener('click', function() {
  30. self.get('callback').call(self, editTextarea.value);
  31. SuperGlue.get('windowManager').do('closeWindow', self);
  32. });
  33. var modalButtonCancel = document.createElement('button');
  34. modalButtonCancel.classList.add('cancel');
  35. modalButtonCancel.addEventListener('click', function() {
  36. SuperGlue.get('windowManager').do('closeWindow', self);
  37. });
  38. modalButtonContainer.appendChild(modalButtonConfirm);
  39. modalButtonContainer.appendChild(modalButtonCancel);
  40. this.get('content').appendChild(modalButtonContainer);
  41. }
  42. }
  43. }
  44. }});