<reponame>SummerCoCo/qiandao<filename>web/static/har/editor.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-01 11:02:45
  define(function(require, exports, module) {
    var cookie_input, editor;
    require('/static/har/contenteditable');
    require('/static/har/upload_ctrl');
    require('/static/har/entry_list');
    require('/static/har/entry_editor');
    // contentedit-wrapper
    $(document).on('click', '.contentedit-wrapper', function(ev) {
      var editable;
      return editable = $(this).hide().next('[contenteditable]').show().focus();
    });
    $(document).on('blur', '.contentedit-wrapper + [contenteditable]', function(ev) {
      return $(this).hide().prev('.contentedit-wrapper').show();
    });
    $(document).on('focus', '[contenteditable]', function(ev) {
      var range, sel;
      if (this.childNodes[0]) {
        range = document.createRange();
        sel = window.getSelection();
        range.setStartBefore(this.childNodes[0]);
        range.setEndAfter(this);
        sel.removeAllRanges();
        return sel.addRange(range);
      }
    });
    // $(() ->
    //   if $('body').attr('get-cookie') == 'true'
    //     $('[data-toggle=get-cookie][disabled]').attr('disabled', false)
    //   return
    // )

    // get cookie helper
    cookie_input = null;
    $(document).on('click', "[data-toggle=get-cookie]", function(ev) {
      var $this;
      $this = $(this);
      // if $this.attr('disabled')
      //   return
      cookie_input = angular.element($this.parent().find('input'));
      if ($('body').attr('get-cookie') !== 'true') {
        // $this.html('没有插件，详情F12')
        // console.log('如需要插件请访问https://github.com/ckx000/get-cookies/下载并手动安装插件')
        if ($this.attr('getmod') === 1) {
          $this.attr('href', 'https://github.com/ckx000/get-cookies/').attr('target', '_blank').html('安装后请刷新');
        } else {
          $this.attr('getmod', 1).html('再次点击前往安装GetCookie插件');
        }
      }
    });
    window.addEventListener("message", function(ev) {
      var cookie, cookie_str, key, value;
      if (event.origin !== window.location.origin) {
        return;
      }
      cookie = ev.data;
      cookie_str = "";
      for (key in cookie) {
        value = cookie[key];
        cookie_str += key + '=' + value + '; ';
      }
      if (cookie_str === '') {
        console.log('没有获得cookie，您是否已经登录？');
        return;
      }
      if (cookie_input != null) {
        cookie_input.val(cookie_str);
      }
      return cookie_input != null ? cookie_input.scope().$parent.var.value = cookie_str : void 0;
    });
    editor = angular.module('HAREditor', ['editablelist', 'upload_ctrl', 'entry_list', 'entry_editor']);
    return {
      init: function() {
        return angular.bootstrap(document.body, ['HAREditor']);
      }
    };
  });

}).call(this);
