predefinedVars.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. @license
  3. Copyright 2015 Hendrik Diel
  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. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. @fileoverview
  14. this file enables predefined variables. You can add a variables by calling
  15. addPredefinedVar(name) and remove by calling removePredefinedVar(name).
  16. @author
  17. diel.hendrik@gmail.com (Hendrik Diel)
  18. */
  19. (function(){
  20. Blockly.Variables.predefinedVars = [];
  21. Blockly.Variables.addPredefinedVar = function(name){
  22. Blockly.Variables.predefinedVars.push(name);
  23. };
  24. Blockly.Variables.removePredefinedVar = function(name){
  25. var index = array.indexOf(name);
  26. if (index > -1) {
  27. Blockly.Variables.predefinedVars.splice(index, 1);
  28. }
  29. };
  30. var old = Blockly.Variables.allVariables;
  31. Blockly.Variables.allVariables = function(root) {
  32. var vars = old.call(this, root);
  33. Blockly.Variables.predefinedVars.forEach(function(x){
  34. if(vars.indexOf(x) < 0)
  35. vars.push(x);
  36. });
  37. return vars;
  38. };
  39. })();