preview.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ///import core
  2. ///commands 预览
  3. ///commandsName Preview
  4. ///commandsTitle 预览
  5. /**
  6. * 预览
  7. * @function
  8. * @name baidu.editor.execCommand
  9. * @param {String} cmdName preview预览编辑器内容
  10. */
  11. UE.commands['preview'] = {
  12. execCommand : function(){
  13. var me = this,
  14. w = window.open('', '_blank', ""),
  15. d = w.document,
  16. css = me.document.getElementById("syntaxhighlighter_css"),
  17. js = document.getElementById("syntaxhighlighter_js"),
  18. // style = "<style type='text/css'>" + me.options.initialStyle + "</style>",
  19. style = "<style type='text/css'>"+(me.document.getElementById("editorinitialstyle")&&me.document.getElementById("editorinitialstyle").innerHTML)+"</style>",
  20. cont = me.getContent();
  21. if(browser.ie){
  22. cont = cont.replace(/<\s*br\s*\/?\s*>/gi,'<br/><br/>')
  23. }
  24. d.open();
  25. d.write('<html><head>'+style+'<link rel="stylesheet" type="text/css" href="'+utils.unhtml( this.options.iframeCssUrl ) + '"/>'+
  26. (css ? '<link rel="stylesheet" type="text/css" href="' + css.href + '"/>' : '')
  27. + (css&&js ? ' <script type="text/javascript" charset="utf-8" src="'+js.src+'"></script>':'')
  28. +'<title></title></head><body >' +
  29. cont +
  30. (css && js ? '<script type="text/javascript">'+(baidu.editor.browser.ie ? 'window.onload = function(){SyntaxHighlighter.all()};' : 'SyntaxHighlighter.all();')+
  31. 'setTimeout(function(){' +
  32. 'for(var i=0,di;di=SyntaxHighlighter.highlightContainers[i++];){' +
  33. 'var tds = di.getElementsByTagName("td");' +
  34. 'for(var j=0,li,ri;li=tds[0].childNodes[j];j++){' +
  35. 'ri = tds[1].firstChild.childNodes[j];' +
  36. 'ri.style.height = li.style.height = ri.offsetHeight + "px";' +
  37. '}' +
  38. '}},100)</script>':'') +
  39. '</body></html>');
  40. d.close();
  41. },
  42. notNeedUndo : 1
  43. };