HomeHelpTrac

Changeset 15946


Ignore:
Timestamp:
02/05/12 23:00:59 (4 months ago)
Author:
Alexander Trofimov
Message:

AJAX popup corrections

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/inc/js/jquery.dolPopup.js

    r15942 r15946  
    77(function($) { 
    88 
     9    $.fn.dolPopupDefaultOptions = { 
     10        closeOnOuterClick: true, 
     11        closeElement: '.bx-popup-element-close', // link to element which will close popup 
     12        position: 'centered', // | 'absolute' | 'fixed' | event | element, 
     13        fog: {color: '#fff', opacity: .7}, // {color, opacity}, 
     14        pointer: false, // {el:(string_id|jquery_object), align: (left|right|center)}, 
     15        left: 0, // only for fixed or absolute 
     16        top: 0, // only for fixed 
     17        onBeforeShow: function () {}, 
     18        onShow: function () {}, 
     19        onBeforeHide: function () {}, 
     20        onHide: function () {}, 
     21        speed: 150 
     22    };  
     23 
     24    $.fn.dolPopupDefaultPointerOptions = { 
     25        align: 'right', 
     26        offset: '0 0', 
     27        offset_pointer: '0 0' 
     28    };  
     29 
    930    $.fn.dolPopup = function(options) { 
    1031        var options = options || {}; 
    11         var defaults = { 
    12             closeOnOuterClick: true, 
    13             closeElement: '.bx-popup-element-close', // link to element which will close popup 
    14             position: 'centered', // | 'absolute' | 'fixed' | event | element, 
    15             fog: {color: '#fff', opacity: .7}, // {color, opacity}, 
    16             pointer: false, // {el:(string_id|jquery_object), align: (left|right|center)}, 
    17             left: 0, // only for fixed or absolute 
    18             top: 0, // only for fixed 
    19             onBeforeShow: function () {}, 
    20             onShow: function () {}, 
    21             onBeforeHide: function () {}, 
    22             onHide: function () {}, 
    23             speed: 150 
    24         }; 
    25  
    26         var o = $.extend({}, defaults, options); 
    27  
    28         var defaults_pointer = { 
    29             align: 'right', 
    30             offset: '0 0', 
    31             offset_pointer: '0 0', 
    32         } 
     32        var o = $.extend({}, $.fn.dolPopupDefaultOptions, options);         
    3333 
    3434        if (false != o.pointer) { 
    3535            o.fog = false; 
    36             o.pointer = $.extend({}, defaults_pointer, $(document).data('bx-popup-options') ? $(document).data('bx-popup-options') : {}, o.pointer); 
     36            o.pointer = $.extend({}, $.fn.dolPopupDefaultPointerOptions, $(document).data('bx-popup-options') ? $(document).data('bx-popup-options') : {}, o.pointer); 
    3737        } 
    3838 
     
    163163 
    164164    $.fn.dolPopupAjax = function(options) {  
    165  
     165         
    166166        if ('undefined' == typeof(options) || 'object' != typeof(options) || 'undefined' == typeof(options.url)) 
    167167            return; 
     
    169169        var bx_menu_on = function (e, b) { 
    170170            var li = $(e).parents('li:first');    
     171            if (!li.length) 
     172                return; 
    171173            if (b) { 
    172174                var ul = $(e).parents('ul:first');    
     
    180182        var bx_menu_is_on = function (e) {     
    181183            var li = $(e).parents('li:first');    
     184            if (!li.length) 
     185                return false; 
    182186            return li.hasClass('bx-menu-tab-active'); 
    183187        } 
     
    185189        return this.each(function() { 
    186190            var e = $(this); 
    187  
    188             var id = ('undefined' == typeof(options.id) ? parseInt(2147483647 * Math.random()) : options.id); 
    189  
    190             if ($("#bx-popup-ajax-" + id + ":visible").length) { 
     191            var id; 
     192 
     193            // get id 
     194            if ('undefined' == typeof(e.attr('bx-popup-id'))) { 
     195                id = ('undefined' == typeof(options.id) ? parseInt(2147483647 * Math.random()) : options.id); 
     196                e.attr('bx-popup-id', id); 
     197            } else { 
     198                id = e.attr('bx-popup-id'); 
     199            } 
     200 
     201            if ($("#bx-popup-ajax-wrapper-" + id + ":visible").length) { // if popup exists and is shown - hide it 
    191202                 
    192                 $("#bx-popup-ajax-" + id).dolPopupHide(); 
    193  
    194             } else if ($("#bx-popup-ajax-" + id).length) { 
    195  
    196                 bx_menu_on(e, true); 
    197                 $("#bx-popup-ajax-" + id).dolPopup({ 
    198                     pointer: {el:$(e)}, 
     203                $("#bx-popup-ajax-wrapper-" + id).dolPopupHide(); 
     204 
     205            } else if ($("#bx-popup-ajax-wrapper-" + id).length) { // if popup exists but not shown - unhide it 
     206 
     207                if (!$.isWindow(e[0])) 
     208                    bx_menu_on(e, true); 
     209 
     210                $("#bx-popup-ajax-wrapper-" + id).dolPopup({ 
     211                    pointer: $.isWindow(e[0]) ? false : {el:$(e), align:'center'}, 
    199212                    onHide: function () { 
    200                         bx_menu_on(e, false); 
     213                        if (!$.isWindow(e[0])) 
     214                            bx_menu_on(e, false); 
    201215                    } 
    202216                }); 
    203217 
    204             } else {         
    205  
    206                 bx_menu_on(e, true); 
    207                 bx_loading_content($('#bx-popup-loading .bx-popup-ajax-content'), true, true); 
    208                 $('#bx-popup-loading').dolPopup({ 
    209                     pointer: {el:e}, 
    210                     closeOnOuterClick: false 
    211                 }); 
    212                 $('<div id="bx-popup-ajax-' + id + '" style="display:none;"><div>').appendTo($('body')).load(sUrlRoot + options.url, 
    213                     function() { 
    214                         if (!bx_menu_is_on(e)) 
    215                             return; 
    216                         $('#bx-popup-loading').dolPopupHide({ 
    217                             onHide: function () { 
    218                                 $('#bx-popup-ajax-' + id).dolPopup({ 
    219                                     pointer: {el:e}, 
    220                                     onHide: function () { 
    221                                         bx_menu_on(e, false); 
    222                                     } 
    223                                 }); 
    224                             } 
    225                         }); 
     218            } else { // if popup doesn't exists - create new one from provided url 
     219 
     220                if (!$.isWindow(e[0])) 
     221                    bx_menu_on(e, true); 
     222 
     223                $('body').append('<div id="bx-popup-ajax-wrapper-' + id + '" style="display:none;">' + $('#bx-popup-loading').html() + '</div>'); 
     224                bx_loading_content($('#bx-popup-ajax-wrapper-' + id + ' .bx-popup-ajax-content'), true, true); 
     225                console.log('iswin:' + $.isWindow(e[0]) + " / "); 
     226                console.log(e); 
     227                $('#bx-popup-ajax-wrapper-' + id).dolPopup({ 
     228                    pointer: $.isWindow(e[0]) ? false : {el:e, align:'center'}, 
     229                    onHide: function () { 
     230                        if (!$.isWindow(e[0])) 
     231                            bx_menu_on(e, false); 
    226232                    } 
    227                 );     
     233                }); 
     234 
     235                $('#bx-popup-ajax-wrapper-' + id + ' .bx-popup-ajax-content').load(sUrlRoot + options.url, function () {                     
     236                    $('#bx-popup-ajax-wrapper-' + id)._dolPopupSetPosition({ 
     237                        pointer: $.isWindow(e[0]) ? false : {el:e, align:'center'} 
     238                    }); 
     239                }); 
    228240 
    229241            } 
     
    232244    }; 
    233245 
    234     $.fn._dolPopupSetPosition = function(o) { 
     246    $.fn._dolPopupSetPosition = function(options) { 
     247 
     248        var o = $.extend({}, $.fn.dolPopupDefaultOptions, options); 
     249 
     250        if (undefined != o.pointer && false != o.pointer) 
     251            o.pointer = $.extend({}, $.fn.dolPopupDefaultPointerOptions, $(document).data('bx-popup-options') ? $(document).data('bx-popup-options') : {}, o.pointer); 
     252 
    235253        return this.each(function() { 
    236254            var $el = $(this); 
  • trunk/menu.php

    r15942 r15946  
    2323 
    2424header('Content-type: text/html; charset=utf-8'); 
    25 echo $oMenu->getCodeForPopup (); 
     25echo $oMenu->getCode (); 
    2626 
    2727/** @} */ 
  • trunk/samples/popup.php

    r15931 r15946  
    2222 
    2323if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) { 
    24     echo BxTemplFunctions::getInstance()->transBox('<div class="bx-def-padding bx-def-color-bg-block">AJAX content here: ' .  date(DATE_RFC822) . '</div>'); 
     24    sleep(2); // to see AJAX loader 
     25    echo date(DATE_RFC822); 
    2526    exit; 
    2627} 
     
    4546 
    4647    // transBox AJAX 
    47     echo ' 
    48     <script> 
    49         function bx_sample_ajax_popup () { 
    50             $("#bx-sample-popup-ajax").remove(); 
    51             $(\'<div id="bx-sample-popup-ajax" style="display: none;"></div>\').prependTo("body").load( 
    52                 "' . BX_DOL_URL_ROOT . 'samples/popup.php", 
    53                 function() {  
    54                     $(this).dolPopup();  
    55                 } 
    56             );     
    57         } 
    58     </script>'; 
    59     echo '<button class="bx-btn bx-def-margin-left" onclick="bx_sample_ajax_popup ()">transBox AJAX</button>'; 
     48    echo '<button class="bx-btn bx-def-margin-left" onclick="$(window).dolPopupAjax({url: \'samples/popup.php\'})">transBox AJAX</button>'; 
    6049 
    6150    // popupBox 
     
    8271    echo '<button class="bx-btn bx-def-margin-left" onclick="$(\'#bx-sample-popup-box-with-pointer\').dolPopup({pointer:{el:$(this)}})">popupBox with pointer</button>'; 
    8372 
     73    // popupBox with pointer AJAX 
     74    echo BxTemplFunctions::getInstance()->popupBox('bx-sample-popup-box-with-pointer', 'popupBox', 'popupBox with pointer AJAX', array(), true); 
     75    echo '<button class="bx-btn bx-def-margin-left" onclick="$(this).dolPopupAjax({url: \'samples/popup.php\'})">popupBox with pointer AJAX</button>'; 
     76 
    8477    echo '<div class="bx-clear"></div>'; 
    8578 
  • trunk/templates/base/_footer.html

    r15211 r15946  
     1        __popup_loading__ 
    12       <bx_injection:injection_footer /> 
    23    </body> 
  • trunk/templates/base/_header.html

    r15942 r15946  
    2727__flush_header__ 
    2828<body class="bx-def-font bx-def-color-bg-page" <bx_injection:injection_body /> > 
    29     <bx_injection:injection_header /> 
    30     __popup_loading__ 
     29    <bx_injection:injection_header />     
  • trunk/templates/base/css/menu.css

    r15942 r15946  
    101101.bx-menu-main li:active, 
    102102.bx-menu-main li.bx-menu-tab-active { 
     103    background-color:#f0f0f0; 
     104 
    103105    -webkit-box-shadow: inset 0px 0px 8px rgba(128, 128, 128, 0.35); 
    104106    -moz-box-shadow: inset 0px 0px 8px rgba(128, 128, 128, 0.35); 
  • trunk/templates/base/scripts/BxBaseMenu.php

    r15942 r15946  
    4545 
    4646    /**  
    47      * Get menu code for displaying menu in popup. 
    48      * @return string 
    49      */ 
    50     public function getCodeForPopup () { 
    51         bx_import('BxTemplFunctions'); 
    52         return BxTemplFunctions::getInstance()->transBox('<div class="bx-def-padding bx-def-color-bg-block">' . $this->getCode () . '</div>'); 
    53     } 
    54  
    55     /**  
    5647     * Get menu items array, which are ready to pass to template. 
    5748     * @return array 
Note: See TracChangeset for help on using the changeset viewer.