/* ======================================================================== * zui: string.js * http://zui.sexy * ======================================================================== * copyright (c) 2014 cnezsoft.com; licensed mit * ======================================================================== */ (function() { 'use strict'; $.extend({ callevent: function(func, event, proxy) { if ($.isfunction(func)) { if (typeof proxy != 'undefined') { func = $.proxy(func, proxy); } event.result = func(event); return !(event.result !== undefined && (!event.result)); } return 1; }, }); string.prototype.format = function(args) { var result = this; if (arguments.length > 0) { var reg; if (arguments.length == 1 && typeof(args) == "object") { for (var key in args) { if (args[key] !== undefined) { reg = new regexp("({" + key + "})", "g"); result = result.replace(reg, args[key]); } } } else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] !== undefined) { reg = new regexp("({[" + i + "]})", "g"); result = result.replace(reg, arguments[i]); } } } } return result; }; $.fn.callevent = function(name, event, model) { var $this = $(this); var dotindex = name.indexof('.sent.'); var shortname = name; if (dotindex < 0 && model && model.name) { name += '.' + model.name; } else { shortname = name.substring(0, dotindex); } var e = $.event(name, event); // var result = $this.trigger(e); if ((typeof model === 'undefined') && dotindex > 0) { model = $this.data(name.substring(dotindex + 1)); } if (model && model.options) { var func = model.options[shortname]; if ($.isfunction(func)) { $.callevent(model.options[shortname], e, model); } } return e; }; /** * judge the string is a integer number * * @access public * @return bool */ string.prototype.isnum = function(s) { if (s !== null) { var r, re; re = /\d*/i; r = s.match(re); return (r == s) ? true : false; } return false; }; })(); /* ======================================================================== * zui: messager.js * http://zui.sexy * ======================================================================== * copyright (c) 2014 cnezsoft.com; licensed mit * ======================================================================== */ (function($, window) { 'use strict'; var id = 0; var template = ''; var defaultoptions = { type: 'default', placement: 'top', time: 4000, parent: 'body', // clear: false, icon: null, close: true, fade: true, scale: true }; var lastmessager; var messager = function(message, options) { var that = this; that.id = id++; options = that.options = $.extend({}, defaultoptions, options); that.message = (options.icon ? ' ' : '') + message; that.$ = $(template.format(options)).toggleclass('fade', options.fade).toggleclass('scale', options.scale).attr('id', 'messager-' + that.id); if(!options.close) { that.$.find('.close').remove(); } else { that.$.on('click', '.close', function() { that.hide(); }); } that.$.find('.messager-content').html(that.message); that.$.data('sent.messager', that); }; messager.prototype.show = function(message) { var that = this, options = this.options; if(lastmessager) { if(lastmessager.id == that.id) { that.$.removeclass('in'); } else if(lastmessager.isshow) { lastmessager.hide(); } } if(that.hiding) { cleartimeout(that.hiding); that.hiding = null; } if(message) { that.message = (options.icon ? ' ' : '') + message; that.$.find('.messager-content').html(that.message); } that.$.appendto(options.parent).show(); if (options.placement === 'top' || options.placement === 'bottom' || options.placement === 'center') { that.$.css('left', ($(window).width() - that.$.width() - 50) / 2); } if (options.placement === 'left' || options.placement === 'right' || options.placement === 'center') { that.$.css('top', ($(window).height() - that.$.height() - 50) / 2); } that.$.addclass('in'); if(options.time) { that.hiding = settimeout(function(){that.hide();}, options.time); } that.isshow = true; lastmessager = that; }; messager.prototype.hide = function() { var that = this; if(that.$.hasclass('in')) { that.$.removeclass('in'); settimeout(function(){that.$.remove();}, 200); } that.isshow = false; }; $.messager = messager; var noconflictmessager = window.messager; window.messager = $.messager; window.messager.noconflict = function() { window.messager = noconflictmessager; }; $.showmessage = function(message, options) { if(typeof options === 'string') { options = {type: options}; } var msg = new messager(message, options); msg.show(); return msg; }; var getoptions = function(options) { return (typeof options === 'string') ? {placement: options} : options; }; $.messager = { show: $.showmessage, primary: function(message, options) { return $.showmessage(message, $.extend({type: 'primary'}, getoptions(options))); }, success: function(message, options) { return $.showmessage(message, $.extend({type: 'success', icon: 'ok-sign'}, getoptions(options))); }, info: function(message, options) { return $.showmessage(message, $.extend({type: 'info', icon: 'info-sign'}, getoptions(options))); }, warning: function(message, options) { return $.showmessage(message, $.extend({type: 'warning', icon: 'warning-sign'}, getoptions(options))); }, danger: function(message, options) { return $.showmessage(message, $.extend({type: 'danger', icon: 'exclamation-sign'}, getoptions(options))); }, important: function(message, options) { return $.showmessage(message, $.extend({type: 'important'}, getoptions(options))); }, special: function(message, options) { return $.showmessage(message, $.extend({type: 'special'}, getoptions(options))); } }; var noconflict = window.messager; window.messager = $.messager; window.messager.noconflict = function() { window.messager = noconflict; }; }(jquery, window));