人人商城

util.js 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. util = {
  2. log : function(){
  3. if (window.sys && window.sys.debug) {
  4. Function.apply.call(console.log, console, arguments)
  5. }
  6. },
  7. guid : (function(){
  8. var guid = 0
  9. return function(){
  10. return 'guid-' + guid++;
  11. };
  12. })(),
  13. search : function(name){
  14. var result = location.search.match(new RegExp("[\?\&]" + name+ "=([^\&]+)","i"));
  15. if (result == null || result.length < 1){
  16. return "";
  17. }
  18. return result[1];
  19. },
  20. };
  21. util.msg = function(content, callback, options) {
  22. var opts = {
  23. time : 2000,
  24. type :'success',
  25. skin: 'layer-ext-we7',
  26. shade : 0.3,
  27. };
  28. opts = $.extend({}, opts, options);
  29. var type = 1;
  30. if (opts.type == 'info') {
  31. type = 0;
  32. } else if (opts.type == 'error') {
  33. type = 2;
  34. } else {
  35. type = 1;
  36. }
  37. require(['layer'], function(){
  38. layer.msg(content, {
  39. time : opts.time, //2s后自动关闭
  40. icon : type, // 图标 0 叹号 1 正确 2 错误
  41. shade : opts.shade, // 遮罩
  42. }, function(data) {
  43. if ($.isFunction(callback)) {
  44. callback(data);
  45. };
  46. });
  47. });
  48. };
  49. util.confirm = function(content,success_callback, cancel_callback, options) {
  50. var opts = {
  51. title : '提示',
  52. btn : ['确定', '取消'],
  53. skin: 'layer-ext-we7',
  54. icon : 3,
  55. shade : 0.3,
  56. };
  57. opts = $.extend({}, opts, options);
  58. require(['layer'], function(){
  59. layer.confirm(
  60. content, //内容
  61. //配置
  62. {
  63. title: opts.title,
  64. btn: opts.btn, //按钮 可以不需要
  65. icon: opts.icon //图标
  66. },
  67. function(data) {
  68. if ($.isFunction(success_callback)) {
  69. success_callback(data);
  70. };
  71. util.closeAll();
  72. },
  73. function(data) {
  74. if ($.isFunction(cancel_callback)) {
  75. cancel_callback(data);
  76. };
  77. }
  78. );
  79. });
  80. };
  81. util.prompt = function(title, callback, options) {
  82. var opts = {
  83. skin: 'layer-ext-we7',
  84. formType: 1, // 0 input="text" 1 input="password" 2 textarea
  85. shade : 0.3,
  86. };
  87. opts = $.extend({}, opts, options);
  88. require(['layer'], function(){
  89. layer.prompt({
  90. title: title,
  91. skin: opts.skin,
  92. formType: opts.formType,
  93. shade : opts.shade
  94. }, function(data) {
  95. if ($.isFunction(callback)) {
  96. callback(data);
  97. };
  98. util.closeAll();
  99. });
  100. });
  101. };
  102. util.loading_layers = [];
  103. util.load = function() {
  104. require(['layer'], function(){
  105. var index = layer.load(2, {
  106. shade: 0.3 //不显示遮罩层
  107. });
  108. util.loading_layers.push(index);
  109. });
  110. };
  111. util.loadClose = function(){
  112. var index;
  113. while(index = util.loading_layers.pop()) {
  114. util.close(index);
  115. };
  116. };
  117. util.close = function(index) {
  118. require(['layer'], function(){
  119. layer.close(index);
  120. });
  121. };
  122. util.closeAll = function() {
  123. require(['layer'], function(){
  124. layer.closeAll();
  125. });
  126. };
  127. util.open = function(content, callback, options) {
  128. require(['layer'], function(){
  129. layer.open({
  130. title: '提示', //标题
  131. content: content, //内容
  132. moveOut: true,
  133. yes: function(data) {
  134. if ($.isFunction(callback)) {
  135. callback(data);
  136. };
  137. }
  138. });
  139. });
  140. };
  141. util.alert = function(content, callback) {
  142. require(['layer'], function(){
  143. layer.alert(content, {
  144. title: '提示',
  145. closeBtn: 1 //关闭按钮是否需要
  146. },
  147. function(data) {
  148. if ($.isFunction(callback)) {
  149. callback(data);
  150. };
  151. });
  152. });
  153. };
  154. util.tomedia = function(src){
  155. if(src.indexOf('http://') == 0 || src.indexOf('https://') == 0 || src.indexOf('./resource') == 0) {
  156. return src;
  157. } else if(src.indexOf('./addons') == 0) {
  158. var url=window.document.location.href;
  159. var pathName = window.document.location.pathname;
  160. var pos = url.indexOf(pathName);
  161. var host = url.substring(0,pos);
  162. if (src.substr(0,1)=='.') {
  163. src=src.substr(1);
  164. }
  165. return host + src;
  166. } else {
  167. return 'http://we7cloud-10016060.file.myqcloud.com/' + src;
  168. }
  169. };
  170. util.clip = function(elm, str) {
  171. if(elm.clip) {
  172. return;
  173. }
  174. require(['jquery.zclip'], function(){
  175. $(elm).zclip({
  176. path: './resource/components/zclip/ZeroClipboard.swf',
  177. copy: str,
  178. afterCopy: function(){
  179. var obj = $('<em> &nbsp; <span class="label label-success"><i class="fa fa-check-circle"></i> 复制成功</span></em>');
  180. var enext = $(elm).next().html();
  181. if (!enext || enext.indexOf('&nbsp; <span class="label label-success"><i class="fa fa-check-circle"></i> 复制成功</span>')<0) {
  182. $(elm).after(obj);
  183. }
  184. setTimeout(function(){
  185. obj.remove();
  186. }, 2000);
  187. }
  188. });
  189. elm.clip = true;
  190. });
  191. };
  192. util.colorpicker = function(elm, callback) {
  193. require(['colorpicker'], function(){
  194. $(elm).spectrum({
  195. className : "colorpicker",
  196. showInput: true,
  197. showInitial: true,
  198. showPalette: true,
  199. maxPaletteSize: 10,
  200. preferredFormat: "hex",
  201. change: function(color) {
  202. if($.isFunction(callback)) {
  203. callback(color);
  204. }
  205. },
  206. palette: [
  207. ["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", "rgb(153, 153, 153)","rgb(183, 183, 183)",
  208. "rgb(204, 204, 204)", "rgb(217, 217, 217)","rgb(239, 239, 239)", "rgb(243, 243, 243)", "rgb(255, 255, 255)"],
  209. ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)",
  210. "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"],
  211. ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
  212. "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
  213. "rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
  214. "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
  215. "rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
  216. "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
  217. "rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
  218. "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
  219. "rgb(133, 32, 12)", "rgb(153, 0, 0)", "rgb(180, 95, 6)", "rgb(191, 144, 0)", "rgb(56, 118, 29)",
  220. "rgb(19, 79, 92)", "rgb(17, 85, 204)", "rgb(11, 83, 148)", "rgb(53, 28, 117)", "rgb(116, 27, 71)",
  221. "rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
  222. "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"]
  223. ]
  224. });
  225. });
  226. }
  227. util.uploadMultiPictures = function(callback, options){
  228. var opts = {
  229. type :'image',
  230. tabs : {
  231. 'upload' : 'active',
  232. 'browser' : '',
  233. 'crawler' : ''
  234. },
  235. path : '',
  236. direct : false,
  237. multi : true,
  238. dest_dir : ''
  239. };
  240. opts = $.extend({}, opts, options);
  241. require(['jquery', 'fileUploader'], function($, fileUploader){
  242. fileUploader.show(function(images){
  243. if(images.length > 0){
  244. if($.isFunction(callback)){
  245. callback(images);
  246. }
  247. }
  248. }, opts);
  249. });
  250. }
  251. util.editor = function(elm, callback){
  252. var id = elm.id;
  253. if(!id) {
  254. id = 'editor-' + Math.random();
  255. elm.id = id;
  256. }
  257. if(!elm.editor) {
  258. require(['editor'], function(){
  259. var editor = tinyMCE.createEditor(id, {
  260. plugins: [
  261. "advlist autolink lists link image multiimage charmap print preview hr anchor pagebreak",
  262. "searchreplace wordcount visualblocks visualchars code fullscreen",
  263. "insertdatetime media nonbreaking save table contextmenu directionality",
  264. "emoticons template paste textcolor"
  265. ],
  266. toolbar1: "undo redo | bold italic | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | preview fullscreen",
  267. toolbar2: "code print | styleselect fontsizeselect link image multiimage media emoticons ",
  268. language: 'zh_CN',
  269. paste_webkit_styles: 'all',
  270. paste_preprocess: function(plugin, args) {
  271. args.content = args.content.replace(/!important/g, '');
  272. },
  273. fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt",
  274. menubar: false
  275. });
  276. elm.editor = editor;
  277. editor.render();
  278. if($.isFunction(callback)) {
  279. callback(elm, editor);
  280. }
  281. });
  282. }
  283. return {
  284. getContent : function(){
  285. if(elm.editor) {
  286. return elm.editor.getContent();
  287. } else {
  288. return '';
  289. }
  290. }
  291. };
  292. };
  293. // target dom 对象
  294. util.emotion = function(elm, target, callback) {
  295. require(['jquery.caret', 'bootstrap', 'css!../../components/emotions/emotions.css'],function($){
  296. $(function() {
  297. var emotions_html = '<table class="emotions" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="eItem" style="background-position:0px 0;" data-title="微笑" data-code="::)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/0.gif"></div></td><td><div class="eItem" style="background-position:-24px 0;" data-title="撇嘴" data-code="::~" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/1.gif"></div></td><td><div class="eItem" style="background-position:-48px 0;" data-title="色" data-code="::B" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/2.gif"></div></td><td><div class="eItem" style="background-position:-72px 0;" data-title="发呆" data-code="::|" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/3.gif"></div></td><td><div class="eItem" style="background-position:-96px 0;" data-title="得意" data-code=":8-)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/4.gif"></div></td><td><div class="eItem" style="background-position:-120px 0;" data-title="流泪" data-code="::<" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/5.gif"></div></td><td><div class="eItem" style="background-position:-144px 0;" data-title="害羞" data-code="::$" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/6.gif"></div></td><td><div class="eItem" style="background-position:-168px 0;" data-title="闭嘴" data-code="::X" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/7.gif"></div></td><td><div class="eItem" style="background-position:-192px 0;" data-title="睡" data-code="::Z" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/8.gif"></div></td><td><div class="eItem" style="background-position:-216px 0;" data-title="大哭" data-code="::\'(" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/9.gif"></div></td><td><div class="eItem" style="background-position:-240px 0;" data-title="尴尬" data-code="::-|" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/10.gif"></div></td><td><div class="eItem" style="background-position:-264px 0;" data-title="发怒" data-code="::@" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/11.gif"></div></td><td><div class="eItem" style="background-position:-288px 0;" data-title="调皮" data-code="::P" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/12.gif"></div></td><td><div class="eItem" style="background-position:-312px 0;" data-title="呲牙" data-code="::D" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/13.gif"></div></td><td><div class="eItem" style="background-position:-336px 0;" data-title="惊讶" data-code="::O" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/14.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-360px 0;" data-title="难过" data-code="::(" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/15.gif"></div></td><td><div class="eItem" style="background-position:-384px 0;" data-title="酷" data-code="::+" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/16.gif"></div></td><td><div class="eItem" style="background-position:-408px 0;" data-title="冷汗" data-code=":--b" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/17.gif"></div></td><td><div class="eItem" style="background-position:-432px 0;" data-title="抓狂" data-code="::Q" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/18.gif"></div></td><td><div class="eItem" style="background-position:-456px 0;" data-title="吐" data-code="::T" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/19.gif"></div></td><td><div class="eItem" style="background-position:-480px 0;" data-title="偷笑" data-code=":,@P" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/20.gif"></div></td><td><div class="eItem" style="background-position:-504px 0;" data-title="可爱" data-code=":,@-D" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/21.gif"></div></td><td><div class="eItem" style="background-position:-528px 0;" data-title="白眼" data-code="::d" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/22.gif"></div></td><td><div class="eItem" style="background-position:-552px 0;" data-title="傲慢" data-code=":,@o" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/23.gif"></div></td><td><div class="eItem" style="background-position:-576px 0;" data-title="饥饿" data-code="::g" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/24.gif"></div></td><td><div class="eItem" style="background-position:-600px 0;" data-title="困" data-code=":|-)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/25.gif"></div></td><td><div class="eItem" style="background-position:-624px 0;" data-title="惊恐" data-code="::!" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/26.gif"></div></td><td><div class="eItem" style="background-position:-648px 0;" data-title="流汗" data-code="::L" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/27.gif"></div></td><td><div class="eItem" style="background-position:-672px 0;" data-title="憨笑" data-code="::>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/28.gif"></div></td><td><div class="eItem" style="background-position:-696px 0;" data-title="大兵" data-code="::,@" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/29.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-720px 0;" data-title="奋斗" data-code=":,@f" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/30.gif"></div></td><td><div class="eItem" style="background-position:-744px 0;" data-title="咒骂" data-code="::-S" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/31.gif"></div></td><td><div class="eItem" style="background-position:-768px 0;" data-title="疑问" data-code=":?" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/32.gif"></div></td><td><div class="eItem" style="background-position:-792px 0;" data-title="嘘" data-code=":,@x" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/33.gif"></div></td><td><div class="eItem" style="background-position:-816px 0;" data-title="晕" data-code=":,@@" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/34.gif"></div></td><td><div class="eItem" style="background-position:-840px 0;" data-title="折磨" data-code="::8" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/35.gif"></div></td><td><div class="eItem" style="background-position:-864px 0;" data-title="衰" data-code=":,@!" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/36.gif"></div></td><td><div class="eItem" style="background-position:-888px 0;" data-title="骷髅" data-code=":!!!" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/37.gif"></div></td><td><div class="eItem" style="background-position:-912px 0;" data-title="敲打" data-code=":xx" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/38.gif"></div></td><td><div class="eItem" style="background-position:-936px 0;" data-title="再见" data-code=":bye" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/39.gif"></div></td><td><div class="eItem" style="background-position:-960px 0;" data-title="擦汗" data-code=":wipe" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/40.gif"></div></td><td><div class="eItem" style="background-position:-984px 0;" data-title="抠鼻" data-code=":dig" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/41.gif"></div></td><td><div class="eItem" style="background-position:-1008px 0;" data-title="鼓掌" data-code=":handclap" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/42.gif"></div></td><td><div class="eItem" style="background-position:-1032px 0;" data-title="糗大了" data-code=":&-(" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/43.gif"></div></td><td><div class="eItem" style="background-position:-1056px 0;" data-title="坏笑" data-code=":B-)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/44.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-1080px 0;" data-title="左哼哼" data-code=":<@" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/45.gif"></div></td><td><div class="eItem" style="background-position:-1104px 0;" data-title="右哼哼" data-code=":@>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/46.gif"></div></td><td><div class="eItem" style="background-position:-1128px 0;" data-title="哈欠" data-code="::-O" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/47.gif"></div></td><td><div class="eItem" style="background-position:-1152px 0;" data-title="鄙视" data-code=":>-|" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/48.gif"></div></td><td><div class="eItem" style="background-position:-1176px 0;" data-title="委屈" data-code=":P-(" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/49.gif"></div></td><td><div class="eItem" style="background-position:-1200px 0;" data-title="快哭了" data-code="::\'|" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/50.gif"></div></td><td><div class="eItem" style="background-position:-1224px 0;" data-title="阴险" data-code=":X-)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/51.gif"></div></td><td><div class="eItem" style="background-position:-1248px 0;" data-title="亲亲" data-code="::*" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/52.gif"></div></td><td><div class="eItem" style="background-position:-1272px 0;" data-title="吓" data-code=":@x" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/53.gif"></div></td><td><div class="eItem" style="background-position:-1296px 0;" data-title="可怜" data-code=":8*" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/54.gif"></div></td><td><div class="eItem" style="background-position:-1320px 0;" data-title="菜刀" data-code=":pd" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/55.gif"></div></td><td><div class="eItem" style="background-position:-1344px 0;" data-title="西瓜" data-code=":<W>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/56.gif"></div></td><td><div class="eItem" style="background-position:-1368px 0;" data-title="啤酒" data-code=":beer" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/57.gif"></div></td><td><div class="eItem" style="background-position:-1392px 0;" data-title="篮球" data-code=":basketb" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/58.gif"></div></td><td><div class="eItem" style="background-position:-1416px 0;" data-title="乒乓" data-code=":oo" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/59.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-1440px 0;" data-title="咖啡" data-code=":coffee" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/60.gif"></div></td><td><div class="eItem" style="background-position:-1464px 0;" data-title="饭" data-code=":eat" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/61.gif"></div></td><td><div class="eItem" style="background-position:-1488px 0;" data-title="猪头" data-code=":pig" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/62.gif"></div></td><td><div class="eItem" style="background-position:-1512px 0;" data-title="玫瑰" data-code=":rose" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/63.gif"></div></td><td><div class="eItem" style="background-position:-1536px 0;" data-title="凋谢" data-code=":fade" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/64.gif"></div></td><td><div class="eItem" style="background-position:-1560px 0;" data-title="示爱" data-code=":showlove" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/65.gif"></div></td><td><div class="eItem" style="background-position:-1584px 0;" data-title="爱心" data-code=":heart" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/66.gif"></div></td><td><div class="eItem" style="background-position:-1608px 0;" data-title="心碎" data-code=":break" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/67.gif"></div></td><td><div class="eItem" style="background-position:-1632px 0;" data-title="蛋糕" data-code=":cake" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/68.gif"></div></td><td><div class="eItem" style="background-position:-1656px 0;" data-title="闪电" data-code=":li" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/69.gif"></div></td><td><div class="eItem" style="background-position:-1680px 0;" data-title="炸弹" data-code=":bome" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/70.gif"></div></td><td><div class="eItem" style="background-position:-1704px 0;" data-title="刀" data-code=":kn" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/71.gif"></div></td><td><div class="eItem" style="background-position:-1728px 0;" data-title="足球" data-code=":footb" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/72.gif"></div></td><td><div class="eItem" style="background-position:-1752px 0;" data-title="瓢虫" data-code=":ladybug" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/73.gif"></div></td><td><div class="eItem" style="background-position:-1776px 0;" data-title="便便" data-code=":shit" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/74.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-1800px 0;" data-title="月亮" data-code=":moon" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/75.gif"></div></td><td><div class="eItem" style="background-position:-1824px 0;" data-title="太阳" data-code=":sun" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/76.gif"></div></td><td><div class="eItem" style="background-position:-1848px 0;" data-title="礼物" data-code=":gift" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/77.gif"></div></td><td><div class="eItem" style="background-position:-1872px 0;" data-title="拥抱" data-code=":hug" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/78.gif"></div></td><td><div class="eItem" style="background-position:-1896px 0;" data-title="强" data-code=":strong" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/79.gif"></div></td><td><div class="eItem" style="background-position:-1920px 0;" data-title="弱" data-code=":weak" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/80.gif"></div></td><td><div class="eItem" style="background-position:-1944px 0;" data-title="握手" data-code=":share" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/81.gif"></div></td><td><div class="eItem" style="background-position:-1968px 0;" data-title="胜利" data-code=":v" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/82.gif"></div></td><td><div class="eItem" style="background-position:-1992px 0;" data-title="抱拳" data-code=":@)" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/83.gif"></div></td><td><div class="eItem" style="background-position:-2016px 0;" data-title="勾引" data-code=":jj" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/84.gif"></div></td><td><div class="eItem" style="background-position:-2040px 0;" data-title="拳头" data-code=":@@" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/85.gif"></div></td><td><div class="eItem" style="background-position:-2064px 0;" data-title="差劲" data-code=":bad" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/86.gif"></div></td><td><div class="eItem" style="background-position:-2088px 0;" data-title="爱你" data-code=":lvu" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/87.gif"></div></td><td><div class="eItem" style="background-position:-2112px 0;" data-title="NO" data-code=":no" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/88.gif"></div></td><td><div class="eItem" style="background-position:-2136px 0;" data-title="OK" data-code=":ok" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/89.gif"></div></td></tr><tr><td><div class="eItem" style="background-position:-2160px 0;" data-title="爱情" data-code=":love" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/90.gif"></div></td><td><div class="eItem" style="background-position:-2184px 0;" data-title="飞吻" data-code=":<L>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/91.gif"></div></td><td><div class="eItem" style="background-position:-2208px 0;" data-title="跳跳" data-code=":jump" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/92.gif"></div></td><td><div class="eItem" style="background-position:-2232px 0;" data-title="发抖" data-code=":shake" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/93.gif"></div></td><td><div class="eItem" style="background-position:-2256px 0;" data-title="怄火" data-code=":<O>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/94.gif"></div></td><td><div class="eItem" style="background-position:-2280px 0;" data-title="转圈" data-code=":circle" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/95.gif"></div></td><td><div class="eItem" style="background-position:-2304px 0;" data-title="磕头" data-code=":kotow" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/96.gif"></div></td><td><div class="eItem" style="background-position:-2328px 0;" data-title="回头" data-code=":turn" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/97.gif"></div></td><td><div class="eItem" style="background-position:-2352px 0;" data-title="跳绳" data-code=":skip" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/98.gif"></div></td><td><div class="eItem" style="background-position:-2376px 0;" data-title="挥手" data-code=":oY" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/99.gif"></div></td><td><div class="eItem" style="background-position:-2400px 0;" data-title="激动" data-code=":#-0" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/100.gif"></div></td><td><div class="eItem" style="background-position:-2424px 0;" data-title="街舞" data-code=":hiphot" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/101.gif"></div></td><td><div class="eItem" style="background-position:-2448px 0;" data-title="献吻" data-code=":kiss" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/102.gif"></div></td><td><div class="eItem" style="background-position:-2472px 0;" data-title="左太极" data-code=":<&" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/103.gif"></div></td><td><div class="eItem" style="background-position:-2496px 0;" data-title="右太极" data-code=":&>" data-gifurl="http://res.mail.qq.com/zh_CN/images/mo/DEFAULT2/104.gif"></div></td></tr></tbody></table><div class="emotionsGif" style=""></div>';
  298. $(elm).popover({
  299. html: true,
  300. content: emotions_html,
  301. placement:"bottom"
  302. });
  303. $(elm).one('shown.bs.popover', function(){
  304. $(elm).next().mouseleave(function(){
  305. $(elm).popover('hide');
  306. });
  307. $(elm).next().delegate(".eItem", "mouseover", function(){
  308. var emo_img = '<img src="'+$(this).attr("data-gifurl")+'" alt="mo-'+$(this).attr("data-title")+'" />';
  309. var emo_txt = '/'+$(this).attr("data-code");
  310. $(elm).next().find(".emotionsGif").html(emo_img);
  311. });
  312. $(elm).next().delegate(".eItem", "click", function(){
  313. $(target).setCaret();
  314. var emo_txt = '/'+$(this).attr("data-code");
  315. $(target).insertAtCaret(emo_txt);
  316. $(elm).popover('hide');
  317. if($.isFunction(callback)) {
  318. callback(emo_txt, elm, target);
  319. }
  320. });
  321. });
  322. });
  323. });
  324. };
  325. util.loading = function() {
  326. var loadingid = 'modal-loading';
  327. var modalobj = $('#' + loadingid);
  328. if(modalobj.length == 0) {
  329. $(document.body).append('<div id="' + loadingid + '" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div>');
  330. modalobj = $('#' + loadingid);
  331. html =
  332. '<div class="modal-dialog">'+
  333. ' <div style="text-align:center; background-color: transparent;">'+
  334. ' <img style="width:48px; height:48px; margin-top:100px;" src="images/loading.gif" title="正在努力加载...">'+
  335. ' </div>'+
  336. '</div>';
  337. modalobj.html(html);
  338. }
  339. modalobj.modal('show');
  340. modalobj.next().css('z-index', 999999);
  341. return modalobj;
  342. };
  343. util.loaded = function(){
  344. var loadingid = 'modal-loading';
  345. var modalobj = $('#' + loadingid);
  346. if(modalobj.length > 0){
  347. modalobj.modal('hide');
  348. }
  349. }
  350. util.dialog = function(title, content, footer, options) {
  351. if(!options) {
  352. options = {};
  353. }
  354. if(!options.containerName) {
  355. options.containerName = 'modal-message';
  356. }
  357. var modalobj = $('#' + options.containerName);
  358. if(modalobj.length == 0) {
  359. $(document.body).append('<div id="' + options.containerName + '" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"></div>');
  360. modalobj = $('#' + options.containerName);
  361. }
  362. html =
  363. '<div class="modal-dialog">'+
  364. ' <div class="modal-content">';
  365. if(title) {
  366. html +=
  367. '<div class="modal-header">'+
  368. ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>'+
  369. ' <h4>' + title + '</h4>'+
  370. '</div>';
  371. }
  372. if(content) {
  373. if(!$.isArray(content)) {
  374. html += '<div class="modal-body">'+ content + '</div>';
  375. } else {
  376. html += '<div class="modal-body">正在加载中</div>';
  377. }
  378. }
  379. if(footer) {
  380. html +=
  381. '<div class="modal-footer">'+ footer + '</div>';
  382. }
  383. html += ' </div></div>';
  384. modalobj.html(html);
  385. if(content && $.isArray(content)) {
  386. var embed = function(c) {
  387. modalobj.find('.modal-body').html(c);
  388. };
  389. if(content.length == 2) {
  390. $.post(content[0], content[1]).success(embed);
  391. } else {
  392. $.get(content[0]).success(embed);
  393. }
  394. }
  395. return modalobj;
  396. };
  397. util.message = function(msg, redirect, type){
  398. if (!redirect && !type) {
  399. type = 'info';
  400. }
  401. if ($.inArray(type, ['success', 'error', 'info', 'warning']) == -1) {
  402. type = '';
  403. }
  404. if (type == '') {
  405. type = redirect == '' ? 'error' : 'success';
  406. }
  407. var icons = {
  408. success: 'check-circle',
  409. error: 'times-circle',
  410. info: 'info-circle',
  411. warning: 'exclamation-triangle'
  412. };
  413. var p = '';
  414. if (redirect && redirect.length > 0) {
  415. if (redirect == 'back') {
  416. p = '<p>[<a href="javascript:;" onclick="history.go(-1)">返回上一页</a>] &nbsp; [<a href="./?refresh">回首页</a>]</p>';
  417. }
  418. }
  419. var content =
  420. '<div class="form-group">' +
  421. '<div class="col-sm-2">' +
  422. '<i class="pull-left fa fa-4x fa-'+icons[type]+'"></i>'+
  423. '</div>' +
  424. '<div class="col-sm-9">' +
  425. '<p>'+ msg +'</p>' + p +
  426. '</div>'+
  427. '<div class="clearfix"></div>' +
  428. '</div>';
  429. var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">确认</button>';
  430. var modalobj = util.dialog('系统提示', content, footer, {'containerName': 'modal-message'});
  431. modalobj.find('.modal-content').addClass('alert alert-' + type);
  432. modalobj.on('hide.bs.modal', function () {
  433. if (redirect) {
  434. if (redirect == 'back') {
  435. history.go(-1);
  436. }else if (redirect == 'close'){
  437. (function(){
  438. if (navigator.appName=="Netscape") {
  439. window.open('','_self','');
  440. window.close();
  441. } else {
  442. window.close();
  443. }
  444. })();
  445. } else {
  446. window.location.href = redirect;
  447. }
  448. }
  449. });
  450. modalobj.on('hidden.bs.modal', function () {
  451. modalobj.remove();
  452. });
  453. modalobj.modal({
  454. backdrop: 'static'
  455. });
  456. return modalobj;
  457. };
  458. util.map = function(val, callback){
  459. require(['map'], function(BMap){
  460. if(!val) {
  461. val = {};
  462. }
  463. if(!val.lng) {
  464. val.lng = 116.403851;
  465. }
  466. if(!val.lat) {
  467. val.lat = 39.915177;
  468. }
  469. var point = new BMap.Point(val.lng, val.lat);
  470. var geo = new BMap.Geocoder();
  471. var modalobj = $('#map-dialog');
  472. if(modalobj.length == 0) {
  473. var content =
  474. '<div class="form-group">' +
  475. '<div class="input-group">' +
  476. '<input type="text" class="form-control" placeholder="请输入地址来直接查找相关位置">' +
  477. '<div class="input-group-btn">' +
  478. '<button class="btn btn-default"><i class="icon-search"></i> 搜索</button>' +
  479. '</div>' +
  480. '</div>' +
  481. '</div>' +
  482. '<div id="map-container" style="height:400px;"></div>';
  483. var footer =
  484. '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>' +
  485. '<button type="button" class="btn btn-primary">确认</button>';
  486. modalobj = util.dialog('请选择地点', content, footer, {containerName : 'map-dialog'});
  487. modalobj.find('.modal-dialog').css('width', '80%');
  488. modalobj.modal({'keyboard': false});
  489. map = util.map.instance = new BMap.Map('map-container');
  490. map.centerAndZoom(point, 12);
  491. map.enableScrollWheelZoom();
  492. map.enableDragging();
  493. map.enableContinuousZoom();
  494. map.addControl(new BMap.NavigationControl());
  495. map.addControl(new BMap.OverviewMapControl());
  496. marker = util.map.marker = new BMap.Marker(point);
  497. marker.setLabel(new BMap.Label('请您移动此标记,选择您的坐标!', {'offset': new BMap.Size(10,-20)}));
  498. map.addOverlay(marker);
  499. marker.enableDragging();
  500. marker.addEventListener('dragend', function(e){
  501. var point = marker.getPosition();
  502. geo.getLocation(point, function(address){
  503. modalobj.find('.input-group :text').val(address.address);
  504. });
  505. });
  506. function searchAddress(address) {
  507. geo.getPoint(address, function(point){
  508. map.panTo(point);
  509. marker.setPosition(point);
  510. marker.setAnimation(BMAP_ANIMATION_BOUNCE);
  511. setTimeout(function(){marker.setAnimation(null)}, 3600);
  512. });
  513. }
  514. modalobj.find('.input-group :text').keydown(function(e){
  515. if(e.keyCode == 13) {
  516. var kw = $(this).val();
  517. searchAddress(kw);
  518. }
  519. });
  520. modalobj.find('.input-group button').click(function(){
  521. var kw = $(this).parent().prev().val();
  522. searchAddress(kw);
  523. });
  524. }
  525. modalobj.off('shown.bs.modal');
  526. modalobj.on('shown.bs.modal', function(){
  527. marker.setPosition(point);
  528. map.panTo(marker.getPosition());
  529. });
  530. modalobj.find('button.btn-primary').off('click');
  531. modalobj.find('button.btn-primary').on('click', function(){
  532. if($.isFunction(callback)) {
  533. var point = util.map.marker.getPosition();
  534. geo.getLocation(point, function(address){
  535. var val = {lng: point.lng, lat: point.lat, label: address.address};
  536. callback(val);
  537. });
  538. }
  539. modalobj.modal('hide');
  540. });
  541. modalobj.modal('show');
  542. });
  543. }; // end of map
  544. util.iconBrowser = function(callback){
  545. var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>';
  546. var modalobj = util.dialog('请选择图标',['./index.php?c=utility&a=icon&callback=selectIconComplete'],footer,{containerName:'icon-container'});
  547. modalobj.modal({'keyboard': false});
  548. modalobj.find('.modal-dialog').css({'width':'70%'});
  549. modalobj.find('.modal-body').css({'height':'70%','overflow-y':'scroll'});
  550. modalobj.modal('show');
  551. window.selectIconComplete = function(ico){
  552. if($.isFunction(callback)){
  553. callback(ico);
  554. modalobj.modal('hide');
  555. }
  556. };
  557. }; // end of icon dialog
  558. util.emojiBrowser = function(callback){
  559. var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>';
  560. var modalobj = util.dialog('请选择表情',['./index.php?c=utility&a=emoji&callback=selectEmojiComplete'],footer,{containerName:'icon-container'});
  561. modalobj.modal({'keyboard': false});
  562. modalobj.find('.modal-dialog').css({'width':'70%'});
  563. modalobj.find('.modal-body').css({'height':'70%','overflow-y':'scroll'});
  564. modalobj.modal('show');
  565. window.selectEmojiComplete = function(emoji){
  566. if($.isFunction(callback)){
  567. callback(emoji);
  568. modalobj.modal('hide');
  569. }
  570. };
  571. }; // end of emoji dialog
  572. util.linkBrowser = function(callback){
  573. var footer = '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>';
  574. var modalobj = util.dialog('请选择链接',['./index.php?c=utility&a=link&callback=selectLinkComplete'],footer,{containerName:'link-container'});
  575. modalobj.modal({'keyboard': false});
  576. modalobj.find('.modal-body').css({'height':'300px','overflow-y':'auto' });
  577. modalobj.modal('show');
  578. window.selectLinkComplete = function(link){
  579. if($.isFunction(callback)){
  580. callback(link);
  581. modalobj.modal('hide');
  582. }
  583. };
  584. }; // end of icon dialog
  585. /**
  586. * val : image 值;
  587. * callback: 回调函数
  588. * base64options: base64(json($options))
  589. * options: {tabs: {'browser': 'active', 'upload': '', 'remote': ''}
  590. **/
  591. util.image = function(val, callback, base64options, options) {
  592. var opts = {
  593. type :'image',
  594. direct : false,
  595. multiple : false,
  596. path : val,
  597. dest_dir : '',
  598. global : false,
  599. thumb : false,
  600. width : 0
  601. };
  602. opts = $.extend({}, opts, options);
  603. opts.type = 'image';
  604. require(['jquery', 'fileUploader'], function($, fileUploader){
  605. fileUploader.show(function(images){
  606. if(images){
  607. if($.isFunction(callback)){
  608. callback(images);
  609. }
  610. }
  611. }, opts);
  612. });
  613. }; // end of image
  614. util.wechat_image = function(val, callback, options) {
  615. var opts = {
  616. type :'image',
  617. direct : false,
  618. multiple : false,
  619. acid : 0,
  620. path : val,
  621. dest_dir : ''
  622. };
  623. opts = $.extend({}, opts, options);
  624. require(['jquery', 'wechat_fileUploader'], function($, wechat_fileUploader){
  625. wechat_fileUploader.show(function(images){
  626. if(images){
  627. if($.isFunction(callback)){
  628. callback(images);
  629. }
  630. }
  631. }, opts);
  632. });
  633. };
  634. util.audio = function(val, callback, base64options, options) {
  635. var opts = {
  636. type :'audio',
  637. direct : false,
  638. multiple : false,
  639. path : '',
  640. dest_dir : ''
  641. };
  642. if(val){
  643. opts.path = val;
  644. }
  645. opts = $.extend({}, opts, options);
  646. opts.type = 'audio';
  647. require(['jquery', 'fileUploader'], function($, fileUploader){
  648. fileUploader.show(function(audios){
  649. if(audios){
  650. if($.isFunction(callback)){
  651. callback(audios);
  652. }
  653. }
  654. }, opts);
  655. });
  656. }; // end of audio
  657. /*
  658. 打开远程地址
  659. @params string url 目标远程地址
  660. @params string title 打开窗口标题,为空则不显示标题。可在返回的HTML定义<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>控制关闭
  661. @params object options 打开窗口的属性配置,可选项backdrop,show,keyboard,remote,width,height。具体参考bootcss模态对话框的options说明
  662. @params object events 窗口的一些回调事件,可选项show,shown,hide,hidden,confirm。回调函数第一个参数对话框JQ对象。具体参考bootcss模态对话框的on说明.
  663. @demo ajaxshow('url', 'title', {'show' : true}, {'hidden' : function(obj) {obj.remove();}});
  664. */
  665. util.ajaxshow = function(url, title, options, events) {
  666. var defaultoptions = {'show' : true};
  667. var defaultevents = {};
  668. var option = $.extend({}, defaultoptions, options);
  669. var events = $.extend({}, defaultevents, events);
  670. var footer = (typeof events['confirm'] == 'function' ? '<a href="javascript:;" class="btn btn-primary confirm">确定</a>' : '') + '<a href="javascript:;" class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</a><iframe id="_formtarget" style="display:none;" name="_formtarget"></iframe>';
  671. var modalobj = util.dialog(title, '正在加载中', footer, {'containerName' : 'modal-panel-ajax'});
  672. if (typeof option['width'] != 'undeinfed') {
  673. modalobj.find('.modal-dialog').addClass('modal-lg');
  674. }
  675. if (events) {
  676. for (i in events) {
  677. if (typeof events[i] == 'function') {
  678. modalobj.on(i, events[i]);
  679. }
  680. }
  681. }
  682. modalobj.find('.modal-body').load(url, function(){
  683. $('.js-model-form').each(function(){
  684. $(this).attr('action', $(this).attr('action') + '&isajax=1&target=formtarget');
  685. $(this).attr('target', '_formtarget');
  686. })
  687. });
  688. modalobj.on('hidden.bs.modal', function(){modalobj.remove();});
  689. if (typeof events['confirm'] == 'function') {
  690. modalobj.find('.confirm', modalobj).on('click', events['confirm']);
  691. }
  692. return modalobj.modal(option);
  693. }; //end of ajaxshow
  694. util.cookie = {
  695. 'prefix' : '',
  696. // 保存 Cookie
  697. 'set' : function(name, value, seconds) {
  698. expires = new Date();
  699. expires.setTime(expires.getTime() + (1000 * seconds));
  700. document.cookie = this.name(name) + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
  701. },
  702. // 获取 Cookie
  703. 'get' : function(name) {
  704. cookie_name = this.name(name) + "=";
  705. cookie_length = document.cookie.length;
  706. cookie_begin = 0;
  707. while (cookie_begin < cookie_length)
  708. {
  709. value_begin = cookie_begin + cookie_name.length;
  710. if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
  711. {
  712. var value_end = document.cookie.indexOf ( ";", value_begin);
  713. if (value_end == -1)
  714. {
  715. value_end = cookie_length;
  716. }
  717. return unescape(document.cookie.substring(value_begin, value_end));
  718. }
  719. cookie_begin = document.cookie.indexOf ( " ", cookie_begin) + 1;
  720. if (cookie_begin == 0)
  721. {
  722. break;
  723. }
  724. }
  725. return null;
  726. },
  727. // 清除 Cookie
  728. 'del' : function(name) {
  729. var expireNow = new Date();
  730. document.cookie = this.name(name) + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
  731. },
  732. 'name' : function(name) {
  733. return this.prefix + name;
  734. }
  735. };//end cookie
  736. util.wechat_audio = function(val, callback, options) {
  737. var opts = {
  738. type :'voice',
  739. direct : false,
  740. multiple : false,
  741. path : '',
  742. dest_dir : ''
  743. };
  744. if(val){
  745. opts.path = val;
  746. }
  747. opts = $.extend({}, opts, options);
  748. require(['jquery', 'wechat_fileUploader'], function($, wechat_fileUploader){
  749. wechat_fileUploader.show(function(audios){
  750. if(audios){
  751. if($.isFunction(callback)){
  752. callback(audios);
  753. }
  754. }
  755. }, opts);
  756. });
  757. };
  758. util.randomString = function(len) {
  759. len = len || 43;
  760. var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  761. var maxPos = $chars.length;
  762. var str = '';
  763. for (i = 0; i < len; i++) {
  764. str += $chars.charAt(Math.floor(Math.random() * maxPos));
  765. }
  766. return str;
  767. };
  768. util.countDown = function (time,day_elem,hour_elem,minute_elem,second_elem){
  769. require(['moment'], function(){
  770. var end_time = moment(time),//月份是实际月份-1
  771. sys_second = (end_time-moment())/1000;
  772. var timer = setInterval(function(){
  773. if (sys_second > 0) {
  774. sys_second -= 1;
  775. var day = Math.floor((sys_second / 3600) / 24);
  776. var hour = Math.floor((sys_second / 3600) % 24);
  777. var minute = Math.floor((sys_second / 60) % 60);
  778. var second = Math.floor(sys_second % 60);
  779. if(day<10){
  780. day = "0"+day;
  781. }
  782. if(day>999){
  783. day = "99+";
  784. }
  785. day_elem && $(day_elem).text(day);//计算天
  786. $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
  787. $(minute_elem).text(minute<10?"0"+minute:minute);//计算分
  788. $(second_elem).text(second<10?"0"+second:second);// 计算秒
  789. } else {
  790. clearInterval(timer);
  791. location.reload();
  792. }
  793. }, 1000);
  794. });
  795. };