PageSourceSearch

https://www.madnesslive.es/modules/facebookpsconnect/views/js/module.js?v=19

js madnesslive.es collected 2026-09-24 20:36:35 UTC 20,972 bytes, 693 lines download raw bytes

1/**
2 * Social Login
3 *
4 * @author    businesstech.fr <[email protected]> - https://www.businesstech.fr/
5 * @copyright Business Tech  - https://www.businesstech.fr/
6 * @license   see file: LICENSE.txt
7 *
8 *           ____    _______
9 *          |  _ \  |__   __|
10 *          | |_) |    | |
11 *          |  _ <     | |
12 *          | |_) |    | |
13 *          |____/     |_|
14 */
15
16// declare main object of module
17var FpcModule = function (sName) {
18	// set name
19	this.name = sName;
20
21	// set name
22	this.oldVersion = false;
23
24	// set translated js msgs
25	this.msgs = {};
26
27	// stock error array
28	this.aError = [];
29
30	// set url of admin img
31	this.sImgUrl = "";
32
33	// set url of module's web service
34	this.sWebService = "";
35
36	// set url of module's web service
37	this.sShortCodeUrl = "";
38
39	// set response
40	this.response = null;
41
42	// set this in obj context
43	var oThis = this;
44
45	/*
46	 * show() method show effect and assign HTML in
47	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
48	 * @param string sId : container to show in
49	 * @param string sHtml : HTML to display
50	 * @return -
51	 */
52	this.show = function (sId, sHtml) {
53		$("#" + sId)
54			.html(sHtml)
55			.css("style", "none");
56		$("#" + sId).show("fast");
57	};
58
59	/*
60	 * hide() method hide effect and delete html
61	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
62	 * @param string sId : container to hide in
63	 * @return -
64	 */
65	this.hide = function (sId) {
66		$("#" + sId).hide("fast", function () {
67			$("#" + sId).html("");
68		});
69	};
70
71	/*
72	 * form() method check all fields of current form and execute : XHR or submit => used for update all admin config
73	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
74	 * @see ajax
75	 * @param string sForm : form
76	 * @param string sURI : query params used for XHR
77	 * @param string sRequestParam : param action and type in order to send with post mode
78	 * @param string sToDisplay :
79	 * @param string sToHide : force to hide specific ID
80	 * @param bool bSubmit : used only for sending main form
81	 * @param bool bFancyBox : used only for fancybox in xhr
82	 * @param string sCallback :
83	 * @param string sErrorType :
84	 * @param string sLoadBar :
85	 * @return string : HTML returned by smarty
86	 */
87	this.form = function (sForm, sURI, sRequestParam, sToDisplay, sToHide, bSubmit, bFancyBox, sCallback, sErrorType, sLoadBar) {
88		// set loading bar
89		if (sLoadBar) {
90			$("#" + sLoadBar).show();
91		}
92
93		// set return validation
94		var aError = [];
95
96		// get all fields of form
97		var fields = $("#" + sForm).serializeArray();
98
99		// set counter
100		var iCounter = 0;
101
102		// set bIsError
103		var bIsError = false;
104
105		toastr.options = {
106			closeButton: true,
107			debug: false,
108			newestOnTop: false,
109			progressBar: true,
110			positionClass: "toast-top-right",
111			preventDuplicates: false,
112			onclick: null,
113			showDuration: "5000",
114			hideDuration: "1000",
115			timeOut: "5000",
116			extendedTimeOut: "1000",
117			showEasing: "swing",
118			hideEasing: "linear",
119			showMethod: "fadeIn",
120			hideMethod: "fadeOut",
121		};
122
123		// check element form
124		jQuery.each(fields, function (i, field) {
125			bIsError = false;
126
127			switch (field.name) {
128				case "id":
129					if (field.value == "") {
130						oThis.aError[iCounter] = oThis.msgs.id;
131						toastr.error(oThis.msgs.id);
132						bIsError = true;
133					}
134					break;
135				case "secret":
136					if (field.value == "") {
137						oThis.aError[iCounter] = oThis.msgs.secret;
138						toastr.error(oThis.msgs.secret);
139						bIsError = true;
140					}
141					break;
142				case "callback":
143					if (field.value == "") {
144						oThis.aError[iCounter] = oThis.msgs.callback;
145						toastr.error(oThis.msgs.callback);
146						bIsError = true;
147					}
148					break;
149				case "scope":
150					if (field.value == "") {
151						oThis.aError[iCounter] = oThis.msgs.scope;
152						toastr.error(oThis.msgs.scope);
153						bIsError = true;
154					}
155					break;
156				case "developerKey":
157					if (field.value == "") {
158						oThis.aError[iCounter] = oThis.msgs.developerKey;
159						toastr.error(oThis.msgs.developerKey);
160						bIsError = true;
161					}
162					break;
163				case "socialEmail":
164					if (field.value == "") {
165						oThis.aError[iCounter] = oThis.msgs.socialEmail;
166						toastr.error(oThis.msgs.socialEmail);
167						bIsError = true;
168					}
169					break;
170				case "fbpscDefaultConnectText":
171					if (field.value == "") {
172						oThis.aError[iCounter] = oThis.msgs.defaultText;
173						toastr.error(oThis.msgs.defaultText);
174						bIsError = true;
175					}
176					break;
177				case "fbpscPrefixCode":
178					if (field.value == "" && $('input:radio[name="fbpscEnableVoucher"]').val() == "true") {
179						oThis.aError[iCounter] = oThis.msgs.prefixCode;
180						toastr.error(oThis.msgs.prefixCode);
181						bIsError = true;
182					}
183					break;
184				case "fbpscApiRequestType":
185					if (field.value == "") {
186						oThis.aError[iCounter] = oThis.msgs.apiType;
187						toastr.error(oThis.msgs.apiType);
188						bIsError = true;
189					}
190					break;
191				case "fbpscHtmlElement":
192					if (field.value == "") {
193						oThis.aError[iCounter] = oThis.msgs.htmlElement;
194						toastr.error(oThis.msgs.htmlElement);
195						bIsError = true;
196					}
197					break;
198				case "fbpscPositionName":
199					if (field.value == "") {
200						oThis.aError[iCounter] = oThis.msgs.positionName;
201						toastr.error(oThis.msgs.positionName);
202						bIsError = true;
203					}
204					break;
205				case "sCssPaddingTop":
206					if (field.value == "" || $.isNumeric(field.value) == false) {
207						oThis.aError[iCounter] = oThis.msgs.padding;
208						toastr.error(oThis.msgs.padding);
209						bIsError = true;
210					}
211					break;
212				case "sCssPaddingRight":
213					if (field.value == "" || $.isNumeric(field.value) == false) {
214						oThis.aError[iCounter] = oThis.msgs.padding;
215						toastr.error(oThis.msgs.padding);
216						bIsError = true;
217					}
218					break;
219				case "sCssPaddingBottom":
220					if (field.value == "" || $.isNumeric(field.value) == false) {
221						oThis.aError[iCounter] = oThis.msgs.padding;
222						toastr.error(oThis.msgs.padding);
223						bIsError = true;
224					}
225					break;
226				case "sCssPaddingLeft":
227					if (field.value == "" || $.isNumeric(field.value) == false) {
228						oThis.aError[iCounter] = oThis.msgs.padding;
229						toastr.error(oThis.msgs.padding);
230						bIsError = true;
231					}
232					break;
233				case "sCssMarginTop":
234					if (field.value == "" || $.isNumeric(field.value) == false) {
235						oThis.aError[iCounter] = oThis.msgs.margin;
236						toastr.error(oThis.msgs.margin);
237						bIsError = true;
238					}
239					break;
240				case "sCssMarginRight":
241					if (field.value == "" || $.isNumeric(field.value) == false) {
242						oThis.aError[iCounter] = oThis.msgs.margin;
243						toastr.error(oThis.msgs.margin);
244						bIsError = true;
245					}
246					break;
247				case "sCssMarginBottom":
248					if (field.value == "" || $.isNumeric(field.value) == false) {
249						oThis.aError[iCounter] = oThis.msgs.margin;
250						toastr.error(oThis.msgs.margin);
251						bIsError = true;
252					}
253					break;
254				case "sCssMarginLeft":
255					if (field.value == "" || $.isNumeric(field.value) == false) {
256						oThis.aError[iCounter] = oThis.msgs.margin;
257						toastr.error(oThis.msgs.margin);
258						bIsError = true;
259					}
260					break;
261				default:
262					break;
263			}
264
265			if (($('input[name="' + field.name + '"]') != undefined || $('textarea[name="' + field.name + '"]') != undefined || $('select[name="' + field.name + '"]').length != undefined) && bIsError == true) {
266				if ($('input[name="' + field.name + '"]').length != 0) {
267					$('input[name="' + field.name + '"]')
268						.parent()
269						.addClass("has-error has-feedback");
270					$('input[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
271				}
272				if ($('textarea[name="' + field.name + '"]').length != 0) {
273					$('textarea[name="' + field.name + '"]')
274						.parent()
275						.addClass("has-error has-feedback");
276					$('textarea[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
277				}
278				if ($('select[name="' + field.name + '"]').length != 0) {
279					$('select[name="' + field.name + '"]')
280						.parent()
281						.addClass("has-error has-feedback");
282					$('select[name="' + field.name + '"]').append('<span class="icon-remove-sign"></span>');
283				}
284				++iCounter;
285			}
286		});
287
288		if (oThis.aError.length == 0 && !bIsError) {
289			// use case - Ajax request
290			if (bSubmit == undefined || bSubmit == null || !bSubmit) {
291				if (sLoadBar && sToHide != null) {
292					oThis.hide(sToHide, true);
293				}
294
295				// format object of fields in string to execute Ajax request
296				var sFormParams = $.param(fields);
297
298				if (sRequestParam != null && sRequestParam != "") {
299					sFormParams = sRequestParam + "&" + sFormParams;
300				}
301
302				// execute Ajax request
303				this.ajax(sURI, sFormParams, sToDisplay, sToHide, bFancyBox, null, sLoadBar);
304
305				return true;
306			}
307			// use case - send form
308			else {
309				// hide loading bar
310				if (sLoadBar) {
311					$("#" + sLoadBar).hide();
312				}
313				document.forms[sForm].submit();
314				return true;
315			}
316		} else {
317			$("#" + sLoadBar).hide();
318		}
319		// display errors
320		this.displayError(sErrorType);
321
322		return false;
323	};
324
325	/*
326	 * ajax() method execute XHR
327	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
328	 * @param string sURI : query params used for XHR
329	 * @param string sParams :
330	 * @param string sToShow :
331	 * @param string sToHide :
332	 * @param bool bFancyBox : used only for fancybox in xhr
333	 * @param bool bFancyBoxActivity : used only for fancybox in xhr
334	 * @param string sLoadBar : used only for loading
335	 * @return string : HTML returned by smarty
336	 */
337	this.ajax = function (sURI, sParams, sToShow, sToHide, bFancyBox, bFancyBoxActivity, sLoadBar) {
338		if (bFancyBox && bFancyBoxActivity != false) {
339			//$.fancybox.showActivity();
340		}
341
342		sParams = "sMode=xhr" + (sParams == null || sParams == undefined ? "" : "&" + sParams);
343
344		// configure XHR
345		$.ajax({
346			type: "POST",
347			url: sURI,
348			data: sParams,
349			dataType: "html",
350			success: function (data) {
351				// hide loading bar
352				if (sLoadBar) {
353					$("#" + sLoadBar).hide();
354				}
355				if (bFancyBox) {
356					// update fancybox content
357					$.fancybox(data);
358					$.fancybox.close();
359
360					// use case - update only widget list
361					if (sToShow == oThis.name + "ConnectorList") {
362						oThis.ajax("" + sURI, "sAction=display&sType=connectors", "" + sToShow + "", "" + sToHide + "");
363					}
364					// use case - update widget list and hook list
365					else if (sToShow == oThis.name + "HookList") {
366						sToShow = sToHide = oThis.name + "ConnectorList";
367						oThis.ajax("" + sURI + "connectors", "sAction=display&sType=connectors", "" + sToShow + "", "" + sToHide + "");
368						sToShow = sToHide = oThis.name + "HookList";
369						oThis.ajax("" + sURI + "hooks", "sAction=display&sType=hooks", "" + sToShow + "", "" + sToHide + "");
370					} else if (sToShow == oThis.name + "HookAdvanced") {
371						oThis.ajax("" + sURI, "sAction=display&sType=hookAdvanced", "" + sToShow + "", "" + sToHide + "");
372					} else if (sToShow == oThis.name + "ShortCode") {
373						oThis.ajax("" + sURI, "sAction=display&sType=shortCode", "" + sToShow + "", "" + sToHide + "");
374					}
375				} else if (sToShow != null && sToHide != null) {
376					// same hide and show
377					if (sToShow == sToHide) {
378						oThis.hide("fast");
379						$("#" + sToHide).hide("fast");
380						$("#" + sToHide).empty();
381						setTimeout("", 1000);
382						oThis.show(sToShow, data);
383					} else {
384						oThis.hide(sToHide);
385						setTimeout("", 1000);
386						oThis.show(sToShow, data);
387					}
388				} else if (sToShow != null) {
389					oThis.show(sToShow, data);
390				} else if (sToHide != null) {
391					oThis.hide(sToHide);
392				} else {
393					oThis.response = data;
394				}
395				setTimeout(function () {
396					$('#fbpscConfirm').slideUp();
397				}, 2000);
398			},
399			error: function (xhr, ajaxOptions, thrownError) {
400				$("#" + oThis.name + "FormError").addClass("alert error");
401				oThis.show("#" + oThis.name + "FormError", "<h3>internal error</h3>");
402			},
403		});
404	};
405
406	/*
407	 * displayError() method display errors
408	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
409	 * @param string sType : type of container
410	 * @return bool
411	 */
412	this.displayError = function (sType) {
413		if (oThis.aError.length != 0) {
414			var sError = '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert">×</button><ul class="list-unstyled">';
415			for (var i = 0; i < oThis.aError.length; ++i) {
416				sError += "<li>" + oThis.aError[i] + "</li>";
417			}
418			sError += "</ul></div>";
419
420			$("#" + oThis.name + sType + "Error").html(sError);
421			$("#" + oThis.name + sType + "Error").slideDown();
422
423			// flush errors
424			oThis.aError = [];
425
426			return false;
427		}
428	};
429
430	/**
431	 * changeSelect() method displays or hide related option form
432	 *
433	 * @param string sId : type of container
434	 * @param mixed mDestId
435	 * @param string sDestId2
436	 * @param string sType of second dest id
437	 * @param bool bForce
438	 * @param bool mVal
439	 */
440	this.changeSelect = function (sId, mDestId, sDestId2, sDestIdToHide, bForce, mVal) {
441		if (bForce) {
442			if (typeof mDestId == "string") {
443				mDestId = [mDestId];
444			}
445
446			for (var i = 0; i < mDestId.length; ++i) {
447				if (mVal) {
448					$("#" + mDestId[i]).fadeIn("fast", function () {
449						$("#" + mDestId[i]).css("display", "block");
450					});
451				} else {
452					$("#" + mDestId[i]).fadeOut("fast");
453				}
454			}
455		} else {
456			$("#" + sId).bind("change", function (event) {
457				$("#" + sId + " input:checked").each(function () {
458					switch ($(this).val()) {
459						case "true":
460							// display option features
461							$("#" + sDestId).fadeIn("fast", function () {
462								$("#" + sDestId).css("display", "block");
463							});
464							break;
465						default:
466							// hide option features
467							$("#" + sDestId).fadeOut("fast");
468
469							// set to false
470							if (sDestId2 && sDestIdToHide) {
471								$("#" + sDestId2 + " input").each(function () {
472									switch ($(this).val()) {
473										case "false":
474											$(this).attr("checked", "checked");
475											// hide option features
476											$("#" + sDestIdToHide).fadeOut("fast");
477											break;
478										default:
479											$(this).attr("checked", "");
480											break;
481									}
482								});
483							}
484							break;
485					}
486				});
487			});
488		}
489	};
490
491	/**
492	 * selectAll() method select / deselect all checkbox
493	 *
494	 * @param string sId : type of container
495	 * @param string sCible : all checkbox to process
496	 */
497	this.selectAll = function (sCible, sType) {
498		if (sType == "check") {
499			$(sCible).attr("checked", true);
500		} else {
501			$(sCible).attr("checked", false);
502		}
503	};
504
505	/*
506	 * updateHook() method verify all childnodes of hook list and determine position to display widget in hook
507	 * User: Business Tech (www.businesstech.fr)
508	 * @param string sURI : query params used for XHR
509	 * @param string sHookList :
510	 * @param string sToShow :
511	 * @param string sToHide :
512	 * @param bool bFancyBox : used only for fancybox in xhr
513	 * @return string : HTML returned by smarty
514	 */
515	this.updateHook = function (sURI, sHookList, sToShow, sToHide, bFancyBox) {
516		var sList = "";
517
518		if ($("#" + sHookList + " li").length != 0) {
519			var aConnectorId = [];
520			$("#" + sHookList + " li").each(function (i, elt) {
521				aConnectorId[i] = elt.id;
522			});
523			sList = aConnectorId.toString();
524		}
525		this.ajax(sURI, "sConnectorList=" + sList, sToShow, sToHide, bFancyBox);
526	};
527
528	/*
529	 * draggableConnector() method set draggable
530	 * User: Business Tech (www.businesstech.fr)
531	 * @param obj Current HTML elt
532	 * @return -
533	 */
534	this.draggableConnector = function () {
535		// declare draggable elts
536		$("#" + oThis.name + "DraggableConnector li").draggable({
537			revert: "invalid",
538		});
539
540		// declare droppable elt - only drop elt in this tag
541		$("#" + oThis.name + "DroppableConnector ul").droppable({
542			drop: function (event, ui) {
543				// append draggable elt
544				$("#" + oThis.name + "DroppableConnector ul").append(ui.draggable);
545				// set css and deactivate drag
546				$(ui.draggable).css({ position: "relative", top: "0px", left: "0px", display: "block" }).draggable("disable").css({ opacity: 1 }).addClass("fbpscsortli", "ui-state-default", "pull-left", "col-xs-8");
547
548				// append img and click evt only in no already added img
549				var bFound = $(ui.draggable).find("span." + oThis.name + "Garbage");
550
551				// use case - add img and click evt in no img case
552				if (bFound.length == 0) {
553					//Init html content
554					var oCurrentDragableA = $(ui.draggable).html();
555					var oGarbage = '<span class="pull-left btn btn-default btn-mini ' + oThis.name + 'Garbage"> <i class="fa fa-trash"/></span>';
556
557					$(ui.draggable).html();
558					$(ui.draggable).html('<div class="row" id="fbpsc" ><div class="col-xs-10">' + oCurrentDragableA + '</div><div class="col-xs-2">' + oGarbage + " </div></div>");
559					$(ui.draggable).bind("click", function () {
560						oThis.deleteConnector(this);
561					});
562				}
563			},
564		});
565	};
566
567	/*
568	 * sortableConnector() method set sortable Connector
569	 * User: Business Tech (www.businesstech.fr)
570	 * @param obj Current HTML elt
571	 * @return -
572	 */
573	this.sortableConnector = function () {
574		// set sortable elt
575		$("#" + oThis.name + "Sortable").sortable();
576		$("#" + oThis.name + "Sortable").disableSelection();
577	};
578
579	/*
580	 * deleteConnector() method delete added Connector in hook form
581	 * User: Business Tech (www.businesstech.fr)
582	 * @param obj Current HTML elt
583	 * @return -
584	 */
585	this.deleteConnector = function (oElt) {
586		$(oElt)
587			.find("button." + oThis.name + "Garbage")
588			.remove();
589		$("#" + oThis.name + "DraggableConnector ul").append($(oElt).removeClass("fbpscsortli").draggable("enable").draggable("option", "revert", "invalid").addClass("fbpscdragli"));
590	};
591
592	/*
593	 * getCharts() method get the charts for connect
594	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
595	 * @param string sElem : Canvas element to plug the charts
596	 * @param array aData : data to manage the charts
597	 * @param array aLabel : list of label to manage
598	 * @param array aColor : color for each element of the charts
599	 * @param string sTitle : the graph title
600	 */
601	this.getCharts = function (sElem, aData, aLabel, aColor, sTitle) {
602		//For filter charts
603		aDataSet = {
604			datasets: [
605				{
606					data: aData,
607					backgroundColor: aColor,
608				},
609			],
610			// These labels appear in the legend and in the tooltips when hovering different arcs
611			labels: aLabel,
612		};
613
614		//var ctx = $('#' + sElem);
615
616		//alert(ctx);
617		new Chart(ctx, {
618			type: "pie",
619			data: aDataSet,
620			options: {
621				legend: {
622					position: "bottom",
623				},
624				title: {
625					display: true,
626					position: "top",
627					text: sTitle,
628					fontSize: 14,
629				},
630			},
631		});
632	};
633
634	/*
635	 * hide() method hide effect and delete html
636	 * User: Business Tech (www.businesstech.fr) - Contact: http://www.businesstech.fr/en/contact-us
637	 * @param string sId : container to hide in
638	 * @return -
639	 */
640	this.hide = function (sId) {
641		$("#" + sId).hide("fast", function () {
642			$("#" + sId).html("");
643		});
644	};
645
646	/**
647	 * getBulkCheckBox() method get all checkbox for one element
648	 *
649	 * @param array aParams
650	 * @param json
651	 */
652	this.getBulkCheckBox = function (sFieldName) {
653		var iElemId = [];
654
655		$('input:checked[name="' + sFieldName + '"]').each(function () {
656			iElemId.push($(this).val());
657		});
658
659		if (iElemId != null) return iElemId;
660		else return (iElemId = 1);
661	};
662
663	/**
664	 * getContentFromSwitch() method return a cotent according to the switch value
665	 */
666	this.getContentFromSwitch = function (sIdElemOn, sElem) {
667		if ($("#" + sIdElemOn).is(":checked") == true) {
668			$("#" + sElem).show();
669		} else {
670			$("#" + sElem).hide();
671		}
672	};
673
674	/**
675	 * getConnectors() method return visual for connectors
676	 * @param sShortCodeName
677	 */
678	this.getConnectors = function (sSelector, sShortCodeName) {
679		this.ajax(this.sShortCodeUrl, "sAction=display&sType=shortCode&sShortCodeName=" + sShortCodeName, "sl_connector_" + sSelector, null, null, null, null);
680	};
681
682	/**
683	 * getConnectors() method return visual for connectors
684	 * @param sElement
685	 * @param sAction
686	 */
687	this.activateLinkedOption = function(sElement, sAction) {
688		if (sAction == 'click'){
689			$('#' + sElement).trigger('click');
690		}
691
692	};
693};

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.