// 上传音频
UE.registerUI('uploadAudio', function(editor, uiname){

  // 创建dialog
  var audioDialog = new UE.ui.Dialog({

      // 指定弹出层路径
      iframeUrl: editor.options.UEDITOR_HOME_URL + 'kityformula-plugin/uploadAudioDialog.html',
      // 编辑器实例
      editor: editor,
      // dialog 名称
      name: uiname,
      // dialog 标题
      title: '插入音频',

      // dialog 外围 css
      cssRules: 'width:783px; height: 386px;',

      //如果给出了buttons就代表dialog有确定和取消
      buttons:[
          {
              className:'edui-okbutton',
              label:'确定',
              onclick:function () {
                  audioDialog.close(true);
              }
          },
          {
              className:'edui-cancelbutton',
              label:'取消',
              onclick:function () {
                  audioDialog.close(false);
              }
          }
      ]});

  editor.ready(function(){
      UE.utils.cssRule('uploadAudio', 'img.kfformula{vertical-align: middle;}', editor.document);
  });
  console.log(editor)
  var iconUrl = editor.options.UEDITOR_HOME_URL + 'kityformula-plugin/audio-icon.png';
  var tmpLink = document.createElement('a');
  tmpLink.href = iconUrl;
  tmpLink.href = tmpLink.href;
  iconUrl = tmpLink.href;

  // 音频
  var uploadAudioBtn = new UE.ui.Button({
      name:'上传',
      title:'上传音频',
      //需要添加的额外样式，指定icon图标
      cssRules :'background: url("' + iconUrl + '") !important',
      onclick:function () {
          //渲染dialog
          audioDialog.render();
          audioDialog.open();
      }
  });

  //当点到编辑内容上时，按钮要做的状态反射
  editor.addListener('selectionchange', function () {
      var state = editor.queryCommandState(uiname);
      if (state == -1) {
          uploadAudioBtn.setDisabled(true);
          uploadAudioBtn.setChecked(false);
      } else {
          uploadAudioBtn.setDisabled(false);
          uploadAudioBtn.setChecked(state);
      }
  });

  return uploadAudioBtn;


});

