afui.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /**
  2. * desc: 对afui进行扩展
  3. * author: wangyang
  4. * date: 2015-04-12
  5. */
  6. define(['jquery', 'appframeworkui'], function($, afui){
  7. $.extend(afui, {
  8. //开启自定义弹窗
  9. simple_popup: function(content){
  10. if ($.query('#simple_popup').length == 0){
  11. $.query('#afui').append('<div id="simple_popup" class="box_center"><div id="popup_content"></div></div>');
  12. }
  13. $.query('#popup_content').html('').append(content);
  14. $.query('#simple_popup').show();
  15. },
  16. //关闭自定义弹窗
  17. hide_popup: function(callback){
  18. $.query('#simple_popup').hide();
  19. if (typeof(callback) === 'function'){
  20. callback.call();
  21. }
  22. },
  23. /**
  24. * 常用的弹出框
  25. * @param {options:{
  26. 'title' : '',
  27. 'text' : '',
  28. 'buttons' : [{'text' : '', handler : function(){}},...]
  29. } }
  30. * @returns {}
  31. */
  32. popular_popup: function(options){
  33. var defaults = {
  34. title: '',
  35. text: '欢迎来到壹管家',
  36. buttons : [
  37. {
  38. text : '我知道了',
  39. handler : function(){}
  40. }
  41. ],
  42. onOpen: function(){
  43. $.query('.panel').addClass('prevent-pointer-events');
  44. },
  45. onClose: function(){
  46. setTimeout(function(){
  47. $.query('.panel').removeClass('prevent-pointer-events');
  48. }, 1000);
  49. }
  50. };
  51. var new_options = $.extend({}, defaults, options);
  52. var button_class = '';
  53. var buttons = new_options.buttons;
  54. if (buttons.length > 2){
  55. buttons = buttons.slice(0, 2);
  56. }
  57. if (buttons.length == 1){
  58. button_class = ' one_button';
  59. } else if (buttons.length == 2){
  60. button_class = ' two_button';
  61. }
  62. var htm = '<div id="popup_box">';
  63. htm += '<div class="box_center"><span class="popup_title">' + new_options.title + '</span></div>';
  64. htm += '<div class="box_center popup_text">' + new_options.text + '</div>';
  65. htm += '<div class="box button_box">';
  66. if (buttons.length == 1){
  67. htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="action">' + buttons[0]['text'] + '</a></div>';
  68. } else if (buttons.length == 2){
  69. htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="cancel">' + buttons[0]['text'] + '</a></div>';
  70. htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="action">' + buttons[1]['text'] + '</a></div>';
  71. }
  72. htm += '</div>';
  73. htm += '</div>';
  74. $.simple_popup(htm);
  75. if (typeof(new_options.onOpen) == 'function'){
  76. new_options.onOpen.call();
  77. }
  78. $.query('#cancel').on('tap', function(){
  79. $.hide_popup(new_options.onClose);
  80. buttons[0].handler.call();
  81. });
  82. $.query('#action').on('tap', function(){
  83. $.hide_popup(new_options.onClose);
  84. if (buttons.length == 1){
  85. buttons[0].handler.call();
  86. } else if (buttons.length == 2){
  87. buttons[1].handler.call();
  88. }
  89. });
  90. },
  91. //对带验证的ajax
  92. sign_ajax: function(options){
  93. var params = options.data;
  94. var sgf = options.success;
  95. options.success = function(res){
  96. alert(res.error_code);
  97. if ( res.error_code == '1001' || res.error_code == "1003") {
  98. native.getNewKey();
  99. return ;
  100. };
  101. sgf(res);
  102. }
  103. if (!!!params.time){
  104. params.time = new Date().getTime() / 1000;
  105. }
  106. sign_queue.push(options);
  107. if (sign_queue.length == 1){
  108. native.getSign(sign_queue[0].data, sign_callback);
  109. }
  110. },
  111. //touch绑定事件的封装
  112. new_touch: function(el, callback, parent_dom){
  113. var event = 'tap';
  114. if (!((window.DocumentTouch && document instanceof DocumentTouch) || 'ontouchstart' in window)){
  115. event = 'click';
  116. }
  117. if (parent_dom !== undefined){
  118. $(parent_dom).on(event, el, function(ev){
  119. callback.call(this, ev);
  120. });
  121. } else {
  122. $(el).on(event, function(ev){
  123. callback.call(this, ev);
  124. });
  125. }
  126. },
  127. //显示loading mask并锁定UI
  128. show_loading: function(message){
  129. if (typeof message == 'undefined'){
  130. message = '加载中';
  131. }
  132. $.ui.showMask(message);
  133. $.ui.blockUI();
  134. var that = this;
  135. setTimeout(function(){
  136. that.hide_loading();
  137. }, 10000);
  138. },
  139. //隐藏loading mas并解锁UI
  140. hide_loading: function(){
  141. $.ui.hideMask();
  142. $.ui.unblockUI();
  143. },
  144. //显示右侧边栏
  145. show_side_menu: function(){
  146. require(['iscroll'], function(IScroll){
  147. if (right_selector_scroll === null){
  148. right_selector_scroll = new IScroll('#right_selector_scroll');
  149. } else {
  150. right_selector_scroll.refresh();
  151. }
  152. });
  153. $.query('#content').addClass('prevent-pointer-events');
  154. $.ui.toggleRightSideMenu(true, function(){
  155. $.query('#afui').one('swipeRight', function(){
  156. $.ui.toggleRightSideMenu(false, null, 200);
  157. setTimeout(function(){
  158. $.query('#content').removeClass('prevent-pointer-events');
  159. }, 500);
  160. });
  161. }, 200);
  162. },
  163. //关闭右侧边栏
  164. hide_side_menu: function(){
  165. setTimeout(function(){
  166. $.query('#content').removeClass('prevent-pointer-events');
  167. }, 500);
  168. $.ui.toggleRightSideMenu(false, function(){
  169. $.query('#afui').unbind('swipeRight');
  170. }, 200);
  171. }
  172. });
  173. return afui;
  174. });