comment.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import $ from 'jquery';
  2. import { Types } from '../types';
  3. import * as Models from '../ivprog_elements';
  4. import { LocalizedStrings } from '../../services/localizedStringsService';
  5. import * as GlobalsManagement from '../globals';
  6. import * as VariablesManagement from '../variables';
  7. import * as VariableValueMenu from './variable_value_menu';
  8. export function createFloatingCommand () {
  9. return $('<div class="ui comment created_element"> <i class="ui icon small quote left"></i> <span class="span_comment_text" "> '+LocalizedStrings.getUI('text_comment')+' </span></div>');
  10. }
  11. export function renderCommand (command, function_obj) {
  12. var el = $('<div class="ui comment"> <i class="ui icon small quote left"></i> <div class="var_value_menu_div"></div> <div class="div_comment_text">'+command.comment_text.content+'</div> </div>');
  13. $(el).data('command', command);
  14. addHandlers(command, function_obj, el);
  15. return el;
  16. }
  17. function addHandlers (command, function_obj, comment_dom) {
  18. $(comment_dom).find('.div_comment_text').on('click', function() {
  19. $(comment_dom).find('.div_comment_text').text('');
  20. VariableValueMenu.renderMenu(command, command.comment_text, $(comment_dom).find('.var_value_menu_div'), function_obj, 20);
  21. $(comment_dom).find('.width-dynamic').val(command.comment_text.content);
  22. $(comment_dom).find('.width-dynamic').focusout(function() {
  23. if ($(this).val().trim()) {
  24. command.comment_text.content = $(this).val().trim();
  25. }
  26. $(comment_dom).find('.div_comment_text').text(command.comment_text.content);
  27. $(this).remove();
  28. });
  29. $('.width-dynamic').on('keydown', function(e) {
  30. var code = e.keyCode || e.which;
  31. if(code == 13) {
  32. if ($(this).val().trim()) {
  33. command.comment_text.content = $(this).val().trim();
  34. }
  35. $(comment_dom).find('.div_comment_text').text(command.comment_text.content);
  36. $(this).remove();
  37. }
  38. if(code == 27) {
  39. $(comment_dom).find('.div_comment_text').text(command.comment_text.content);
  40. $(this).remove();
  41. }
  42. });
  43. });
  44. }