/*globals requirejs, define*/
requirejs.config({
  baseUrl: '../js',
  shim: {
    box2d: {
      exports: 'Box2D'
    }
  },
  paths: {
    box2d: 'Box2dWeb/Box2dWeb-2.1.a.3.min'
  }
});

define(function( require ) {
  'use strict';

  var Polygon = require( 'geometry/polygon' );
  var Editor = require( 'editor/editor' );


  var editor = new Editor({
    el: '#editor',
    scaleEl: '#scale',
    historyEl: '#history'
  });

  document.addEventListener( 'keydown', editor.onKeyDown.bind( editor ) );
  document.addEventListener( 'keyup', editor.onKeyUp.bind( editor ) );

  // Disable all keys on blur.
  window.addEventListener( 'blur', function() {
    Object.keys( editor.keys ).forEach(function( key ) {
      editor.keys[ key ] = false;
    });
  });

  var polygon = new Polygon();
  polygon.vertices = [ 100, 50, -100, 50, 0, -100 ];
  polygon.angle = 0.5 * Math.PI;
  editor.add( polygon );
  editor.draw();

  // History buttons.
  var loadHistoryBtn = document.getElementById( 'load-history-btn' );
  loadHistoryBtn.addEventListener( 'click', editor.loadSelected.bind( editor ) );

  var removeHistoryBtn = document.getElementById( 'remove-history-btn' );
  removeHistoryBtn.addEventListener( 'click', editor.removeSelected.bind( editor ) );

  var clearBtn = document.getElementById( 'clear-history-btn' );
  clearBtn.addEventListener( 'click', editor.clearHistory.bind( editor ) );

  // Text area buttons.
  var loadDataBtn = document.getElementById( 'load-data-btn' );
  loadDataBtn.addEventListener( 'click', function() {
    var data = editor.textarea.value;
    var scale = parseFloat( document.getElementById( 'load-scale' ).value );
    if ( data.length ) {
      editor.loadData( data, scale );
    }
  });

  var loadBatchBtn = document.getElementById( 'load-batch-btn' );
  loadBatchBtn.addEventListener( 'click', function() {
    var data = editor.textarea.value;
    var scale = parseFloat( document.getElementById( 'load-scale' ).value );
    if ( data.length ) {
      editor.loadBatchData( data, scale );
    }
  });
});

@@ -1415,27 +1415,32 @@
  buttons.%0A  
-var
+function
  loadDataBtn
@@ -1440,98 +1440,33 @@
 Data
-Btn = document.getElementById( 'load-data-btn' );%0A  loadDataBtn.addEventListener( 'click',
+Fn( fnName ) %7B%0A    return
  fun
@@ -1467,32 +1467,34 @@
 rn function() %7B%0A
+  
     var data = e
@@ -1507,32 +1507,34 @@
 textarea.value;%0A
+  
     var scale = 
@@ -1590,32 +1590,34 @@
  ).value );%0A    
+  
 if ( data.length
@@ -1631,23 +1631,26 @@
     
+  
 editor
-.loadData
+%5B fnName %5D
 ( da
@@ -1666,23 +1666,30 @@
  );%0A    
+  
 %7D%0A  
-%7D);
+  %7D;%0A  %7D
 %0A%0A  var 
@@ -1692,21 +1692,20 @@
 var load
-Batch
+Data
 Btn = do
@@ -1737,13 +1737,12 @@
 oad-
-batch
+data
 -btn
@@ -1752,21 +1752,20 @@
 ;%0A  load
-Batch
+Data
 Btn.addE
@@ -1791,86 +1791,57 @@
 k', 
-function() %7B%0A    var data = editor.textarea.value;%0A  
+loadDataFn( 'loadData' ) );%0A%0A
   var 
-scale = parseFloat(
+loadBatchBtn =
  doc
@@ -1872,103 +1872,94 @@
 oad-
-scale' ).value );%0A    if ( data.length ) %7B%0A      editor.loadBatchData( data, scale );%0A    %7D%0A  %7D
+batch-btn' );%0A  loadBatchBtn.addEventListener( 'click', loadDataFn( 'loadBatchData' ) 
 );%0A%7D

Simplify load data button event handlers.