修复emlog6.0.0版不支持模板设置插件的问题

图片[1]|修复emlog6.0.0版不支持模板设置插件的问题|孤狼资源网

emlog6.0.0正式版中使用官方模板设置时无法正常设置模板参数

温馨提示:本教程只针对emlog6.0.0版本,其他emlog版无效!教程有小问题,不管模板支持不支持模板设置,都会显示设置2字

第一步、首先找到路径/admin/views/template.php文件中代码:

<?php if (!defined('EMLOG_ROOT')) {exit('error!');}?>

后面加入代码:

<div id="containers"><?php doAction('adm_main_top'); ?>

第二步、找到代码替换模板设置插件(content/plugins/tpl_options/assets/main.js)的所有代码即可:

  1. $(function() {
  2. //初始化变量
  3. var tplOptions = window.tplOptions;
  4. var body = $('body');
  5. var iframe = $('<iframe name="upload-image" src="about:blank" style="display:none"/>').appendTo(body);
  6. var optionArea = $('<div/>').appendTo($('#containers')).addClass(attr('area')).slideUp();
  7. var templateContent = $('.tpl:last, #container table');
  8. var loadingDom = $('<div />').appendTo(body);
  9. var message = $('<div />').appendTo($('.tpl_msg:first')).css('position', 'fixed');
  10. var timer, input, targetInput, target, templateInput, template;
  11. var trueInput = $('<input type="file" name="image">').css({
  12. position: 'absolute',
  13. margin: 0,
  14. visibility: 'hidden'
  15. }).on('change', function() {
  16. loading();
  17. target = input.data('target');
  18. targetInput.val(target);
  19. templateInput.val(template);
  20. form.submit();
  21. }).on('mouseleave', function() {
  22. trueInput.css('visibility', 'hidden');
  23. input.css('visibility', 'visible');
  24. });
  25. var form = $('<form id="upload-form" target="upload-image" />').append(
  26. trueInput,
  27. targetInput = $('<input type="hidden" name="target">'),
  28. templateInput = $('<input type="hidden" name="template">')
  29. ).appendTo(body).attr({
  30. action: tplOptions.uploadUrl,
  31. target: 'upload-image',
  32. enctype: 'multipart/form-data',
  33. method: 'post'
  34. });
  35. //插入设置按钮
  36. for (var tpl in tplOptions.templates) {
  37. (function(tpl) {
  38. var td = $('.active .act').parent();
  39. $('<span>设置 </span>').insertBefore(td.find('a')).addClass(attr('setting')).data('template', tpl);
  40. })(tpl);
  41. }
  42. //当前模板
  43. (function() {
  44. try
  45. {
  46. var c
  47. urrentTemplate = $('.theme_ntpls .theme-preview .screenshot img').attr('src').match(/\/templates\/(.*?)\/preview.jpg/)[1];
  48. if (tplOptions.templates[currentTemplate]) {
  49. $('<br>').insertBefore($('<span><strong>[设置]</strong></span>').appendTo($('.theme_ntpls .theme-info')).addClass(attr('setting')).data('template', currentTemplate));
  50. }
  51. }catch(err) {}
  52. })();
  53. //绑定事件
  54. body.on('click', '.' + attr('setting'), function() {
  55. $.ajax({
  56. url: tplOptions.baseUrl,
  57. data: {
  58. template: $(this).data('template')
  59. },
  60. cache: false,
  61. beforeSend: function() {
  62. loading();
  63. editorMap = {};
  64. },
  65. success: function(data) {
  66. templateContent.slideUp(500, function() {
  67. optionArea.html(data).slideDown();
  68. window.setTimeout(function() {
  69. initOptionSort();
  70. initRichText();
  71. loading(false);
  72. }, 0);
  73. });
  74. }
  75. });
  76. }).on('click', '.tpl-options-close', function() {
  77. optionArea.slideUp(500, function() {
  78. templateContent.slideDown();
  79. });
  80. }).on('click', '.option-sort-name', function() {
  81. var that = $(this);
  82. if (that.is('.selected')) {
  83. return;
  84. }
  85. var left = that.parent(),
  86. right = left.siblings('.option-sort-right');
  87. left.find('.selected').removeClass('selected');
  88. that.addClass('selected');
  89. right.find('.option-sort-option').removeClass('selected').eq(that.index()).addClass('selected');
  90. }).on('change', '.option-sort-select', function() {
  91. var that = $(this);
  92. var right = that.parent().siblings('.option-sort-right');
  93. right.find('.option-sort-option').removeClass('selected').eq(that.find('option:selected').index()).addClass('selected');
  94. }).on('mouseenter', '.tpl-options-form input[type="file"]', function() {
  95. input = $(this);
  96. trueInput.css(input.offset());
  97. input.css('visibility', 'hidden');
  98. trueInput.css('visibility', 'visible');
  99. }).on('submit', 'form.tpl-options-form', function() {
  100. var that = $(this);
  101. $.ajax({
  102. url: that.attr('action'),
  103. type: 'post',
  104. data: that.serialize(),
  105. cache: false,
  106. dataType: 'json',
  107. // beforeSend: loading,
  108. success: function(data) {
  109. showMsg(data.code, data.msg);
  110. },
  111. error: function() {
  112. showMsg(1, '网络异常');
  113. },
  114. complete: function() {
  115. // loading(false);
  116. }
  117. });
  118. return false;
  119. }).on('change', '.tpl-options-form input, .tpl-options-form textarea', function() {
  120. $('form.tpl-options-form').trigger('submit');
  121. });
  122. //定义方法
  123. var initRichText = (function() {
  124. var num = 0;
  125. return function() {
  126. $('.option-rich-text').each(function() {
  127. var that = $(this);
  128. if (that.attr('id') === undefined) {
  129. that.attr('id', 'option-rich-text-' + (num++));
  130. }
  131. loadEditor(that.attr('id'));
  132. });
  133. window.setTimeout(function() {
  134. for (var id in editorMap) {
  135. editorMap[id].container[0].style.width = '';
  136. }
  137. }, 100);
  138. }
  139. })();
  140. window.setImage = function(src, path, code, msg) {
  141. if (code == 0) {
  142. $('[name="' + target + '"]').val(path).trigger('change');
  143. $('[data-name="' + target + '"]').attr('href', src).find('img').attr('src', src);
  144. } else {
  145. alert('上传失败:' + msg)
  146. }
  147. trueInput.val('');
  148. target = '';
  149. loading(false);
  150. };
  151. function initOptionSort() {
  152. $('.option-sort-left').each(function() {
  153. $(this).find('.option-sort-name:first').addClass('selected');
  154. });
  155. $('.option-sort-right').each(function() {
  156. $(this).find('.option-sort-option:first').addClass('selected');
  157. });
  158. }
  159. function loading(enable) {
  160. if (enable === undefined) {
  161. enable = true;
  162. }
  163. if (enable) {
  164. loadingDom.addClass('loading');
  165. } else {
  166. loadingDom.removeClass('loading');
  167. }
  168. }
  169. function showMsg(code, msg) {
  170. message.text(msg).css('display', '');
  171. if (code == 0) {
  172. message.attr('class', 'alert alert-info alert-tpl');
  173. if (timer) {
  174. window.clearTimeout(timer);
  175. }
  176. timer = window.setTimeout(function() {
  177. message.hide();
  178. }, 2600);
  179. } else {
  180. message.attr('class', 'alert alert-danger alert-tpl');
  181. }
  182. }
  183. function attr(name) {
  184. return tplOptions.prefix + name;
  185. }
  186. function loadEditor(id) {
  187. editorMap[id] = editorMap[id] || KindEditor.create('#' + id, {
  188. resizeMode: 1,
  189. allowUpload: false,
  190. allowImageUpload: false,
  191. allowFlashUpload: false,
  192. allowPreviewEmoticons: false,
  193. filterMode: false,
  194. afterChange: (function() {
  195. var t, i = 0;
  196. return function() {
  197. var that = this;
  198. if (t) {
  199. window.clearTimeout(t);
  200. }
  201. if (i++ > 0) {
  202. t = window.setTimeout(function() {
  203. that.sync();
  204. $(that.srcElement[0]).trigger('change');
  205. }, 2000);
  206. }
  207. }
  208. })(),
  209. urlType: 'domain',
  210. items: ['bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'hilitecolor', 'fontname', 'fontsize', 'lineheight', 'removeformat', 'plainpaste', 'quickformat', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'justifyleft', 'justifycenter', 'justifyright', 'link', 'unlink', 'image', 'flash', 'table', 'emoticons', 'code', 'fullscreen', 'source', '|', 'about']
  211. });
  212. }
  213. });
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容