123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- /**
- * jQuery ligerUI 1.1.9
- *
- * http://ligerui.com
- *
- * Author daomi 2012 [ gd_star@163.com ]
- *
- */
- (function ($)
- {
- $.ligerMessageBox = function (options)
- {
- return $.ligerui.run.call(null, "ligerMessageBox", arguments, { isStatic: true });
- };
- $.ligerDefaults.MessageBox = {
- isDrag: true
- };
- $.ligerMethos.MessageBox = {};
- $.ligerui.controls.MessageBox = function (options)
- {
- $.ligerui.controls.MessageBox.base.constructor.call(this, null, options);
- };
- $.ligerui.controls.MessageBox.ligerExtend($.ligerui.core.UIComponent, {
- __getType: function ()
- {
- return 'MessageBox';
- },
- __idPrev: function ()
- {
- return 'MessageBox';
- },
- _extendMethods: function ()
- {
- return $.ligerMethos.MessageBox;
- },
- _render: function ()
- {
- var g = this, p = this.options;
- var messageBoxHTML = "";
- messageBoxHTML += '<div class="l-messagebox">';
- messageBoxHTML += ' <div class="l-messagebox-lt"></div><div class="l-messagebox-rt"></div>';
- messageBoxHTML += ' <div class="l-messagebox-l"></div><div class="l-messagebox-r"></div> ';
- messageBoxHTML += ' <div class="l-messagebox-image"></div>';
- messageBoxHTML += ' <div class="l-messagebox-title">';
- messageBoxHTML += ' <div class="l-messagebox-title-inner"></div>';
- messageBoxHTML += ' <div class="l-messagebox-close"></div>';
- messageBoxHTML += ' </div>';
- messageBoxHTML += ' <div class="l-messagebox-content">';
- messageBoxHTML += ' </div>';
- messageBoxHTML += ' <div class="l-messagebox-buttons"><div class="l-messagebox-buttons-inner">';
- messageBoxHTML += ' </div></div>';
- messageBoxHTML += ' </div>';
- g.messageBox = $(messageBoxHTML);
- $('body').append(g.messageBox);
- g.messageBox.close = function ()
- {
- g._removeWindowMask();
- g.messageBox.remove();
- };
- //设置参数属性
- p.width && g.messageBox.width(p.width);
- p.title && $(".l-messagebox-title-inner", g.messageBox).html(p.title);
- p.content && $(".l-messagebox-content", g.messageBox).html(p.content);
- if (p.buttons)
- {
- $(p.buttons).each(function (i, item)
- {
- var btn = $('<div class="l-messagebox-btn"><div class="l-messagebox-btn-l"></div><div class="l-messagebox-btn-r"></div><div class="l-messagebox-btn-inner"></div></div>');
- $(".l-messagebox-btn-inner", btn).html(item.text);
- $(".l-messagebox-buttons-inner", g.messageBox).append(btn);
- item.width && btn.width(item.width);
- item.onclick && btn.click(function () { item.onclick(item, i, g.messageBox) });
- });
- $(".l-messagebox-buttons-inner", g.messageBox).append("<div class='l-clear'></div>");
- }
- var boxWidth = g.messageBox.width();
- var sumBtnWidth = 0;
- $(".l-messagebox-buttons-inner .l-messagebox-btn", g.messageBox).each(function ()
- {
- sumBtnWidth += $(this).width();
- });
- $(".l-messagebox-buttons-inner", g.messageBox).css({ marginLeft: parseInt((boxWidth - sumBtnWidth) * 0.5) });
- //设置背景、拖动支持 和设置图片
- g._applyWindowMask();
- g._applyDrag();
- g._setImage();
- //位置初始化
- var left = 0;
- var top = 0;
- var width = p.width || g.messageBox.width();
- if (p.left != null) left = p.left;
- else p.left = left = 0.5 * ($(window).width() - width);
- if (p.top != null) top = p.top;
- else p.top = top = 0.5 * ($(window).height() - g.messageBox.height()) + $(window).scrollTop() - 10;
- if (left < 0) p.left = left = 0;
- if (top < 0) p.top = top = 0;
- g.messageBox.css({ left: left, top: top });
- //设置事件
- $(".l-messagebox-btn", g.messageBox).hover(function ()
- {
- $(this).addClass("l-messagebox-btn-over");
- }, function ()
- {
- $(this).removeClass("l-messagebox-btn-over");
- });
- $(".l-messagebox-close", g.messageBox).hover(function ()
- {
- $(this).addClass("l-messagebox-close-over");
- }, function ()
- {
- $(this).removeClass("l-messagebox-close-over");
- }).click(function ()
- {
- g.messageBox.close();
- });
- g.set(p);
- },
- close: function ()
- {
- var g = this, p = this.options;
- this.g._removeWindowMask();
- this.messageBox.remove();
- g._hideIframe();
- },
- _applyWindowMask: function ()
- {
- var g = this, p = this.options;
- $(".l-window-mask").remove();
- g._createIframe();
- g._showIframe();
- $("<div class='l-window-mask' style='display: block;'></div>").appendTo($("body"));
- },
- /**
- * 创建iframe
- */
- _createIframe:function(){
- var width= $(window).width();
- var height= $(window).height();
- var left= $(window).scrollLeft ();
- var top= $(window).scrollTop();
- var iframeObj=$('<iframe frameborder="0" class="l_messagebox_frame" style="position:absolute;z-index:1;display:none;"></iframe>');
- iframeObj.css({left:left,top:top,width:width,height:height});
- iframeObj.attr("iframeId","messageBoxId");
- iframeObj.appendTo('body');
- },
- /**
- * 隐藏iframe
- */
- _hideIframe:function(){
- $("iframe.l_messagebox_frame[iframeId='messageBoxId']").hide();
- },
- /**
- * 显示Ifame
- */
- _showIframe:function(){
- $("iframe.l_messagebox_frame[iframeId='messageBoxId']").show();
- },
-
- _removeWindowMask: function ()
- {
- var g = this, p = this.options;
- $(".l-window-mask").remove();
- g._hideIframe(g);
- },
- _applyDrag: function ()
- {
- var g = this, p = this.options;
- if (p.isDrag && $.fn.ligerDrag)
- g.messageBox.ligerDrag({ handler: '.l-messagebox-title-inner', animate: false });
- },
- _setImage: function ()
- {
- var g = this, p = this.options;
- if (p.type)
- {
- if (p.type == 'success' || p.type == 'donne')
- {
- $(".l-messagebox-image", g.messageBox).addClass("l-messagebox-image-donne").show();
- $(".l-messagebox-content", g.messageBox).css({ paddingLeft: 64, paddingBottom: 30 });
- }
- else if (p.type == 'error')
- {
- $(".l-messagebox-image", g.messageBox).addClass("l-messagebox-image-error").show();
- $(".l-messagebox-content", g.messageBox).css({ paddingLeft: 64, paddingBottom: 30 });
- }
- else if (p.type == 'warn')
- {
- $(".l-messagebox-image", g.messageBox).addClass("l-messagebox-image-warn").show();
- $(".l-messagebox-content", g.messageBox).css({ paddingLeft: 64, paddingBottom: 30 });
- }
- else if (p.type == 'question')
- {
- $(".l-messagebox-image", g.messageBox).addClass("l-messagebox-image-question").show();
- $(".l-messagebox-content", g.messageBox).css({ paddingLeft: 64, paddingBottom: 40 });
- }
- }
- }
- });
- $.ligerMessageBox.show = function (p)
- {
- return $.ligerMessageBox(p);
- };
- $.ligerMessageBox.alert = function (title, content, type, onBtnClick)
- {
- title = title || "";
- content = content || title;
- var onclick = function (item, index, messageBox)
- {
- messageBox.close();
- if (onBtnClick)
- onBtnClick(item, index, messageBox);
- };
- p = {
- title: title,
- content: content,
- buttons: [{ text: '确定', onclick: onclick}]
- };
- if (type) p.type = type;
- return $.ligerMessageBox(p);
- };
- $.ligerMessageBox.confirm = function (title, content, callback)
- {
- var onclick = function (item, index, messageBox)
- {
- messageBox.close();
- if (callback)
- {
- callback(index == 0);
- }
- };
- p = {
- type: 'question',
- title: title,
- content: content,
- buttons: [{ text: '是', onclick: onclick }, { text: '否', onclick: onclick}]
- };
- return $.ligerMessageBox(p);
- };
- $.ligerMessageBox.success = function (title, content, onBtnClick)
- {
- return $.ligerMessageBox.alert(title, content, 'success', onBtnClick);
- };
- $.ligerMessageBox.error = function (title, content, onBtnClick)
- {
- return $.ligerMessageBox.alert(title, content, 'error', onBtnClick);
- };
- $.ligerMessageBox.warn = function (title, content, onBtnClick)
- {
- return $.ligerMessageBox.alert(title, content, 'warn', onBtnClick);
- };
- $.ligerMessageBox.question = function (title, content)
- {
- return $.ligerMessageBox.alert(title, content, 'question');
- };
- })(jQuery);
|