PageSourceSearch

https://www.ecranlarge.be/components/cmson.js

js ecranlarge.be collected 2026-10-06 07:42:47 UTC 13,613 bytes, 556 lines download raw bytes

1function onAjaxError(XMLHttpRequest, textStatus, exception)
2{
3    var errortext = XMLHttpRequest.responseText;
4    if (typeof exception != "undefined") {
5        errortext += exception.message ? exception.message : exception;
6        errortext += "\n" + _getStackTrace(exception);
7    }
8    if (errortext.length > 0) alert("Ajax failure\n" + errortext);
9}
10function ajax( url, parameter, onSuccess, dataType, method)  {
11    $.ajax({
12        url: url,
13        type: method || 'POST',
14        dataType: dataType || "html",
15        data: parameter ,
16        success: onSuccess,
17        error: onAjaxError,
18        async: true
19    });
20}
21function message ( type, message) {
22
23    $('#msg').html("<div class=\"notification  "+type+"\">"+message+"</div>").fadeIn().delay(3000).fadeOut('slow');
24}
25
26/* Clear all elements of a from */
27function clear_form_elements(form) {
28
29    $(form).find(':input').each(function() {
30        switch(this.type) {
31            default:
32            case 'password':
33            case 'select-multiple':
34            case 'select-one':
35            case 'text':
36            case 'textarea':
37                $(this).val('');
38                break;
39            case 'checkbox':
40            case 'radio':
41                this.checked = false;
42        }
43    });
44
45}
46
47
48/**
49 *  CmsOn Object.
50 *
51 *   jQuery required !!!
52 **/
53
54function CmsOn(lang)  {
55
56    this.lang = lang;
57    this.callBackError;
58    this.callBackSuccess;
59    this.translations;
60
61
62}
63
64
65/****************************************** AJAX Methods ********************************/
66CmsOn.prototype.ajax = function ( url, parameter, onSuccess, dataType, method)  {
67
68    var self = this;
69    $.ajax({
70        url: url,
71        type: method || 'POST',
72        dataType: dataType || "html",
73        data: parameter ,
74        success: onSuccess,
75        error: self.ajaxError,
76        async: true
77    });
78}
79
80CmsOn.prototype.syncajax = function( url, parameter, onSuccess, dataType, method)  {
81    var self = this;
82    $.ajax({
83        url: url,
84        type: method || 'POST',
85        dataType: dataType || "html",
86        data: parameter ,
87        success: onSuccess,
88        error: self.ajaxError,
89        async: false
90    });
91}
92
93CmsOn.prototype.ajaxError = function(XMLHttpRequest, textStatus, exception)
94{
95
96    var errortext = XMLHttpRequest.responseText;
97    if (typeof exception != "undefined") {
98        errortext += exception.message ? exception.message : exception;
99        errortext += "\n" + _getStackTrace(exception);
100    }
101    if (errortext.length > 0) {
102        alert("Ajax failure\n" + errortext);
103
104    }
105
106}
107/****************************************** END AJAX ********************************/
108
109
110/****************** LOGIN ***************/
111CmsOn.prototype.login = function(login, password, success_callback)  {
112
113    var self = this;
114    this.syncajax('callback.php', {
115            action: "login",
116            user_login: login,
117            user_password: password
118        },
119        function(response) {
120            var res = $.parseJSON(response);
121            if (res.type == "success")  {
122                if ( success_callback )
123                    success_callback(res);
124            }
125            else {
126                self.error("login : "+ res.message);
127            }
128        });
129}
130
131
132
133/***************************************** GET CONTENT METHODS **********************/
134
135/*
136 * Load a bloc and render it's content in target
137 **/
138CmsOn.prototype.loadBloc = function(id, target, callback)  {
139
140    var self = this;
141    this.syncajax('callback.php', {
142            action: "get",
143            type: "bloc",
144            id: id,
145            lang: lang
146        },
147        function(response) {
148
149            var res = $.parseJSON(response);
150            if (res.type == "success")  {
151                $("#"+target).html(res.data[0]['content']);
152                if ( callback && typeof callback == "function" )
153                    callback(res.data[0]);
154            }
155            else
156                self.error("loadBloc : "+ res.message);
157        });
158}
159
160
161CmsOn.prototype.loadMenu = function(id, callback) {
162
163
164    callback = callback || function() {};
165
166
167
168
169    this.syncajax('callback.php', {
170            action: "get",
171            type: "menu",
172            id: id,
173            lang: lang
174        },
175        function(response) {
176
177            var res = $.parseJSON(response);
178            if (res.type == "success") {
179                callback(res.data);
180            }
181
182        });
183
184
185
186}
187
188/*
189 * Load a gallery. The rendering is delegated to "renderCallBack"
190 **/
191CmsOn.prototype.loadGallery = function (id, renderCallBack, random) {
192
193    var self = this;
194    var param = {
195        action: "get",
196        type: "gallery",
197        id: id
198    };
199    if ( typeof random != "undefined" && random )
200        param.random = 1;
201
202    this.ajax('callback.php',
203        param,
204
205        function(response) {
206
207            var res = $.parseJSON(response);
208            if (res.type == "success") {
209                if ( renderCallBack && typeof renderCallBack == "function" )
210                    renderCallBack(res.data,res.title,res.description,id);
211            }
212            else
213                self.error("loadGallery : " + res.message);
214        });
215}
216
217/*
218 * Load a page and render it's content in target
219 **/
220CmsOn.prototype.loadPage = function(id, target)  {
221
222    var self = this;
223    this.syncajax('callback.php', {
224            action: "get",
225            type: "page",
226            id: id,
227            lang: lang
228        },
229        function(response) {
230            var res = $.parseJSON(response);
231            if (res.type == "success")
232                $("#"+target).html(res.data.content);
233            else
234                self.error("loadPage : "+ res.message);
235        });
236}
237
238
239/**
240 * Load news list
241 */
242CmsOn.prototype.loadNews = function (target, tag, nb) {
243
244    $("#"+target).empty();
245    this.ajax('callback.php', {
246            action: "get",
247            type: "newslist",
248            lang: lang,
249            tag: tag
250        },
251
252        function(response) {
253
254            var res = $.parseJSON(response);
255            if (res.type == "success") {
256                var content= "";
257                var newslist = "";
258                for (var i = 0; i < res.data.length; i++) {
259
260                    if ( i == nb ) {
261                        break;
262                    }
263                    content += " <div class=\"news_block\">";
264
265                    if( res.data[i]['image_file'] != "" )
266                        content += "<div class=\"news_img\"><img src=\""+res.data[i]['image_file']+"\"  />";
267
268                    content +="<div class=\"newsleft\"><div class=\"news_content\">"+res.data[i]['content']+"</div>";
269                    content += "</div><div class=\"clear\"></div>";
270
271                }
272                $("#"+target).html(content);
273            } else {
274                alert("loadNews error : " + res.message);
275            }
276        });
277
278
279}
280
281
282
283
284/** Define the same height for each element of group */
285CmsOn.prototype.equalHeight = function(group)  {
286    tallest = 0;
287    group.each(function() {
288        thisHeight = $(this).height();
289        if(thisHeight > tallest) {
290            tallest = thisHeight;
291        }
292    });
293    group.height(tallest);
294}
295
296/** Place an element to the bottom : position absolute or relative*/
297CmsOn.prototype.glueToBottom = function(target) {
298    var targetHeight = $("#"+target).outerHeight();
299    var windowHeight= $(window).height();
300    // occuped height is body - footer
301    var bodyHeight = $("body").outerHeight();
302    var occupedHeight = bodyHeight - targetHeight;
303
304    //alert("targetHeight= "+ targetHeight+ " windowHeight = " + windowHeight+",bodyHeight = "+bodyHeight+" occupedHeight = " + occupedHeight);
305    if ( bodyHeight >= windowHeight ) {
306        setTimeout(function() {$("#"+target).css('position', 'relative'); },0);
307    }
308    else {
309        setTimeout(function() {
310            $("#"+target).css('position', 'absolute');
311            $("#"+target).css('bottom', '0');
312        },0);
313    }
314}
315
316/** Scroll to an element */
317CmsOn.prototype.scrollTo = function(target) {
318
319    $('html,body').animate({scrollTop: $("#"+target).offset().top}, 1000);
320    /*event.preventDefault();*/
321    return false;
322
323}
324
325
326
327/** Manage error message */
328CmsOn.prototype.error = function(str) {
329
330    if(window.console && console.log )
331        console.log("CmsOn : error : " +  str ) ;
332    else
333        alert("CmsOn : error : " + str ) ;
334
335    if ( this.callBackError ) // call error callback if it defined
336        this.callBackError(str);
337}
338
339/** Simple log function */
340CmsOn.prototype.log = function(str ) {
341
342    if(windthis.ow.console && console.log )
343        console.log(typeof str == "object" ? str : "CmsOn : " +  str ) ;
344    else
345        alert("CmsOn : " + str ) ;
346
347
348}
349
350
351
352
353
354/***************************************** FORM MANAGMENT METHODS **********************/
355/** Send a form */
356CmsOn.prototype.sendMessage = function (form, callback) {
357    var self=this;
358
359    if (!this.checkForm(form))
360        return false;
361
362    // prepare data
363    var param = { action: "sendmessage" };
364    $(form).find(':input').each(function() {
365
366        if ( $(this).is(':checkbox') ) {
367
368            param[$(this).attr('id')] = $(this).is(':checked') ? "oui" : "non";
369        }
370        else
371            param[$(this).attr('id')] = $(this).val();
372
373    });
374
375    this.ajax('callback.php', param,
376        function(response) {
377            if (response != "ok") {
378
379                message("error", this.translations ? this.translations.contact_error : "Une erreur est survenue durant l'envoi du message.");
380
381            }
382            else {
383                message("success", this.translations ? this.translations.contact_ok : "Votre message a été envoyé. Merci");
384                clear_form_elements(form);
385                if ( callback && typeof callback == "function" )
386                    callback();
387
388            }
389        });
390}
391
392
393/** Check form methods */
394CmsOn.prototype.checkForm = function (form) {
395
396    var validForm = true;
397    var self = this;
398    var msg = this.translations ? this.translations.contact_formerror : "Le formulaire n'est pas correctement compl&eacute;té ! ";
399
400    $(form).find(':input').each(function() {
401        if ( $(this).attr('required') )  {
402            if ( $(this).is(':checkbox') ) {
403
404                if ( $(this).is(':checked') ) {   $(this.removeClass('errorform')); }
405                else {  $(this).addClass('errorform');  validForm = false; }
406            }
407            else
408                validForm =  validForm && self.checkNotEmpty(this);
409        }
410    });
411    if ( validForm == false )
412        message("error",msg);
413    return validForm;
414}
415
416CmsOn.prototype.checkNotEmpty = function(field) {
417
418    if ( $(field).val() == "" ) 	{
419        $(field).addClass('errorform');
420        $(field).focus();
421        return false;
422    }
423    else {
424        $(field).removeClass('errorform');
425        return true;
426    }
427}
428
429CmsOn.prototype.checkNotEqualTo = function (field, value, chk) {
430    if ( $(field).val() == value ) 	{
431        chk.css('display','');
432        $(field).addClass('errorform');
433        return false;
434    }
435    else {
436        chk.css('display','none');
437        $(field).removeClass('errorform');
438        return true;
439    }
440}
441
442
443/******* Shops method *****/
444
445/* charge les produit d'une catégorie donnée. loadchildrenlevel indique que les produits se trouvant dans les catégories filles doivent aussi être chargés */
446CmsOn.prototype.shopLoadProduct = function ( id_cat, renderCallBack, loadchildrenlevel, sort ) {
447
448
449    var self = this;
450
451
452    this.ajax('shop.php', {
453            action: "productlist",
454            id_cat: id_cat,
455            lang: lang,
456            loadchildrenlevel: loadchildrenlevel ? loadchildrenlevel : null,
457            sort: sort ? sort : false
458        },
459
460        function (response) {
461
462            var res = $.parseJSON(response);
463            // console.table(res);
464            if (res.type == "success")
465                renderCallBack(res.data);
466            else
467                self.error("shopLoadProduct : " + res.message);
468        });
469};
470
471
472CmsOn.prototype.shopLoadCategories = function (  renderCallBack, id_parent) {
473
474      var self = this;
475
476    this.ajax('shop.php', {
477            action: "categorylist",
478            lang : lang,
479            level: id_parent
480        },
481
482        function(response) {
483
484            var res = $.parseJSON(response);
485            if (res.type == "success")
486                renderCallBack(res.data);
487            else
488                self.error("shopLoadCategories : " + res.message);
489        });
490};
491
492
493CmsOn.prototype.shopGetProduct = function ( id, renderCallBack ) {
494
495
496    var self = this;
497
498
499    this.ajax('shop.php', {
500            action: "getjsonproduct",
501            lang : lang,
502            id: id
503
504        },
505
506        function(response) {
507
508            var res = $.parseJSON(response);
509            renderCallBack(res);
510
511
512        });
513};
514
515CmsOn.prototype.shopGetCategory = function ( id, renderCallBack ) {
516    var self = this;
517    this.ajax('shop.php', {
518            action: "getjsoncategory",
519            lang : lang,
520            id: id
521
522        },
523
524        function(response) {
525            var res = $.parseJSON(response);
526            renderCallBack(res);
527
528        });
529
530};
531
532
533
534
535
536
537CmsOn.prototype.shopGetBreadcrumb= function ( id, renderCallBack ) {
538    var self = this;
539    this.ajax('shop.php', {
540            action: "breadcrumb",
541            lang : lang,
542            level: id
543        },
544
545        function(response) {
546            var res = $.parseJSON(response);
547            renderCallBack(res.data);
548
549        });
550
551};
552
553
554
555
556

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.