PageSourceSearch

https://www.lolc.com.kh/userfiles/modules/microweber/api/components.js

js lolc.com.kh collected 2026-10-01 16:34:44 UTC 9,851 bytes, 288 lines download raw bytes

1    mw.components = {
2    _rangeOnce: false,
3    'range': function(el){
4        mw.lib.require('jqueryui');
5        var options = this._options(el);
6        var defaults = {
7            range: 'min',
8            animate: "fast"
9        };
10        var ex = {}, render = el;
11        if(el.nodeName === 'INPUT'){
12            el._pauseChange = false;
13            el.type = 'text';
14            render = document.createElement('div');
15            $(el).removeClass('mw-range');
16            $(render).addClass('mw-range');
17            $(el).after(render);
18            ex = {
19                slide: function( event, ui ) {
20                    el._pauseChange = true;
21                   $(el).val(ui.value).trigger('change').trigger('input');
22                    setTimeout(function () {
23                        el._pauseChange = false;
24                    }, 78);
25                }
26            };
27
28        }
29        var settings = $.extend({}, defaults, options, ex);
30        if(el.min){
31            settings.min = parseFloat(el.min);
32        }
33        if(el.max){
34            settings.max = parseFloat(el.max);
35        }
36        if(el.value){
37            settings.value = parseFloat(el.value);
38        }
39        mw.$(render)
40            .slider(settings)
41            .on('mousedown touchstart', function(){
42                mw.$(this).addClass('active');
43            });
44        $(el).on('input', function(){
45            mw.$(render).slider( "value", this.value );
46        });
47        if(!mw.components._rangeOnce) {
48            mw.components._rangeOnce = true;
49            mw.$(document.body).on('mouseup touchend', function(){
50                mw.$('.mw-range.active').removeClass('active');
51            });
52        }
53    },
54    'color-picker': function(el){
55        var options = this._options(el);
56        var defaults = {
57            position: 'bottom-center'
58        };
59        var settings = $.extend({}, defaults, options);
60        var nav = document.createElement('div');
61        nav.className = 'mw-ui-btn-nav mw-color-picker-holder';
62        var view = document.createElement('div');
63        view.className = 'mw-ui-btn';
64        view.innerHTML = '<span class="mw-ui-btn-img"></span>';
65        nav.appendChild(view);
66        var inputEl;
67        if(el.nodeName === 'INPUT'){
68            inputEl = el;
69            mw.$(el).addClass('mw-ui-field').after(nav);
70            nav.appendChild(el);
71            mw.$('.mw-ui-btn-img', view).css("background-color", el.value);
72        }
73
74        inputEl._time = null;
75        var picker = mw.colorPicker({
76            element:inputEl,
77            position:settings.position,
78            onchange:function(color){
79                mw.$('.mw-ui-btn-img', view).css("background-color", color);
80                mw.$(inputEl).trigger('change');
81            }
82        });
83        mw.$(view).on("click", function(){
84            setTimeout(function(){
85                picker.toggle();
86            }, 10);
87        });
88    },
89    'file-uploader':function(el){
90        var options = this._options(el);
91        var defaults = {
92            element: el
93        };
94        var settings = $.extend({}, defaults, options);
95        var ch = mw.$(el).attr("onchange");
96
97        mw.fileWindow({
98            types:'media',
99            change:function(url){
100                try{
101                    eval(ch);
102                }
103                catch(err){}
104            }
105        });
106    },
107    'modules-tabs':function(el){
108        var options = this._options(el);
109        options.breakPoint = 100; //makes accordion if less then 100px
110        if(window.live_edit_sidebar) {
111            mw.$(el).addClass('mw-accordion-window-height')
112            options.breakPoint = 800; //makes accordion if less then 800px
113        }
114        var accordion = this.accordion(el);
115        var tb = new mw.tabAccordion(options, accordion);
116    },
117    'tab-accordion':function(el){
118       var options = this._options(el);
119       var accordion = this.accordion(el);
120       var tb = new mw.tabAccordion(options, accordion);
121    },
122    accordion:function(el){
123        if(!el || el._accordion) return;
124        if(!$(el).is(':visible')){
125            setTimeout(function(){
126                mw.components.accordion(el);
127            }, 777, el);
128            return;
129        }
130        el._accordion = true;
131        var options = this._options(el);
132        var settings = $.extend(options, {element:el})
133        var accordion = new mw.uiAccordion(settings);
134        if($(el).hasClass('mw-accordion-window-height')){
135            accordion._setHeight = function(){
136                var max =  mw.$(window).height() - (accordion.root.offset().top - mw.$(window).scrollTop());
137                accordion.root.css('height', max);
138                var content_max = max - (accordion.titles.length * accordion.titles.eq(0).outerHeight());
139                accordion.contents.css('height', content_max);
140            };
141            accordion._setHeight();
142            mw.$(window).on('load resize', function(){
143                accordion._setHeight();
144            });
145            if(window !== top){
146                mw.$(top).on('load resize', function(){
147                    accordion._setHeight();
148                });
149            }
150        }
151        if($(el).hasClass('mw-accordion-full-height')){
152            accordion._setHeight = function(){
153                var max = Math.min($(el).parent().height(), mw.$(window).height());
154                accordion.root.css('maxHeight', max);
155                var content_max = max - (accordion.titles.length * accordion.titles.eq(0).outerHeight());
156                accordion.contents.css('maxHeight', content_max);
157            };
158            accordion._setHeight();
159            mw.$(window).on('load resize', function(){
160                accordion._setHeight();
161            });
162            if(window !== top){
163                mw.$(top).on('load resize', function(){
164                    accordion._setHeight();
165                });
166            }
167        }
168        return accordion;
169    },
170    postSearch: function (el) {
171        var defaults = {keyword: el.value, limit: 4};
172        el._setValue = function (id) {
173            mw.tools.ajaxSearch(this._settings, function () {
174
175            });
176        };
177
178        el = mw.$(el);
179        var options = JSON.parse(el.attr("data-options") || '{}');
180        settings = $.extend({}, defaults, options);
181        el[0]._settings = settings;
182
183        el.wrap("<div class='mw-component-post-search'></div>");
184        el.after("<ul></ul>");
185
186        el.on("input focus blur", function (event) {
187
188            if (!el[0].is_searching) {
189                var val = el.val();
190                if (event.type == 'blur') {
191                    mw.$(this).next('ul').hide();
192                    return false;
193                }
194                if (event.type == 'focus') {
195                    if ($(this).next('ul').html()) {
196                        mw.$(this).next('ul').show()
197                    }
198                    return false;
199                }
200                el[0].is_searching = true;
201
202                this._settings.keyword = this.value;
203                mw.$('ul', el).empty("")
204                el.parent().addClass("loading");
205                mw.tools.ajaxSearch(this._settings, function () {
206                    var lis = [];
207                    var json = this;
208                    for (var item in json) {
209                        var obj = json[item];
210                        if (typeof obj === 'object') {
211                            var li = document.createElement("li");
212                            li._value = obj;
213                            li.innerHTML = obj.title;
214                            mw.$(li).on("mousedown touchstart", function () {
215                                el.val(this._value.title);
216
217                                el[0]._value = this._value;
218
219                                el.trigger('postSelected', [this._value]);
220                                mw.$(this.parentNode).hide()
221                            })
222
223                            lis.push(li);
224                        }
225                    }
226                    el.parent().removeClass("loading");
227                    var ul = el.parent().find("ul");
228                    ul.empty().append(lis).show();
229                    el[0].is_searching = false;
230                });
231            }
232        });
233        el.trigger("postSearchReady");
234    },
235    _options: function (el) {
236        return mw.tools.elementOptions(el);
237    },
238    _init: function () {
239        mw.$('.mw-field input[type="range"]').addClass('mw-range');
240        mw.$('[data-mwcomponent]').each(function () {
241            var component = mw.$(this).attr("data-mwcomponent");
242            if (mw.components[component]) {
243                mw.components[component](this);
244                mw.$(this).removeAttr('data-mwcomponent')
245            }
246        });
247        $.each(this, function(key){
248            if(key.indexOf('_') === -1){
249                mw.$('.mw-'+key+', mw-'+key).not(".mw-component-ready").each(function () {
250                    mw.$(this).addClass('mw-component-ready');
251                    mw.components[key](this);
252                });
253            }
254        });
255    }
256};
257
258$(document).ready(function () {
259    mw.components._init();
260});
261
262$(window).on('load', function () {
263    mw.components._init();
264});
265
266    mw.on('ComponentsLaunch', function () {
267        mw.components._init();
268    });
269
270    mw.on('mwDialogShow', function () {
271        setTimeout(function () {
272            mw.components._init();
273        }, 110);
274    });
275
276$(window).on('ajaxStop', function () {
277    setTimeout(function () {
278        mw.components._init();
279    }, 100);
280});
281
282mw.registerComponent = function(name, func){
283    if(mw.components[name]){
284        console.warn('Component ' + name + ' already exists.');
285        return;
286    }
287    mw.components[name] = func;
288};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.