<reponame>SummerCoCo/qiandao<filename>web/static/har/contenteditable.js<gh_stars>0// Generated by CoffeeScript 2.7.0
(function() {
  // vim: set et sw=2 ts=2 sts=2 ff=unix fenc=utf8:
  // Author: Binux<dycjh@example.com>
  //         http://binux.me
  // Created on 2014-08-04 19:34:02
  define(function(require, exports, module) {
    return angular.module('contenteditable', []).directive('contenteditable', [
      '$timeout',
      function($timeout) {
        return {
          restrict: 'A',
          require: '?ngModel',
          link: function(scope,
      element,
      attrs,
      ngModel) {
            var oldRender;
            if (!ngModel) {
              return;
            }
            element.bind('input',
      function(e) {
              return scope.$apply(function() {
                var text;
                text = element.text();
                ngModel.$setViewValue(text);
                if (text === '') {
                  return $timeout(function() {
                    if (element.prev().hasClass('contentedit-wrapper')) {
                      return element.prev().click();
                    } else {
                      element[0].blur();
                      return element[0].focus();
                    }
                  });
                }
              });
            });
            element.bind('blur',
      function(e) {
              var text;
              text = element.text();
              if (ngModel.$viewValue !== text) {
                return ngModel.$render();
              }
            });
            oldRender = ngModel.$render;
            return ngModel.$render = function() {
              if (!!oldRender) {
                oldRender();
              }
              if (!element.is(':focus')) {
                return element.text(ngModel.$viewValue || '');
              }
            };
          }
        };
      }
    ]);
  });

}).call(this);
