血透系统PC前端

template.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Created with JetBrains PhpStorm.
  3. * User: xuheng
  4. * Date: 12-8-8
  5. * Time: 下午2:09
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. (function () {
  9. var me = editor,
  10. preview = $G( "preview" ),
  11. preitem = $G( "preitem" ),
  12. tmps = templates,
  13. currentTmp;
  14. var initPre = function () {
  15. var str = "";
  16. for ( var i = 0, tmp; tmp = tmps[i++]; ) {
  17. str += '<div class="preitem" onclick="pre(' + i + ')"><img src="' + "images/" + tmp.pre + '" ' + (tmp.title ? "alt=" + tmp.title + " title=" + tmp.title + "" : "") + '></div>';
  18. }
  19. preitem.innerHTML = str;
  20. };
  21. var pre = function ( n ) {
  22. var tmp = tmps[n - 1];
  23. currentTmp = tmp;
  24. clearItem();
  25. domUtils.setStyles( preitem.childNodes[n - 1], {
  26. "background-color":"#f3f3f3",
  27. "border":"#ccc 1px solid"
  28. } );
  29. preview.innerHTML = tmp.preHtml ? tmp.preHtml : "";
  30. };
  31. var clearItem = function () {
  32. var items = preitem.children;
  33. for ( var i = 0, item; item = items[i++]; ) {
  34. domUtils.setStyles( item, {
  35. "background-color":"",
  36. "border":"white 1px solid"
  37. } );
  38. }
  39. };
  40. dialog.onok = function () {
  41. if ( !$G( "issave" ).checked ){
  42. me.execCommand( "cleardoc" );
  43. }
  44. var obj = {
  45. html:currentTmp && currentTmp.html
  46. };
  47. me.execCommand( "template", obj );
  48. };
  49. initPre();
  50. window.pre = pre;
  51. pre(2)
  52. })();