You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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