(function () {
  var faceJson=[{"faceID":"face0","title":"微笑"},{"faceID":"face1","title":"撇嘴"},{"faceID":"face2","title":"色"},{"faceID":"face3","title":"发呆"},{"faceID":"face4","title":"得意"},{"faceID":"face5","title":"流泪"},{"faceID":"face6","title":"害羞"},{"faceID":"face7","title":"闭嘴"},{"faceID":"face8","title":"睡"},{"faceID":"face9","title":"大哭"},{"faceID":"face10","title":"尴尬"},{"faceID":"face11","title":"发怒"},{"faceID":"face12","title":"调皮"},{"faceID":"face13","title":"呲牙"},{"faceID":"face14","title":"惊讶"},{"faceID":"face15","title":"难过"},{"faceID":"face16","title":"酷"},{"faceID":"face17","title":"冷汗"},{"faceID":"face18","title":"抓狂"},{"faceID":"face19","title":"吐"},{"faceID":"face20","title":"偷笑"},{"faceID":"face21","title":"可爱"},{"faceID":"face22","title":"白眼"},{"faceID":"face23","title":"傲慢"},{"faceID":"face24","title":"饥饿"},{"faceID":"face25","title":"困"},{"faceID":"face26","title":"惊恐"},{"faceID":"face27","title":"流汗"},{"faceID":"face28","title":"憨笑"},{"faceID":"face29","title":"装逼"},{"faceID":"face30","title":"奋斗"},{"faceID":"face31","title":"咒骂"},{"faceID":"face32","title":"疑问"},{"faceID":"face33","title":"嘘"},{"faceID":"face34","title":"晕"},{"faceID":"face35","title":"折磨"},{"faceID":"face36","title":"衰"},{"faceID":"face37","title":"骷髅"},{"faceID":"face38","title":"敲打"},{"faceID":"face39","title":"再见"},{"faceID":"face40","title":"擦汗"},{"faceID":"face41","title":"抠鼻"},{"faceID":"face42","title":"鼓掌"},{"faceID":"face43","title":"糗大了"},{"faceID":"face44","title":"坏笑"},{"faceID":"face45","title":"左哼哼"},{"faceID":"face46","title":"右哼哼"},{"faceID":"face47","title":"哈欠"},{"faceID":"face48","title":"鄙视"},{"faceID":"face49","title":"委屈"},{"faceID":"face50","title":"快哭了"},{"faceID":"face51","title":"阴险"},{"faceID":"face52","title":"亲亲"},{"faceID":"face53","title":"吓"},{"faceID":"face54","title":"可怜"},{"faceID":"face55","title":"菜刀"},{"faceID":"face56","title":"西瓜"},{"faceID":"face57","title":"啤酒"},{"faceID":"face58","title":"篮球"},{"faceID":"face59","title":"乒乓"},{"faceID":"face60","title":"咖啡"},{"faceID":"face61","title":"饭"},{"faceID":"face62","title":"猪头"},{"faceID":"face63","title":"玫瑰"},{"faceID":"face64","title":"凋谢"},{"faceID":"face65","title":"示爱"},{"faceID":"face66","title":"爱心"},{"faceID":"face67","title":"心碎"},{"faceID":"face68","title":"蛋糕"},{"faceID":"face69","title":"闪电"},{"faceID":"face70","title":"炸弹"},{"faceID":"face71","title":"刀"},{"faceID":"face72","title":"足球"},{"faceID":"face73","title":"瓢虫"},{"faceID":"face74","title":"便便"},{"faceID":"face75","title":"月亮"},{"faceID":"face76","title":"太阳"},{"faceID":"face77","title":"礼物"},{"faceID":"face78","title":"拥抱"},{"faceID":"face79","title":"赞"},{"faceID":"face80","title":"踩"},{"faceID":"face81","title":"握手"},{"faceID":"face82","title":"胜利"},{"faceID":"face83","title":"抱拳"},{"faceID":"face84","title":"勾引"},{"faceID":"face85","title":"拳头"},{"faceID":"face86","title":"差劲"},{"faceID":"face87","title":"爱你"},{"faceID":"face88","title":"NO"},{"faceID":"face89","title":"OK"},{"faceID":"face90","title":"爱情"},{"faceID":"face91","title":"飞吻"},{"faceID":"face92","title":"跳跳"},{"faceID":"face93","title":"发抖"},{"faceID":"face94","title":"怄火"},{"faceID":"face95","title":"转圈"},{"faceID":"face96","title":"磕头"},{"faceID":"face97","title":"回头"},{"faceID":"face98","title":"跳绳"},{"faceID":"face99","title":"挥手"}];
  window.Face=function(option) {
      var deafultOpt={
          el:document.querySelector("body"),
          callBack:function () {}
      }
      deafultOpt=option;
      this.opt=deafultOpt;
      this.init();
  }
  Face.prototype={
      Constructor: Face,
      init:function () {
          var _this=this;
          var facePanel=document.createElement("ul");
          var faceWarp=document.createElement("div");
          facePanel.className="face-panel";
          faceWarp.className='face-warp';
          faceWarp.appendChild(facePanel);
          _this.opt.el.appendChild(faceWarp);
          for(var i=0;i<faceJson.length;i++){
              var face=faceJson[i];
              var li=document.createElement("li");
              li.className="face "+face.faceID;
              li.title=face.title;
              (function (face) {
                  li.addEventListener('click',function (e) {
                      _this.opt.callBack(face,faceWarp);
                      e.preventDefault()
                      e.stopPropagation();
                  });
              })(face)
              facePanel.appendChild(li);
          }
          _this.opt.el.addEventListener("click",function (e) {
              faceWarp.style.display="block";
              e.preventDefault()
              e.stopPropagation();

          });
          document.addEventListener("click",function (e) {
              faceWarp.style.display="none";
          })

      },
      replaceFace:function (text) {
          for(var i=0;i<faceJson.length;i++){
              var face=faceJson[i];
              var str="<span class='face "+face.faceID+"' title='"+face.title+"'></span>";
              var str1='〖'+face.title+'〗';
              var reg = new RegExp(str1,"g");
              text=text.replace(reg,str);
          }
          return text;
      }
  }
})(window)