1 /**
  2  * preview for kissy editor
  3  * @author yiminghe@gmail.com
  4  */
  5 KISSY.add("editor/plugin/preview/index", function (S) {
  6     var win = window;
  7 
  8     function Preview() {
  9     }
 10 
 11     S.augment(Preview, {
 12         renderUI:function (editor) {
 13             editor.addButton("preview", {
 14                 tooltip:"预览",
 15                 listeners:{
 16                     click:function () {
 17                         try {
 18                             var screen = win.screen,
 19                                 iWidth = Math.round(screen.width * 0.8),
 20                                 iHeight = Math.round(screen.height * 0.7),
 21                                 iLeft = Math.round(screen.width * 0.1);
 22                         } catch (e) {
 23                             iWidth = 640; // 800 * 0.8,
 24                             iHeight = 420; // 600 * 0.7,
 25                             iLeft = 80;	// (800 - 0.8 * 800) /2 = 800 * 0.1.
 26                         }
 27                         var sHTML = editor.getDocHtml()
 28                                 .replace(/\${title}/, "预览"),
 29                             sOpenUrl = '',
 30                             oWindow = win.open(sOpenUrl,
 31                                 // 每次都弹出新窗口
 32                                 '',
 33                                 'toolbar=yes,' +
 34                                     'location=no,' +
 35                                     'status=yes,' +
 36                                     'menubar=yes,' +
 37                                     'scrollbars=yes,' +
 38                                     'resizable=yes,' +
 39                                     'width=' +
 40                                     iWidth +
 41                                     ',height='
 42                                     + iHeight
 43                                     + ',left='
 44                                     + iLeft), winDoc = oWindow.document;
 45                         winDoc.open();
 46                         winDoc.write(sHTML);
 47                         winDoc.close();
 48                         //ie 重新显示
 49                         oWindow.focus();
 50                     }
 51 
 52                 }
 53             });
 54         }});
 55 
 56     return Preview;
 57 
 58 
 59 });
 60