Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

169 linhas
5.5KB

  1. /**
  2. * Copyright 2013 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. **/
  16. RED.palette = (function() {
  17. var exclusion = ['config','unknown','deprecated'];
  18. var core = ['input', 'output', 'function', 'social', 'storage', 'analysis', 'advanced'];
  19. function createCategoryContainer(category){
  20. $("#palette-container").append('<div class="palette-category">'+
  21. '<div id="header-'+category+'" class="palette-header"><i class="expanded icon-chevron-down"></i><span>'+category+'</span></div>'+
  22. '<div class="palette-content" id="palette-base-category-'+category+'">'+
  23. '<div id="palette-'+category+'-input"></div>'+
  24. '<div id="palette-'+category+'-output"></div>'+
  25. '<div id="palette-'+category+'-function"></div>'+
  26. '</div>'+
  27. '</div>');
  28. }
  29. core.forEach(createCategoryContainer);
  30. function addNodeType(nt,def) {
  31. if ($("#palette_node_"+nt).length) {
  32. return;
  33. }
  34. if (exclusion.indexOf(def.category)===-1) {
  35. var category = def.category.split("-");
  36. var d = document.createElement("div");
  37. d.id = "palette_node_"+nt;
  38. d.type = nt;
  39. var label = /^(.*?)([ -]in|[ -]out)?$/.exec(nt)[1];
  40. d.innerHTML = '<div class="palette_label">'+label+"</div>";
  41. d.className="palette_node";
  42. if (def.icon) {
  43. d.style.backgroundImage = "url(icons/"+def.icon+")";
  44. if (def.align == "right") {
  45. d.style.backgroundPosition = "95% 50%";
  46. } else if (def.inputs > 0) {
  47. d.style.backgroundPosition = "10% 50%";
  48. }
  49. }
  50. d.style.backgroundColor = def.color;
  51. if (def.outputs > 0) {
  52. var portOut = document.createElement("div");
  53. portOut.className = "palette_port palette_port_output";
  54. d.appendChild(portOut);
  55. }
  56. if (def.inputs > 0) {
  57. var portIn = document.createElement("div");
  58. portIn.className = "palette_port";
  59. d.appendChild(portIn);
  60. }
  61. if ($("#palette-base-category-"+category[0]).length === 0){
  62. createCategoryContainer(category[0]);
  63. }
  64. if ($("#palette-"+def.category).length === 0) {
  65. $("#palette-base-category-"+category[0]).append('<div id="palette-'+def.category+'"></div>');
  66. }
  67. $("#palette-"+def.category).append(d);
  68. d.onmousedown = function(e) { e.preventDefault(); }
  69. $(d).popover({
  70. title:d.type,
  71. placement:"right",
  72. trigger: "hover",
  73. delay: { show: 750, hide: 50 },
  74. html: true,
  75. container:'body',
  76. content: $(($("script[data-help-name|='"+nt+"']").html()||"<p>no information available</p>").trim())[0]
  77. });
  78. $(d).click(function() {
  79. var help = '<div class="node-help">'+($("script[data-help-name|='"+d.type+"']").html()||"")+"</div>";
  80. $("#tab-info").html(help);
  81. });
  82. $(d).draggable({
  83. helper: 'clone',
  84. appendTo: 'body',
  85. revert: true,
  86. revertDuration: 50
  87. });
  88. $("#header-"+category[0]).off('click').on('click', function(e) {
  89. $(this).next().slideToggle();
  90. $(this).children("i").toggleClass("expanded");
  91. });
  92. }
  93. }
  94. function removeNodeType(type) {
  95. $("#palette_node_"+type).remove();
  96. }
  97. function filterChange() {
  98. var val = $("#palette-search-input").val();
  99. if (val === "") {
  100. $("#palette-search-clear").hide();
  101. } else {
  102. $("#palette-search-clear").show();
  103. }
  104. var re = new RegExp(val);
  105. $(".palette_node").each(function(i,el) {
  106. if (val === "" || re.test(el.id)) {
  107. $(this).show();
  108. } else {
  109. $(this).hide();
  110. }
  111. });
  112. }
  113. $("#palette-search-input").focus(function(e) {
  114. RED.keyboard.disable();
  115. });
  116. $("#palette-search-input").blur(function(e) {
  117. RED.keyboard.enable();
  118. });
  119. $("#palette-search-clear").on("click",function(e) {
  120. e.preventDefault();
  121. $("#palette-search-input").val("");
  122. filterChange();
  123. $("#palette-search-input").focus();
  124. });
  125. $("#palette-search-input").val("");
  126. $("#palette-search-input").on("keyup",function() {
  127. filterChange();
  128. });
  129. $("#palette-search-input").on("focus",function() {
  130. $("body").one("mousedown",function() {
  131. $("#palette-search-input").blur();
  132. });
  133. });
  134. return {
  135. add:addNodeType,
  136. remove:removeNodeType
  137. };
  138. })();