当前位置:首页 » Emlog教程 » 让Emlog6.0.0版本支持模板设置插件的教程分享

让Emlog6.0.0版本支持模板设置插件的教程分享

emlog6.0.0正式版中使用官方模板设置时无法正常设置模板参数,下面的是教程详情:
第一步、首先找到路径/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)的所有代码即可
$(function() {
  //初始化变量
  var tplOptions = window.tplOptions;
  var body = $('body');
  var iframe = $('<iframe name="upload-image" src="about:blank" style="display:none"/>').appendTo(body);
  var optionArea = $('<div/>').appendTo($('#containers')).addClass(attr('area')).slideUp();
  var templateContent = $('.tpl:last, #container table');
  var loadingDom = $('<div />').appendTo(body);
  var message = $('<div />').appendTo($('.tpl_msg:first')).css('position', 'fixed');
  var timer, input, targetInput, target, templateInput, template;
  var trueInput = $('<input type="file" name="image">').css({
    position: 'absolute',
    margin: 0,
    visibility: 'hidden'
  }).on('change', function() {
    loading();
    target = input.data('target');
    targetInput.val(target);
    templateInput.val(template);
    form.submit();
  }).on('mouseleave', function() {
    trueInput.css('visibility', 'hidden');
    input.css('visibility', 'visible');
  });
  var form = $('<form id="upload-form" target="upload-image" />').append(
    trueInput,
    targetInput = $('<input type="hidden" name="target">'),
    templateInput = $('<input type="hidden" name="template">')
    ).appendTo(body).attr({
      action: tplOptions.uploadUrl,
      target: 'upload-image',
      enctype: 'multipart/form-data',
      method: 'post'
    });
  //插入设置按钮
  for (var tpl in tplOptions.templates) {
    (function(tpl) {
      var td = $('.active .act').parent();
      $('<span>设置  </span>').insertBefore(td.find('a')).addClass(attr('setting')).data('template', tpl);
    })(tpl);
  }
  //当前模板
  (function() {
    try 
    {
      var c
      urrentTemplate = $('.theme_ntpls .theme-preview .screenshot img').attr('src').match(/\/templates\/(.*?)\/preview.jpg/)[1];
      if (tplOptions.templates[currentTemplate]) {
        $('<br>').insertBefore($('<span><strong>[设置]</strong></span>').appendTo($('.theme_ntpls .theme-info')).addClass(attr('setting')).data('template', currentTemplate));
      }
    }catch(err) {}
  })();
  //绑定事件
  body.on('click', '.' + attr('setting'), function() {
    $.ajax({
      url: tplOptions.baseUrl,
      data: {
        template: $(this).data('template')
      },
      cache: false,
      beforeSend: function() {
        loading();
        editorMap = {};
      },
      success: function(data) {
        templateContent.slideUp(500, function() {
          optionArea.html(data).slideDown();
          window.setTimeout(function() {
            initOptionSort();
            initRichText();
            loading(false);
          }, 0);
        });
      }
    });
  }).on('click', '.tpl-options-close', function() {
    optionArea.slideUp(500, function() {
      templateContent.slideDown();
    });
  }).on('click', '.option-sort-name', function() {
    var that = $(this);
    if (that.is('.selected')) {
      return;
    }
    var left = that.parent(),
    right = left.siblings('.option-sort-right');
    left.find('.selected').removeClass('selected');
    that.addClass('selected');
    right.find('.option-sort-option').removeClass('selected').eq(that.index()).addClass('selected');
  }).on('change', '.option-sort-select', function() {
    var that = $(this);
    var right = that.parent().siblings('.option-sort-right');
    right.find('.option-sort-option').removeClass('selected').eq(that.find('option:selected').index()).addClass('selected');
  }).on('mouseenter', '.tpl-options-form input[type="file"]', function() {
    input = $(this);
    trueInput.css(input.offset());
    input.css('visibility', 'hidden');
    trueInput.css('visibility', 'visible');
  }).on('submit', 'form.tpl-options-form', function() {
    var that = $(this);
    $.ajax({
      url: that.attr('action'),
      type: 'post',
      data: that.serialize(),
      cache: false,
      dataType: 'json',
      // beforeSend: loading,
      success: function(data) {
        showMsg(data.code, data.msg);
      },
      error: function() {
        showMsg(1, '网络异常');
      },
      complete: function() {
        // loading(false);
      }
    });
    return false;
  }).on('change', '.tpl-options-form input, .tpl-options-form textarea', function() {
    $('form.tpl-options-form').trigger('submit');
  });
  //定义方法
  var initRichText = (function() {
    var num = 0;
    return function() {
      $('.option-rich-text').each(function() {
        var that = $(this);
        if (that.attr('id') === undefined) {
          that.attr('id', 'option-rich-text-' + (num++));
        }
        loadEditor(that.attr('id'));
      });
      window.setTimeout(function() {
        for (var id in editorMap) {
          editorMap[id].container[0].style.width = '';
        }
      }, 100);
    }
  })();
  window.setImage = function(src, path, code, msg) {
    if (code == 0) {
      $('[name="' + target + '"]').val(path).trigger('change');
      $('[data-name="' + target + '"]').attr('href', src).find('img').attr('src', src);
    } else {
      alert('上传失败:' + msg)
    }
    trueInput.val('');
    target = '';
    loading(false);
  };

  function initOptionSort() {
    $('.option-sort-left').each(function() {
      $(this).find('.option-sort-name:first').addClass('selected');
    });
    $('.option-sort-right').each(function() {
      $(this).find('.option-sort-option:first').addClass('selected');
    });
  }

  function loading(enable) {
    if (enable === undefined) {
      enable = true;
    }
    if (enable) {
      loadingDom.addClass('loading');
    } else {
      loadingDom.removeClass('loading');
    }
  }

  function showMsg(code, msg) {
    message.text(msg).css('display', '');
    if (code == 0) {
      message.attr('class', 'alert alert-info alert-tpl');
      if (timer) {
        window.clearTimeout(timer);
      }
      timer = window.setTimeout(function() {
        message.hide();
      }, 2600);
    } else {
      message.attr('class', 'alert alert-danger alert-tpl');
    }
  }

  function attr(name) {
    return tplOptions.prefix + name;
  }

  function loadEditor(id) {
    editorMap[id] = editorMap[id] || KindEditor.create('#' + id, {
      resizeMode: 1,
      allowUpload: false,
      allowImageUpload: false,
      allowFlashUpload: false,
      allowPreviewEmoticons: false,
      filterMode: false,
      afterChange: (function() {
        var t, i = 0;
        return function() {
          var that = this;
          if (t) {
            window.clearTimeout(t);
          }
          if (i++ > 0) {
            t = window.setTimeout(function() {
              that.sync();
              $(that.srcElement[0]).trigger('change');
            }, 2000);
          }
        }
      })(),
      urlType: 'domain',
      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']
    });
  }
});
温馨提示:本教程只针对emlog6.0.0版本,参考young小杰博客修改而来,其他emlog版无效!!!教程有小问题,不管模板支持不支持模板设置,都会显示设置2字。

