JavaScript - ayuda con código

 
Vista:

ayuda con código

Publicado por thor (1 intervención) el 06/02/2019 13:28:16
alguien podría decirme que clase de estructura representa este código js,quiero decir, un plugin un objeto ,y como aprender a desarrollar de esta forma o un tutorial que me explique

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var LiveSearchJs = function () {
 
    var init = function(options) {
        var live_search = {
            selector: "#search input[name='search']",
            text_no_matches: options.text_empty,
            height: '50px'
        }
        // console.log(options);
 
        // Initializing drop down list
        var html = '<div class="live-search"><ul></ul><div class="result-text"></div></div>';
        $(live_search.selector).after(html);
 
        $(live_search.selector).autocomplete({
            'source': function(request, response) {
                var filter_name = $(live_search.selector).val();
                var cat_id = 0;
                var live_search_min_length = options.module_live_search_min_length;
                if (filter_name.length < live_search_min_length) {
                    $('.live-search').css('display','none');
                }
                else{
                    var live_search_href = 'index.php?route=extension/module/live_search&filter_name=';
                    var all_search_href = 'index.php?route=product/search&search=';
                    if(cat_id > 0){
                        live_search_href = live_search_href + encodeURIComponent(filter_name) + '&cat_id=' + Math.abs(cat_id);
                        all_search_href = all_search_href + encodeURIComponent(filter_name) + '&category_id=' + Math.abs(cat_id);
                    }
                    else{
                        live_search_href = live_search_href + encodeURIComponent(filter_name);
                        all_search_href = all_search_href + encodeURIComponent(filter_name);
                    }
 
                    var html  = '<li style="text-align: center;height:10px;">';
                        html += '<img class="loading" src="catalog/view/javascript/live_search/loading.gif" />';
                        html += '</li>';
                    $('.live-search ul').html(html);
                    $('.live-search').css('display','block');
 
                    $.ajax({
                        url: live_search_href,
                        dataType: 'json',
                        success: function(result) {
                            var products = result.products;
                            $('.live-search ul li').remove();
                            $('.result-text').html('');
                            if (!$.isEmptyObject(products)) {
                                var show_image       = options.module_live_search_show_image;
                                var show_price       = options.module_live_search_show_price;
                                var show_description = options.module_live_search_show_description;
                                var show_add_button  = options.module_live_search_show_add_button;
 
                                $('.result-text').html('<a href="'+all_search_href+'" class="view-all-results">'+options.text_view_all_results+' ('+result.total+')</a>');
                                $.each(products, function(index,product) {
                                    var html = '<li>';
                                        // show_add_button
                                    if(show_add_button){
                                        html += '<div class="product-add-cart">';
                                        html += '<a href="javascript:;" onclick="cart.add('+product.product_id+', '+product.minimum+');" class="btn btn-primary">';
                                        html += '<i class="fa fa-shopping-cart"></i>';
                                        html += '</a>';
                                        html += '</div>';
                                    }
                                        html += '<div>';
                                        html += '<a href="' + product.url + '" title="' + product.name + '">';
                                    // show image
                                    if(product.image && show_image){
                                        html += '<div class="product-image"><img alt="' + product.name + '" src="' + product.image + '"></div>';
                                    }
                                    // show name & extra_info
                                    html += '<div class="product-name">' + product.name ;
                                    if(show_description){
                                        html += '<p>' + product.extra_info + '</p>';
                                    }
                                    html += '</div>';
                                    // show price & special price
                                    if(show_price){
                                        if (product.special) {
                                            html += '<div class="product-price"><span class="special">' + product.price + '</span><span class="price">' + product.special + '</span></div>';
                                        } else {
                                            html += '<div class="product-price"><span class="price">' + product.price + '</span></div>';
                                        }
                                    }
                                    html += '</a>';
                                    html += '</div>';
 
                                    html += '</li>';
                                    $('.live-search ul').append(html);
                                });
                            } else {
                                var html = '';
                                html += '<li style="text-align: center;height:10px;">';
                                html += live_search.text_no_matches;
                                html += '</li>';
 
                                $('.live-search ul').html(html);
                            }
                            // $('.live-search ul li').css('height',live_search.height);
                            $('.live-search').css('display','block');
 
                            return false;
                        }
                    });
 
                }
            },
            'select': function(product) {
                $(live_search.selector).val(product.name);
            }
        });
 
        $(document).bind( "mouseup touchend", function(e){
            var container = $('.live-search');
            if (!container.is(e.target) && container.has(e.target).length === 0) {
                container.hide();
            }
        });
    }
 
    return {
        //main function to initiate the module
        init: function(options) {
            init(options);
        }
    };
 
}();



gracias un cordial saludo
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Xavi
Val: 1.807
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

ayuda con código

Publicado por Xavi (68 intervenciones) el 06/02/2019 17:17:15
Viendo el código me parece que utilzar jquery...
Un buen libro de javascript, NO de jquery es "Secrets of the JavaScript Ninja"...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar