source: sipes/0.3-modules/views_semantic/js/modal.js @ 60aa084

stable
Last change on this file since 60aa084 was 89c313a, checked in by Sipes Apn <root@…>, 7 años ago

se agrego el modulo views_semantic

  • Propiedad mode establecida a 100755
File size: 3.2 KB
Línea 
1//var modal = (function(){
2function modal(){
3    var 
4    method = {},
5    $overlay,
6    $modal,
7    $content,
8    $close;
9
10    var at_close;
11    // Center the modal in the viewport
12    method.center = function () {
13        var top, left;
14        var aux ;
15        if ( $modal.outerWidth() < 400 ){
16            aux = 800;
17        }
18        else{
19            aux = $modal.outerWidth() ;
20        }
21/*
22        var aux1;
23//alert($modal.outerHeight());
24        if ( $modal.outerHeight() < 200 ){
25            aux1 = 1900;
26        }
27        else{
28            aux1 = $modal.outerHeight() ;
29        }*/
30        top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2;
31        //top = Math.max($(window).height() - aux1, 0) / 2;
32        //left = Math.max($(window).width() - $modal.outerWidth(), 0) / 2;
33        left = Math.max($(window).width() - aux, 0) / 2;
34
35       
36        $modal.css({
37            top:top + $(window).scrollTop(), 
38            left:left + $(window).scrollLeft()
39     
40        });
41    };
42
43    // Open the modal
44    method.open = function (settings) {
45        $modal.css({
46            width: settings.width || 'auto', 
47            height: settings.height || 'auto',
48        })
49
50        if (settings.load_url) {
51            //$content.empty().load(settings.load_url)
52            $.get(settings.load_url).done(function(html){
53                $content.empty().append(html);       
54                if (settings.at_open) {
55                    settings.at_open();
56                }
57            });
58        } else if (settings.content) {
59            $content.empty().append(settings.content);
60        } else {
61            $content.empty().append("<h1>ERROR</h1>");
62        }
63        if ( settings.top || settings.left ) {
64            $modal.css({
65                top: settings.top ,
66                left: settings.left
67            })
68        } else { 
69            method.center() ;
70            $(window).bind('resize.modal', method.center);
71        }
72method.center();
73        $modal.show();
74        $overlay.show();
75        at_close = settings.at_close;
76    };
77
78    // Close the modal
79    method.close = function () {
80        /*
81        $modal.hide();
82        $overlay.hide();
83        $content.empty();
84        $(window).unbind('resize.modal');
85        */
86        $modal.remove();
87        $overlay.remove();
88        $content.remove();
89        $(window).unbind('resize.modal');
90    };
91   
92    method.init = function (init) {
93        $overlay = $('<div class="overlay_modal" id="overlay_modal_'+init.id+'"></div>');
94        $modal = $('<div class="modal" id="modal_'+init.id+'"></div>');
95        $content = $('<div class="content_modal" id="content_modal_'+init.id+'"></div>');
96        $close = $('<a class="close_modal" id="close_modal_'+init.id+'" href="#">close</a>');   
97        $modal.hide();
98        $overlay.hide();
99        $modal.append($content, $close);
100
101
102        $close.click(function(e){
103            if (at_close){
104                at_close();
105            } 
106            method.close();
107            e.preventDefault();
108        });
109        method.open(init);
110        $('body').append($overlay, $modal);
111    };
112    method.get_element = function (id) {       
113        return $(id);
114    }
115
116    return method;
117}
118
119
120
121
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.