layui.define(['table', 'jquery', 'element'], function(exports) { "use strict"; var MOD_NAME = 'message', $ = layui.jquery, element = layui.element; var message = function(opt) { this.option = opt; }; message.prototype.render = function(opt) { //默认配置值 var option = { elem: opt.elem, url: opt.url ? opt.url : false, height: opt.height, data: opt.data } if (option.url != false) { option.data = getData(option.url); var notice = createHtml(option); $(option.elem).html(notice); } setTimeout(function(){ element.init(); },300); return new message(option); } message.prototype.click = function(callback){ $("*[notice-id]").click(function(event) { event.preventDefault(); var id = $(this).attr("notice-id"); var title = $(this).attr("notice-title"); var context = $(this).attr("notice-context"); var form = $(this).attr("notice-form"); callback(id, title, context, form); }) } /** 同 步 请 求 获 取 数 据 */ function getData(url) { $.ajaxSettings.async = false; var data = null; $.get(url, function(result) { data = result; }); $.ajaxSettings.async = true; return data; } function createHtml(option) { var notice = '
  • ' + '' + '
    '; var noticeTitle = ''; noticeContent += '
    '; notice += noticeTitle; notice += noticeContent; notice += '
  • '; return notice; } exports(MOD_NAME, new message()); })