让Emlog6.0.0版本支持模板设置插件的教程分享.png

参考教程:http://bbs.emlog.net/thread-65337-1-1.html
End
关键词: emlog
温馨提示:如果您对本文有疑问,请在本页留言即可!!!
觉得很赞 (2)付款方式
X
付款方式:
  • 微信
  • 支付宝
  • QQ红包

使用微信扫一扫
blogger
    发布日期:2018-10-06   所属类别:Emlog教程   浏览:14463次   评论:2次
    本文地址:https://www.shuyong.net/iemlog/1056.html [ 百度已收录 ]
    声明:本页信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!

留言/评论:◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

填写好QQ号码,任点空白处自动获取

昵称

邮箱

网址

2楼、科学上网 [回复该留言]
2018-11-19 08:40
不错不错哦
1楼、网站建设 [回复该留言]
2018-10-22 11:11
不错

个人资料

舍力

博主:舍力

Emlog交流群

    用心做好每一件事!!!

博客统计

  • 文章数量:1132篇
  • 文章评论:3510条
  • 总访问量:9346486次
  • 微语数量:81条
  • 在线人数:1人
  • 本站运行:10年6月25天
  • 估计博主很忙,已经很久没更新了!
Q2 虚位以待
Copyright © 2024 舍力博客 版权所有   粤ICP备11021420号
基于宝塔面板,数据存储于阿里云ECS
Powered by emlog / &Author 舍力博客.