components/blockly-src/demos/blockfactory/factory.js
function init() {
  if ('BlocklyStorage' in window) {
    BlocklyStorage.HTTPREQUEST_ERROR =
        'There was a problem with the request.\n';
    BlocklyStorage.LINK_ALERT =
        'Share your blocks with this link:\n\n%1';
    BlocklyStorage.HASH_ERROR =
        'Sorry, "%1" doesn\'t correspond with any saved Blockly file.';
    BlocklyStorage.XML_ERROR = 'Could not load your saved file.\n'+
        'Perhaps it was created with a different version of Blockly?';
    var linkButton = document.getElementById('linkButton');
    linkButton.style.display = 'inline-block';
    linkButton.addEventListener('click',
        function() {BlocklyStorage.link(mainWorkspace);});
    disableEnableLink();
  }

  document.getElementById('helpButton').addEventListener('click',
    function() {
      open('https://developers.google.com/blockly/custom-blocks/block-factory',
           'BlockFactoryHelp');
    });

  var expandList = [
    document.getElementById('blockly'),
    document.getElementById('blocklyMask'),
    document.getElementById('preview'),
    document.getElementById('languagePre'),
    document.getElementById('languageTA'),
    document.getElementById('generatorPre')
  ];
  var onresize = function(e) {
    for (var i = 0, expand; expand = expandList[i]; i++) {
      expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px';
      expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px';
    }
  };
  onresize();
  window.addEventListener('resize', onresize);

  var toolbox = document.getElementById('toolbox');
  mainWorkspace = Blockly.inject('blockly',
      {collapse: false,
       toolbox: toolbox,
       media: '../../media/'});

  // Create the root block.
  if ('BlocklyStorage' in window && window.location.hash.length > 1) {
    BlocklyStorage.retrieveXml(window.location.hash.substring(1),
                               mainWorkspace);
  } else {
    var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>';
    Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace);
  }
  mainWorkspace.clearUndo();

  mainWorkspace.addChangeListener(updateLanguage);
  document.getElementById('direction')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('keyup', updatePreview);
  document.getElementById('format')
      .addEventListener('change', formatChange);
  document.getElementById('language')
      .addEventListener('change', updatePreview);
}
function init() {
  if ('BlocklyStorage' in window) {
    BlocklyStorage.HTTPREQUEST_ERROR =
        'There was a problem with the request.\n';
    BlocklyStorage.LINK_ALERT =
        'Share your blocks with this link:\n\n%1';
    BlocklyStorage.HASH_ERROR =
        'Sorry, "%1" doesn\'t correspond with any saved Blockly file.';
    BlocklyStorage.XML_ERROR = 'Could not load your saved file.\n'+
        'Perhaps it was created with a different version of Blockly?';
    var linkButton = document.getElementById('linkButton');
    linkButton.style.display = 'inline-block';
    linkButton.addEventListener('click',
        function() {BlocklyStorage.link(mainWorkspace);});
    disableEnableLink();
  }

  document.getElementById('helpButton').addEventListener('click',
    function() {
      open('https://developers.google.com/blockly/custom-blocks/block-factory',
           'BlockFactoryHelp');
    });

  var expandList = [
    document.getElementById('blockly'),
    document.getElementById('blocklyMask'),
    document.getElementById('preview'),
    document.getElementById('languagePre'),
    document.getElementById('languageTA'),
    document.getElementById('generatorPre')
  ];
  var onresize = function(e) {
    for (var i = 0, expand; expand = expandList[i]; i++) {
      expand.style.width = (expand.parentNode.offsetWidth - 2) + 'px';
      expand.style.height = (expand.parentNode.offsetHeight - 2) + 'px';
    }
  };
  onresize();
  window.addEventListener('resize', onresize);

  var toolbox = document.getElementById('toolbox');
  mainWorkspace = Blockly.inject('blockly',
      {collapse: false,
       toolbox: toolbox,
       media: '../../media/'});

  // Create the root block.
  if ('BlocklyStorage' in window && window.location.hash.length > 1) {
    BlocklyStorage.retrieveXml(window.location.hash.substring(1),
                               mainWorkspace);
  } else {
    var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>';
    Blockly.Xml.domToWorkspace(Blockly.Xml.textToDom(xml), mainWorkspace);
  }
  mainWorkspace.clearUndo();

  mainWorkspace.addChangeListener(updateLanguage);
  document.getElementById('direction')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('change', updatePreview);
  document.getElementById('languageTA')
      .addEventListener('keyup', updatePreview);
  document.getElementById('format')
      .addEventListener('change', formatChange);
  document.getElementById('language')
      .addEventListener('change', updatePreview);
}
function init ( ) { if ( 'BlocklyStorage' in window ) { BlocklyStorage . HTTPREQUEST_ERROR = 'There was a problem with the request.\n' ; BlocklyStorage . LINK_ALERT = 'Share your blocks with this link:\n\n%1' ; BlocklyStorage . HASH_ERROR = 'Sorry, "%1" doesn\'t correspond with any saved Blockly file.' ; BlocklyStorage . XML_ERROR = 'Could not load your saved file.\n' + 'Perhaps it was created with a different version of Blockly?' ; var linkButton = document . getElementById ( 'linkButton' ) ; linkButton . style . display = 'inline-block' ; linkButton . addEventListener ( 'click' , function ( ) { BlocklyStorage . link ( mainWorkspace ) ; } ) ; disableEnableLink ( ) ; } document . getElementById ( 'helpButton' ) . addEventListener ( 'click' , function ( ) { open ( 'https://developers.google.com/blockly/custom-blocks/block-factory' , 'BlockFactoryHelp' ) ; } ) ; var expandList = [ document . getElementById ( 'blockly' ) , document . getElementById ( 'blocklyMask' ) , document . getElementById ( 'preview' ) , document . getElementById ( 'languagePre' ) , document . getElementById ( 'languageTA' ) , document . getElementById ( 'generatorPre' ) ] ; var onresize = function ( e ) { for ( var i = 0 , expand ; expand = expandList [ i ] ; i ++ ) { expand . style . width = ( expand . parentNode . offsetWidth - 2 ) + 'px' ; expand . style . height = ( expand . parentNode . offsetHeight - 2 ) + 'px' ; } } ; onresize ( ) ; window . addEventListener ( 'resize' , onresize ) ; var toolbox = document . getElementById ( 'toolbox' ) ; mainWorkspace = Blockly . inject ( 'blockly' , { collapse : false , toolbox : toolbox , media : '../../media/' } ) ; // Create the root block. if ( 'BlocklyStorage' in window && window . location . hash . length > 1 ) { BlocklyStorage . retrieveXml ( window . location . hash . substring ( 1 ) , mainWorkspace ) ; } else { var xml = '<xml><block type="factory_base" deletable="false" movable="false"></block></xml>' ; Blockly . Xml . domToWorkspace ( Blockly . Xml . textToDom ( xml ) , mainWorkspace ) ; } mainWorkspace . clearUndo ( ) ; mainWorkspace . addChangeListener ( updateLanguage ) ; document . getElementById ( 'direction' ) . addEventListener ( 'change' , updatePreview ) ; document . getElementById ( 'languageTA' ) . addEventListener ( 'change' , updatePreview ) ; document . getElementById ( 'languageTA' ) . addEventListener ( 'keyup' , updatePreview ) ; document . getElementById ( 'format' ) . addEventListener ( 'change' , formatChange ) ; document . getElementById ( 'language' ) . addEventListener ( 'change' , updatePreview ) ; }
Initialize Blockly and layout.  Called on page load.
Initialize Blockly and layout . Called on page load .