text: layui.use(['layer'], function () {
      //jquery-layout布局
      myLayout = $('.main-layout').layout('.main-layout', {
          west__size: 300
          , west__spacing_closed: 5
          , west__togglerLength_closed: 1000
          , west__togglerAlign_closed: "top"
          , west__togglerContent_closed: "展<BR>开<BR>菜<BR>单"
          , west__togglerTip_closed: "点击展开菜单"
          , west__sliderTip: ""
          , west__slideTrigger_open: "mouseover"
          , resizerTip: "拖拽调整大小"
          , togglerTip_open: "点击隐藏菜单"
          , center__maskContents: true // IMPORTANT - enable iframe masking
      });
  
      //监听键盘ctrl+s快捷键保存
      $(document).bind("keydown", function (e) {
          if (e.ctrlKey && (e.which == 83)) {
              e.preventDefault();
              saveNote();
              return false;
          }
      });
  
      //文件及文件夹点击事件
      $(document).on('click', '.list-li', function () {
          $(".list-li").removeClass("selected");
          $(this).addClass("selected");
          var content_iframe = $("#content-iframe");
          var noteId = $(this).attr("noteId");
          var noteName = $(this).attr("noteName");
          var noteType = $(this).attr("noteType");
          var noteSuffix = $(this).attr("noteSuffix");
          $("#noteName").val(noteName);
          layer.closeAll();
          $(".loading").show();
          if (noteType == 0) {
              //文件夹
              $("#saveButton").hide();
              $(".tools-item").hide();
              $("#share").show().css("display", "inline-block");
              $("#more").show().css("display", "inline-block");
              $("#about").show().css("display", "inline-block");
          } else if (noteType == 1) {
              //文件
              $("#saveButton").show().css("display", "inline-block");
              $(".tools-item").show().css("display", "inline-block");
              if (noteSuffix != "txt") {
                  //目前只有txt格式支持背景图片
                  $("#background").hide();
              }
          }
          var src = "/note/" + noteSuffix + "/" + noteId + ".html";
          if (content_iframe.attr("src") != src) {
              content_iframe.attr("src", src);
          } else {
              $(".loading").hide();
          }
          content_iframe.on("load", function () {
              $(".loading").hide();
          });
      });
  
      //文件夹双击事件
      $(document).on('dblclick', '.list-li[noteType=0]', function () {
          var noteId = $(this).attr("noteId");
          loadNoteList(noteId);
      });
  
      //初始化左侧云笔记列表
      loadNoteList(0);
  
      //滚动条
      $('.list-bd').overlayScrollbars({
          "scrollbars": {
              "autoHide": "scroll"
          }
      });
  
      //放到最后，初始化结束后隐藏loading
      $(".main-loading").hide();
  });
  
  /**
   * 返回上一级
   */
  function loadUpNoteList() {
      if ($("#back").attr("back") == "true") {
          var noteId = $("#noteParentId").val();
          jfnote_ajax({
              url: '/note/getParentId/' + noteId,
              async: false,
              success: function (noteParentId) {
                  loadNoteList(noteParentId);
              }
          })
      }
  }
  
  /**
   * 加载笔记列表
   * @param noteId
   */
  function loadNoteList(noteParentId) {
      //清空搜索条件
      $("#search").val("");
      var notePassword = $("li[noteId='" + noteParentId + "']").attr("notePassword");
      if (notePassword == 1) {
          //有阅读密码
          var contentNoteId = $("#content-iframe").contents().find("#noteId").val();
          var notePassword = $("#content-iframe").contents().find("#notePassword").val();
          if (noteParentId != contentNoteId || (noteParentId == contentNoteId && notePassword != undefined)) {
              $("li[noteId='" + noteParentId + "']").click();
              return false;
          }
      }
      jfnote_ajax({
          url: '/note/list/' + noteParentId,
          async: false,
          beforeSend: function () {
              jfnote_load();
          },
          success: function (result) {
              //启用或禁用返回按钮
              noteParentId == 0 ? disableBack() : enableBack();
              $("#note-ul").empty();
              $("#noteParentId").val(noteParentId);
              for (var i = 0; i < result.length; i++) {
                  note = result[i];
                  var content = "";
                  //文件夹
                  if (note.noteType == 0) {
                      content = addFolderHTML(note);
                  } else if (note.noteType == 1) {
                      content = addFileHTML(note);
                  }
                  $("#note-ul").append(content);
              }
              if (result.length == 0) {
                  nothingShow();
              } else {
                  nothingHide();
                  setTimeout(function () {
                      //默认选中第一个
                      $(".list-li").eq(0).click();
                  }, 0);
              }
              $("#count").html(result.length);
              jfnote_load_close();
          }
      });
  }
  
  /**
   * 搜索
   * @param _keyword 关键字
   * @param _noteParentId 笔记父ID
   */
  function searchNoteList(_keyword, _noteParentId) {
      jfnote_ajax({
          url: '/note/search/' + _noteParentId,
          data: {
              keyword: _keyword
          },
          async: false,
          beforeSend: function () {
              jfnote_load();
          },
          success: function (result) {
              //禁用返回按钮
              disableBack();
              $("#note-ul").empty();
              for (var i = 0; i < result.length; i++) {
                  note = result[i];
                  var content = "";
                  //文件夹
                  if (note.noteType == 0) {
                      content = addFolderHTML(note);
                  } else if (note.noteType == 1) {
                      content = addFileHTML(note);
                  }
                  $("#note-ul").append(content);
              }
              if (result.length == 0) {
                  nothingShow();
              } else {
                  nothingHide();
                  setTimeout(function () {
                      //默认选中第一个
                      $(".list-li").eq(0).click();
                  }, 0);
              }
              $("#count").html(result.length);
              jfnote_load_close();
          }
      });
  }
  
  /**
   * 禁用返回按钮
   */
  function disableBack() {
      $("#back").attr("back", "false");
      $("#back").attr("title", "没有上一级");
      $("#back").css("cursor", "not-allowed");
      $("#back").css("color", "#dee2e6");
  }
  
  /**
   * 启用返回按钮
   */
  function enableBack() {
      $("#back").attr("back", "true");
      $("#back").attr("title", "点击返回上一级");
      $("#back").css("cursor", "pointer");
      $("#back").css("color", "#20c997");
  }
  
  /**
   * 删除云笔记
   * @param noteId
   */
  function deleteNote(noteId) {
      var index = $(".list-li.selected").index() - 1;
      index = (index < 0) ? 0 : index;
      jfnote_ajax({
          url: '/note/delete/' + noteId,
          success_collback_ok: function () {
              jfnote_alert_msg("删除成功");
              $("li[noteId='" + noteId + "']").remove();
              var count = parseInt($("#count").html()) - 1;
              $("#count").html(count);
              if (count == 0) {
                  nothingShow();
              } else {
                  $(".list-li").eq(index).click();//默认选中删除上一个所在的元素
              }
          }
      });
  }
  
  /**
   * 添加笔记方法
   * @param noteName 笔记名称
   * @param noteType 笔记类型
   * @param noteSuffix 笔记格式后缀
   */
  function addNote(noteName, noteType, noteSuffix) {
      jfnote_ajax({
          url: '/note/add',
          data: {
              "noteParentId": $("#noteParentId").val(),
              "noteName": noteName,
              "noteType": noteType,
              "noteSuffix": noteSuffix == undefined ? "" : noteSuffix
          },
          success_collback_ok: function (result) {
              nothingHide();
              var noteParentId = $("#noteParentId").val();
              loadNoteList(noteParentId);
              var note = $.parseJSON(result.msg);
              setTimeout(function () {
                  $("li[noteId='" + note.noteId + "']").click();
              }, 100);
              /*var note = $.parseJSON(result.msg);
              if (noteType == 0) {
                  $("#note-ul").prepend(addFolderHTML(note));
                  $(".list-li").eq(0).click();
              } else if (noteType == 1) {
                  var allLength = $(".list-li").length;
                  var folderLength = $("li[noteType=0]").length;
                  var fileLength = $("li[noteType=1]").length;
                  var contentHTML = addFileHTML(note);
                  if (allLength == 0 || folderLength == 0) {
                      if (fileLength == 0) {
                          $("#note-ul").append(contentHTML);
                      } else {
                          $(".list-li").eq(0).before(contentHTML);
                      }
                      $(".list-li").eq(0).click();
                  } else {
                      //在最后一个文件夹后面增加文件
                      $(".list-li").eq(folderLength - 1).after(contentHTML);
                      //选中增加的文件
                      $(".list-li").eq(folderLength).click();
                  }
              }
              $("#count").html(parseInt($("#count").html()) + 1);*/
          }
      });
  }
  