util = { log : function(){ if (window.sys && window.sys.debug) { Function.apply.call(console.log, console, arguments) } }, guid : (function(){ var guid = 0 return function(){ return 'guid-' + guid++; }; })(), search : function(name){ var result = location.search.match(new RegExp("[\?\&]" + name+ "=([^\&]+)","i")); if (result == null || result.length < 1){ return ""; } return result[1]; }, }; util.msg = function(content, callback, options) { var opts = { time : 2000, type :'success', skin: 'layer-ext-we7', shade : 0.3, }; opts = $.extend({}, opts, options); var type = 1; if (opts.type == 'info') { type = 0; } else if (opts.type == 'error') { type = 2; } else { type = 1; } require(['layer'], function(){ layer.msg(content, { time : opts.time, //2s后自动关闭 icon : type, // 图标 0 叹号 1 正确 2 错误 shade : opts.shade, // 遮罩 }, function(data) { if ($.isFunction(callback)) { callback(data); }; }); }); }; util.confirm = function(content,success_callback, cancel_callback, options) { var opts = { title : '提示', btn : ['确定', '取消'], skin: 'layer-ext-we7', icon : 3, shade : 0.3, }; opts = $.extend({}, opts, options); require(['layer'], function(){ layer.confirm( content, //内容 //配置 { title: opts.title, btn: opts.btn, //按钮 可以不需要 icon: opts.icon //图标 }, function(data) { if ($.isFunction(success_callback)) { success_callback(data); }; util.closeAll(); }, function(data) { if ($.isFunction(cancel_callback)) { cancel_callback(data); }; } ); }); }; util.prompt = function(title, callback, options) { var opts = { skin: 'layer-ext-we7', formType: 1, // 0 input="text" 1 input="password" 2 textarea shade : 0.3, }; opts = $.extend({}, opts, options); require(['layer'], function(){ layer.prompt({ title: title, skin: opts.skin, formType: opts.formType, shade : opts.shade }, function(data) { if ($.isFunction(callback)) { callback(data); }; util.closeAll(); }); }); }; util.loading_layers = []; util.load = function() { require(['layer'], function(){ var index = layer.load(2, { shade: 0.3 //不显示遮罩层 }); util.loading_layers.push(index); }); }; util.loadClose = function(){ var index; while(index = util.loading_layers.pop()) { util.close(index); }; }; util.close = function(index) { require(['layer'], function(){ layer.close(index); }); }; util.closeAll = function() { require(['layer'], function(){ layer.closeAll(); }); }; util.open = function(content, callback, options) { require(['layer'], function(){ layer.open({ title: '提示', //标题 content: content, //内容 moveOut: true, yes: function(data) { if ($.isFunction(callback)) { callback(data); }; } }); }); }; util.alert = function(content, callback) { require(['layer'], function(){ layer.alert(content, { title: '提示', closeBtn: 1 //关闭按钮是否需要 }, function(data) { if ($.isFunction(callback)) { callback(data); }; }); }); }; util.tomedia = function(src){ if(src.indexOf('http://') == 0 || src.indexOf('https://') == 0 || src.indexOf('./resource') == 0) { return src; } else if(src.indexOf('./addons') == 0) { var url=window.document.location.href; var pathName = window.document.location.pathname; var pos = url.indexOf(pathName); var host = url.substring(0,pos); if (src.substr(0,1)=='.') { src=src.substr(1); } return host + src; } else { return 'http://we7cloud-10016060.file.myqcloud.com/' + src; } }; util.clip = function(elm, str) { if(elm.clip) { return; } require(['jquery.zclip'], function(){ $(elm).zclip({ path: './resource/components/zclip/ZeroClipboard.swf', copy: str, afterCopy: function(){ var obj = $('   复制成功'); var enext = $(elm).next().html(); if (!enext || enext.indexOf('  复制成功')<0) { $(elm).after(obj); } setTimeout(function(){ obj.remove(); }, 2000); } }); elm.clip = true; }); }; util.colorpicker = function(elm, callback) { require(['colorpicker'], function(){ $(elm).spectrum({ className : "colorpicker", showInput: true, showInitial: true, showPalette: true, maxPaletteSize: 10, preferredFormat: "hex", change: function(color) { if($.isFunction(callback)) { callback(color); } }, palette: [ ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", "rgb(153, 153, 153)","rgb(183, 183, 183)", "rgb(204, 204, 204)", "rgb(217, 217, 217)","rgb(239, 239, 239)", "rgb(243, 243, 243)", "rgb(255, 255, 255)"], ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)", "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)", "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)", "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)", "rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)", "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)", "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"] ] }); }); } util.uploadMultiPictures = function(callback, options){ var opts = { type :'image', tabs : { 'upload' : 'active', 'browser' : '', 'crawler' : '' }, path : '', direct : false, multi : true, dest_dir : '' }; opts = $.extend({}, opts, options); require(['jquery', 'fileUploader'], function($, fileUploader){ fileUploader.show(function(images){ if(images.length > 0){ if($.isFunction(callback)){ callback(images); } } }, opts); }); } util.editor = function(elm, callback){ var id = elm.id; if(!id) { id = 'editor-' + Math.random(); elm.id = id; } if(!elm.editor) { require(['editor'], function(){ var editor = tinyMCE.createEditor(id, { plugins: [ "advlist autolink lists link image multiimage charmap print preview hr anchor pagebreak", "searchreplace wordcount visualblocks visualchars code fullscreen", "insertdatetime media nonbreaking save table contextmenu directionality", "emoticons template paste textcolor" ], toolbar1: "undo redo | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | preview fullscreen", toolbar2: "code print | styleselect fontsizeselect link image multiimage media emoticons ", language: 'zh_CN', paste_webkit_styles: 'all', paste_preprocess: function(plugin, args) { args.content = args.content.replace(/!important/g, ''); }, fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt", menubar: false }); elm.editor = editor; editor.render(); if($.isFunction(callback)) { callback(elm, editor); } }); } return { getContent : function(){ if(elm.editor) { return elm.editor.getContent(); } else { return ''; } } }; }; // target dom 对象 util.emotion = function(elm, target, callback) { require(['jquery.caret', 'bootstrap', 'css!../../components/emotions/emotions.css'],function($){ $(function() { var emotions_html = '
'; $(elm).popover({ html: true, content: emotions_html, placement:"bottom" }); $(elm).one('shown.bs.popover', function(){ $(elm).next().mouseleave(function(){ $(elm).popover('hide'); }); $(elm).next().delegate(".eItem", "mouseover", function(){ var emo_img = 'mo-'+$(this).attr('; var emo_txt = '/'+$(this).attr("data-code"); $(elm).next().find(".emotionsGif").html(emo_img); }); $(elm).next().delegate(".eItem", "click", function(){ $(target).setCaret(); var emo_txt = '/'+$(this).attr("data-code"); $(target).insertAtCaret(emo_txt); $(elm).popover('hide'); if($.isFunction(callback)) { callback(emo_txt, elm, target); } }); }); }); }); }; util.loading = function() { var loadingid = 'modal-loading'; var modalobj = $('#' + loadingid); if(modalobj.length == 0) { $(document.body).append(''); modalobj = $('#' + loadingid); html = ''; modalobj.html(html); } modalobj.modal('show'); modalobj.next().css('z-index', 999999); return modalobj; }; util.loaded = function(){ var loadingid = 'modal-loading'; var modalobj = $('#' + loadingid); if(modalobj.length > 0){ modalobj.modal('hide'); } } util.dialog = function(title, content, footer, options) { if(!options) { options = {}; } if(!options.containerName) { options.containerName = 'modal-message'; } var modalobj = $('#' + options.containerName); if(modalobj.length == 0) { $(document.body).append(''); modalobj = $('#' + options.containerName); } html = ''; modalobj.html(html); if(content && $.isArray(content)) { var embed = function(c) { modalobj.find('.modal-body').html(c); }; if(content.length == 2) { $.post(content[0], content[1]).success(embed); } else { $.get(content[0]).success(embed); } } return modalobj; }; util.message = function(msg, redirect, type){ if (!redirect && !type) { type = 'info'; } if ($.inArray(type, ['success', 'error', 'info', 'warning']) == -1) { type = ''; } if (type == '') { type = redirect == '' ? 'error' : 'success'; } var icons = { success: 'check-circle', error: 'times-circle', info: 'info-circle', warning: 'exclamation-triangle' }; var p = ''; if (redirect && redirect.length > 0) { if (redirect == 'back') { p = '

[返回上一页]   [回首页]

'; } } var content = '
' + '
' + ''+ '
' + '
' + '

'+ msg +'

' + p + '
'+ '
' + '
'; var footer = ''; var modalobj = util.dialog('系统提示', content, footer, {'containerName': 'modal-message'}); modalobj.find('.modal-content').addClass('alert alert-' + type); modalobj.on('hide.bs.modal', function () { if (redirect) { if (redirect == 'back') { history.go(-1); }else if (redirect == 'close'){ (function(){ if (navigator.appName=="Netscape") { window.open('','_self',''); window.close(); } else { window.close(); } })(); } else { window.location.href = redirect; } } }); modalobj.on('hidden.bs.modal', function () { modalobj.remove(); }); modalobj.modal({ backdrop: 'static' }); return modalobj; }; util.map = function(val, callback){ require(['map'], function(BMap){ if(!val) { val = {}; } if(!val.lng) { val.lng = 116.403851; } if(!val.lat) { val.lat = 39.915177; } var point = new BMap.Point(val.lng, val.lat); var geo = new BMap.Geocoder(); var modalobj = $('#map-dialog'); if(modalobj.length == 0) { var content = '
' + '
' + '' + '
' + '' + '
' + '
' + '
' + '
'; var footer = '' + ''; modalobj = util.dialog('请选择地点', content, footer, {containerName : 'map-dialog'}); modalobj.find('.modal-dialog').css('width', '80%'); modalobj.modal({'keyboard': false}); map = util.map.instance = new BMap.Map('map-container'); map.centerAndZoom(point, 12); map.enableScrollWheelZoom(); map.enableDragging(); map.enableContinuousZoom(); map.addControl(new BMap.NavigationControl()); map.addControl(new BMap.OverviewMapControl()); marker = util.map.marker = new BMap.Marker(point); marker.setLabel(new BMap.Label('请您移动此标记,选择您的坐标!', {'offset': new BMap.Size(10,-20)})); map.addOverlay(marker); marker.enableDragging(); marker.addEventListener('dragend', function(e){ var point = marker.getPosition(); geo.getLocation(point, function(address){ modalobj.find('.input-group :text').val(address.address); }); }); function searchAddress(address) { geo.getPoint(address, function(point){ map.panTo(point); marker.setPosition(point); marker.setAnimation(BMAP_ANIMATION_BOUNCE); setTimeout(function(){marker.setAnimation(null)}, 3600); }); } modalobj.find('.input-group :text').keydown(function(e){ if(e.keyCode == 13) { var kw = $(this).val(); searchAddress(kw); } }); modalobj.find('.input-group button').click(function(){ var kw = $(this).parent().prev().val(); searchAddress(kw); }); } modalobj.off('shown.bs.modal'); modalobj.on('shown.bs.modal', function(){ marker.setPosition(point); map.panTo(marker.getPosition()); }); modalobj.find('button.btn-primary').off('click'); modalobj.find('button.btn-primary').on('click', function(){ if($.isFunction(callback)) { var point = util.map.marker.getPosition(); geo.getLocation(point, function(address){ var val = {lng: point.lng, lat: point.lat, label: address.address}; callback(val); }); } modalobj.modal('hide'); }); modalobj.modal('show'); }); }; // end of map util.iconBrowser = function(callback){ var footer = ''; var modalobj = util.dialog('请选择图标',['./index.php?c=utility&a=icon&callback=selectIconComplete'],footer,{containerName:'icon-container'}); modalobj.modal({'keyboard': false}); modalobj.find('.modal-dialog').css({'width':'70%'}); modalobj.find('.modal-body').css({'height':'70%','overflow-y':'scroll'}); modalobj.modal('show'); window.selectIconComplete = function(ico){ if($.isFunction(callback)){ callback(ico); modalobj.modal('hide'); } }; }; // end of icon dialog util.emojiBrowser = function(callback){ var footer = ''; var modalobj = util.dialog('请选择表情',['./index.php?c=utility&a=emoji&callback=selectEmojiComplete'],footer,{containerName:'icon-container'}); modalobj.modal({'keyboard': false}); modalobj.find('.modal-dialog').css({'width':'70%'}); modalobj.find('.modal-body').css({'height':'70%','overflow-y':'scroll'}); modalobj.modal('show'); window.selectEmojiComplete = function(emoji){ if($.isFunction(callback)){ callback(emoji); modalobj.modal('hide'); } }; }; // end of emoji dialog util.linkBrowser = function(callback){ var footer = ''; var modalobj = util.dialog('请选择链接',['./index.php?c=utility&a=link&callback=selectLinkComplete'],footer,{containerName:'link-container'}); modalobj.modal({'keyboard': false}); modalobj.find('.modal-body').css({'height':'300px','overflow-y':'auto' }); modalobj.modal('show'); window.selectLinkComplete = function(link){ if($.isFunction(callback)){ callback(link); modalobj.modal('hide'); } }; }; // end of icon dialog /** * val : image 值; * callback: 回调函数 * base64options: base64(json($options)) * options: {tabs: {'browser': 'active', 'upload': '', 'remote': ''} **/ util.image = function(val, callback, base64options, options) { var opts = { type :'image', direct : false, multiple : false, path : val, dest_dir : '', global : false, thumb : false, width : 0 }; opts = $.extend({}, opts, options); opts.type = 'image'; require(['jquery', 'fileUploader'], function($, fileUploader){ fileUploader.show(function(images){ if(images){ if($.isFunction(callback)){ callback(images); } } }, opts); }); }; // end of image util.wechat_image = function(val, callback, options) { var opts = { type :'image', direct : false, multiple : false, acid : 0, path : val, dest_dir : '' }; opts = $.extend({}, opts, options); require(['jquery', 'wechat_fileUploader'], function($, wechat_fileUploader){ wechat_fileUploader.show(function(images){ if(images){ if($.isFunction(callback)){ callback(images); } } }, opts); }); }; util.audio = function(val, callback, base64options, options) { var opts = { type :'audio', direct : false, multiple : false, path : '', dest_dir : '' }; if(val){ opts.path = val; } opts = $.extend({}, opts, options); opts.type = 'audio'; require(['jquery', 'fileUploader'], function($, fileUploader){ fileUploader.show(function(audios){ if(audios){ if($.isFunction(callback)){ callback(audios); } } }, opts); }); }; // end of audio /* 打开远程地址 @params string url 目标远程地址 @params string title 打开窗口标题,为空则不显示标题。可在返回的HTML定义控制关闭 @params object options 打开窗口的属性配置,可选项backdrop,show,keyboard,remote,width,height。具体参考bootcss模态对话框的options说明 @params object events 窗口的一些回调事件,可选项show,shown,hide,hidden,confirm。回调函数第一个参数对话框JQ对象。具体参考bootcss模态对话框的on说明. @demo ajaxshow('url', 'title', {'show' : true}, {'hidden' : function(obj) {obj.remove();}}); */ util.ajaxshow = function(url, title, options, events) { var defaultoptions = {'show' : true}; var defaultevents = {}; var option = $.extend({}, defaultoptions, options); var events = $.extend({}, defaultevents, events); var footer = (typeof events['confirm'] == 'function' ? '确定' : '') + ''; var modalobj = util.dialog(title, '正在加载中', footer, {'containerName' : 'modal-panel-ajax'}); if (typeof option['width'] != 'undeinfed') { modalobj.find('.modal-dialog').addClass('modal-lg'); } if (events) { for (i in events) { if (typeof events[i] == 'function') { modalobj.on(i, events[i]); } } } modalobj.find('.modal-body').load(url, function(){ $('.js-model-form').each(function(){ $(this).attr('action', $(this).attr('action') + '&isajax=1&target=formtarget'); $(this).attr('target', '_formtarget'); }) }); modalobj.on('hidden.bs.modal', function(){modalobj.remove();}); if (typeof events['confirm'] == 'function') { modalobj.find('.confirm', modalobj).on('click', events['confirm']); } return modalobj.modal(option); }; //end of ajaxshow util.cookie = { 'prefix' : '', // 保存 Cookie 'set' : function(name, value, seconds) { expires = new Date(); expires.setTime(expires.getTime() + (1000 * seconds)); document.cookie = this.name(name) + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/"; }, // 获取 Cookie 'get' : function(name) { cookie_name = this.name(name) + "="; cookie_length = document.cookie.length; cookie_begin = 0; while (cookie_begin < cookie_length) { value_begin = cookie_begin + cookie_name.length; if (document.cookie.substring(cookie_begin, value_begin) == cookie_name) { var value_end = document.cookie.indexOf ( ";", value_begin); if (value_end == -1) { value_end = cookie_length; } return unescape(document.cookie.substring(value_begin, value_end)); } cookie_begin = document.cookie.indexOf ( " ", cookie_begin) + 1; if (cookie_begin == 0) { break; } } return null; }, // 清除 Cookie 'del' : function(name) { var expireNow = new Date(); document.cookie = this.name(name) + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/"; }, 'name' : function(name) { return this.prefix + name; } };//end cookie util.wechat_audio = function(val, callback, options) { var opts = { type :'voice', direct : false, multiple : false, path : '', dest_dir : '' }; if(val){ opts.path = val; } opts = $.extend({}, opts, options); require(['jquery', 'wechat_fileUploader'], function($, wechat_fileUploader){ wechat_fileUploader.show(function(audios){ if(audios){ if($.isFunction(callback)){ callback(audios); } } }, opts); }); }; util.randomString = function(len) { len = len || 43; var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; var maxPos = $chars.length; var str = ''; for (i = 0; i < len; i++) { str += $chars.charAt(Math.floor(Math.random() * maxPos)); } return str; }; util.countDown = function (time,day_elem,hour_elem,minute_elem,second_elem){ require(['moment'], function(){ var end_time = moment(time),//月份是实际月份-1 sys_second = (end_time-moment())/1000; var timer = setInterval(function(){ if (sys_second > 0) { sys_second -= 1; var day = Math.floor((sys_second / 3600) / 24); var hour = Math.floor((sys_second / 3600) % 24); var minute = Math.floor((sys_second / 60) % 60); var second = Math.floor(sys_second % 60); if(day<10){ day = "0"+day; } if(day>999){ day = "99+"; } day_elem && $(day_elem).text(day);//计算天 $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时 $(minute_elem).text(minute<10?"0"+minute:minute);//计算分 $(second_elem).text(second<10?"0"+second:second);// 计算秒 } else { clearInterval(timer); location.reload(); } }, 1000); }); };