123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /**
- * desc: 对afui进行扩展
- * author: wangyang
- * date: 2015-04-12
- */
- define(['jquery', 'appframeworkui'], function($, afui){
- $.extend(afui, {
- //开启自定义弹窗
- simple_popup: function(content){
- if ($.query('#simple_popup').length == 0){
- $.query('#afui').append('<div id="simple_popup" class="box_center"><div id="popup_content"></div></div>');
- }
- $.query('#popup_content').html('').append(content);
- $.query('#simple_popup').show();
- },
- //关闭自定义弹窗
- hide_popup: function(callback){
- $.query('#simple_popup').hide();
- if (typeof(callback) === 'function'){
- callback.call();
- }
- },
- /**
- * 常用的弹出框
- * @param {options:{
- 'title' : '',
- 'text' : '',
- 'buttons' : [{'text' : '', handler : function(){}},...]
- } }
- * @returns {}
- */
- popular_popup: function(options){
- var defaults = {
- title: '',
- text: '欢迎来到壹管家',
- buttons : [
- {
- text : '我知道了',
- handler : function(){}
- }
- ],
- onOpen: function(){
- $.query('.panel').addClass('prevent-pointer-events');
- },
- onClose: function(){
- setTimeout(function(){
- $.query('.panel').removeClass('prevent-pointer-events');
- }, 1000);
- }
- };
- var new_options = $.extend({}, defaults, options);
- var button_class = '';
- var buttons = new_options.buttons;
- if (buttons.length > 2){
- buttons = buttons.slice(0, 2);
- }
- if (buttons.length == 1){
- button_class = ' one_button';
- } else if (buttons.length == 2){
- button_class = ' two_button';
- }
- var htm = '<div id="popup_box">';
- htm += '<div class="box_center"><span class="popup_title">' + new_options.title + '</span></div>';
- htm += '<div class="box_center popup_text">' + new_options.text + '</div>';
- htm += '<div class="box button_box">';
- if (buttons.length == 1){
- htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="action">' + buttons[0]['text'] + '</a></div>';
- } else if (buttons.length == 2){
- htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="cancel">' + buttons[0]['text'] + '</a></div>';
- htm += '<div class="box_center' + button_class + '"><a href="javascript:;" class="button center" id="action">' + buttons[1]['text'] + '</a></div>';
- }
- htm += '</div>';
- htm += '</div>';
- $.simple_popup(htm);
- if (typeof(new_options.onOpen) == 'function'){
- new_options.onOpen.call();
- }
- $.query('#cancel').on('tap', function(){
- $.hide_popup(new_options.onClose);
- buttons[0].handler.call();
- });
- $.query('#action').on('tap', function(){
- $.hide_popup(new_options.onClose);
- if (buttons.length == 1){
- buttons[0].handler.call();
- } else if (buttons.length == 2){
- buttons[1].handler.call();
- }
- });
- },
- //对带验证的ajax
- sign_ajax: function(options){
- var params = options.data;
- var sgf = options.success;
- options.success = function(res){
- alert(res.error_code);
- if ( res.error_code == '1001' || res.error_code == "1003") {
- native.getNewKey();
- return ;
- };
- sgf(res);
- }
- if (!!!params.time){
- params.time = new Date().getTime() / 1000;
- }
- sign_queue.push(options);
- if (sign_queue.length == 1){
- native.getSign(sign_queue[0].data, sign_callback);
- }
- },
- //touch绑定事件的封装
- new_touch: function(el, callback, parent_dom){
- var event = 'tap';
- if (!((window.DocumentTouch && document instanceof DocumentTouch) || 'ontouchstart' in window)){
- event = 'click';
- }
- if (parent_dom !== undefined){
- $(parent_dom).on(event, el, function(ev){
- callback.call(this, ev);
- });
- } else {
- $(el).on(event, function(ev){
- callback.call(this, ev);
- });
- }
- },
- //显示loading mask并锁定UI
- show_loading: function(message){
- if (typeof message == 'undefined'){
- message = '加载中';
- }
- $.ui.showMask(message);
- $.ui.blockUI();
- var that = this;
- setTimeout(function(){
- that.hide_loading();
- }, 10000);
- },
- //隐藏loading mas并解锁UI
- hide_loading: function(){
- $.ui.hideMask();
- $.ui.unblockUI();
- },
- //显示右侧边栏
- show_side_menu: function(){
- require(['iscroll'], function(IScroll){
- if (right_selector_scroll === null){
- right_selector_scroll = new IScroll('#right_selector_scroll');
- } else {
- right_selector_scroll.refresh();
- }
- });
- $.query('#content').addClass('prevent-pointer-events');
- $.ui.toggleRightSideMenu(true, function(){
- $.query('#afui').one('swipeRight', function(){
- $.ui.toggleRightSideMenu(false, null, 200);
- setTimeout(function(){
- $.query('#content').removeClass('prevent-pointer-events');
- }, 500);
- });
- }, 200);
- },
- //关闭右侧边栏
- hide_side_menu: function(){
- setTimeout(function(){
- $.query('#content').removeClass('prevent-pointer-events');
- }, 500);
- $.ui.toggleRightSideMenu(false, function(){
- $.query('#afui').unbind('swipeRight');
- }, 200);
- }
- });
- return afui;
- });
|