spreadsheet/ruleJS.all.full.js
function (element) {
      var id = element.getAttribute('id');

      // on db click show formula
      element.addEventListener('dblclick', function () {
        var item = instance.matrix.getItem(id);

        if (item && item.formula) {
          item.formulaEdit = true;
          element.value = '=' + item.formula;
        }
      });

      element.addEventListener('blur', function () {
        var item = instance.matrix.getItem(id);

        if (item) {
          if (item.formulaEdit) {
            element.value = item.value || item.error;
          }

          item.formulaEdit = false;
        }
      });

      // if pressed ESC restore original value
      element.addEventListener('keyup', function (event) {
        switch (event.keyCode) {
          case 13: // ENTER
          case 27: // ESC
            // leave cell
            listen();
            break;
        }
      });

      // re-calculate formula if ref cells value changed
      element.addEventListener('change', function () {
        // reset and remove item
        instance.matrix.removeItem(id);

        // check if inserted text could be the formula
        var value = element.value;

        if (value[0] === '=') {
          element.setAttribute('data-formula', value.substr(1));
          registerElementInMatrix(element);
        }

        // get ref cells and re-calculate formulas
        recalculateElementDependencies(element);
      });
    }
function (element) {
      var id = element.getAttribute('id');

      // on db click show formula
      element.addEventListener('dblclick', function () {
        var item = instance.matrix.getItem(id);

        if (item && item.formula) {
          item.formulaEdit = true;
          element.value = '=' + item.formula;
        }
      });

      element.addEventListener('blur', function () {
        var item = instance.matrix.getItem(id);

        if (item) {
          if (item.formulaEdit) {
            element.value = item.value || item.error;
          }

          item.formulaEdit = false;
        }
      });

      // if pressed ESC restore original value
      element.addEventListener('keyup', function (event) {
        switch (event.keyCode) {
          case 13: // ENTER
          case 27: // ESC
            // leave cell
            listen();
            break;
        }
      });

      // re-calculate formula if ref cells value changed
      element.addEventListener('change', function () {
        // reset and remove item
        instance.matrix.removeItem(id);

        // check if inserted text could be the formula
        var value = element.value;

        if (value[0] === '=') {
          element.setAttribute('data-formula', value.substr(1));
          registerElementInMatrix(element);
        }

        // get ref cells and re-calculate formulas
        recalculateElementDependencies(element);
      });
    }
function ( element ) { var id = element . getAttribute ( 'id' ) ; // on db click show formula element . addEventListener ( 'dblclick' , function ( ) { var item = instance . matrix . getItem ( id ) ; if ( item && item . formula ) { item . formulaEdit = true ; element . value = '=' + item . formula ; } } ) ; element . addEventListener ( 'blur' , function ( ) { var item = instance . matrix . getItem ( id ) ; if ( item ) { if ( item . formulaEdit ) { element . value = item . value || item . error ; } item . formulaEdit = false ; } } ) ; // if pressed ESC restore original value element . addEventListener ( 'keyup' , function ( event ) { switch ( event . keyCode ) { case 13 : // ENTER case 27 : // ESC // leave cell listen ( ) ; break ; } } ) ; // re-calculate formula if ref cells value changed element . addEventListener ( 'change' , function ( ) { // reset and remove item instance . matrix . removeItem ( id ) ; // check if inserted text could be the formula var value = element . value ; if ( value [ 0 ] === '=' ) { element . setAttribute ( 'data-formula' , value . substr ( 1 ) ) ; registerElementInMatrix ( element ) ; } // get ref cells and re-calculate formulas recalculateElementDependencies ( element ) ; } ) ; }
register events for elements
@param element
register events for elements