PageSourceSearch

https://uvejuegos.com/js/formulario.js?now=2026092501

js uvejuegos.com collected 2026-09-24 23:32:23 UTC 15,484 bytes, 401 lines download raw bytes

1(function ($)
2{
3    var modalBotones = 
4    {
5        cancelar: {label: "Cancelar", className: "btn-default"},
6        aceptar: {label: "Aceptar", className: "btn-primary"}
7    }
8    
9    var editor = function (elemento, opciones)
10	{
11		this.elemento = elemento;
12        this.editor = null;
13
14        this.inicializar ();
15	};
16
17	editor.prototype.inicializar = function ()
18	{
19        var botones = [];
20        var acciones =
21        [
22			// B: Botón
23			// S: Select
24			// E: Espacio
25
26            {tipo: "B", funcion: "insertarEtiqueta", param: "b", texto: "Negrita", icono: "mdi mdi-format-bold"},
27            {tipo: "B", funcion: "insertarEtiqueta", param: "i", texto: "Cursiva", icono: "mdi mdi-format-italic"},
28            {tipo: "B", funcion: "insertarEtiqueta", param: "u", texto: "Subrayado", icono: "mdi mdi-format-underline"},
29            {tipo: "B", funcion: "insertarEtiqueta", param: "t", texto: "Tachado", icono: "mdi mdi-format-strikethrough"},
30            {tipo: "E"},
31			{tipo: "B", funcion: "insertarEtiqueta", param: "l", texto: "Alinear a la izquierda", icono: "mdi mdi-format-align-left"},
32			{tipo: "B", funcion: "insertarEtiqueta", param: "c", texto: "Centrar", icono: "mdi mdi-format-align-center"},
33			{tipo: "B", funcion: "insertarEtiqueta", param: "d", texto: "Alinear a la derecha", icono: "mdi mdi-format-align-right"},
34			{tipo: "E"},
35			{tipo: "B", funcion: "insertarEtiqueta", param: "spoiler", texto: "Spoiler", icono: "mdi mdi-eye-off"},
36			{tipo: "B", funcion: "citar", texto: "Citar", icono: "mdi mdi-format-quote"},
37			{tipo: "E"},
38			{tipo: "B", funcion: "insertarEnlace", texto: "Insertar enlace", icono: "mdi mdi-link-variant"},
39			{tipo: "E"},
40			{tipo: "B", funcion: "insertarImagen", texto: "Insertar imagen", icono: "mdi mdi-image"},
41			{tipo: "B", funcion: "insertarAudio", texto: "Insertar audio", icono: "mdi mdi-volume-medium"},
42			{tipo: "B", funcion: "insertarVideo", texto: "Insertar vídeo", icono: "mdi mdi-play-box-outline"},
43			{tipo: "E"},
44			{tipo: "S", funcion: "insertarEtiqueta", param: [["times", "Times"], ["arial", "Arial"], ["verdana", "Verdana"], ["tahoma", "Tahoma"], ["courier", "Courier"]], texto: "Fuente"},
45			{tipo: "S", funcion: "insertarEtiqueta", param: [["amarillo", "Amarillo"], ["verde", "Verde"], ["rojo", "Rojo"], ["negro", "Negro"], ["blanco", "Blanco"], ["gris", "Gris"], ["naranja", "Naranja"], ["azul", "Azul"], ["marron", "Marrón"], ["morado", "Morado"]], texto: "Color texto"},
46			{tipo: "S", funcion: "insertarEtiqueta", param: [["h0", "Pequeñísimo"], ["h1", "Pequeño"], ["h2", "Mediano"], ["h3", "Grande"], ["h4", "Muy grande"], ["h5", "Grandísimo"]], texto: "Tamaño texto"}			
47        ];
48
49        for (var i = 0; i < acciones.length; i ++)
50        {
51			botones.push (this["generar" + acciones[i].tipo] (acciones[i]));
52        };
53        
54		var funcionBotonClick = $.proxy (this.botonClick, this);
55		this.editor = $("<div class=\"editor-botones\">" + botones.join ("") + "</div>");
56		this.editor.on ("click", "a", funcionBotonClick);
57		this.editor.on ("change", "select", funcionBotonClick);
58		this.elemento.before (this.editor);
59	};
60
61	editor.prototype.generarB = function (elemento)
62	{
63		var boton = "<a href=\"#\"";
64		if (elemento.funcion) boton += " data-funcion=\"" + elemento.funcion + "\"";
65		if (elemento.param) boton += " data-param=\"" + elemento.param + "\"";
66		if (elemento.texto) boton += " title=\"" + elemento.texto + "\"";
67		boton += ">";
68		if (elemento.icono) boton += "<span class=\"" + elemento.icono + "\"></span>";
69		else boton += elemento.texto;
70		boton += "</a>";
71		return boton;
72	};
73
74	editor.prototype.generarE = function (elemento)
75	{
76		return "<span class=\"separador\"></span>";	
77	};
78
79	editor.prototype.generarS = function (elemento)
80	{
81		var sel = "<select";
82		if (elemento.funcion) sel += " data-funcion=\"" + elemento.funcion + "\"";
83		sel += ">";
84		if (elemento.texto) sel += "<option value=\"\">" + elemento.texto + "</option>";
85
86		var param = elemento.param;
87		$.each (param, function (pos, opcion)
88		{
89			sel += "<option value=\"" + opcion[0] + "\">" + opcion[1] + "</option>";
90		});
91		sel += "</select>";
92		return sel;
93	};
94
95    editor.prototype.obtenerSeleccion = function ()
96    {
97        var texto = this.elemento.val ();
98        var len = texto.length;
99        var inicio = this.elemento[0].selectionStart;
100        var fin = this.elemento[0].selectionEnd;
101
102        return texto.substring (inicio, fin);
103    };
104
105    editor.prototype.insertarTexto = function (insercion)
106    {
107    	var texto = this.elemento.val ();
108		var len = texto.length;
109		var inicio = this.elemento[0].selectionStart;
110		var fin = this.elemento[0].selectionEnd;
111		var seleccionado = texto.substring (inicio, fin);
112		this.elemento.val (texto.substring (0, inicio) + insercion + texto.substring (fin, len));
113    }
114
115    editor.prototype.botonClick = function (event)
116    {
117        var $this = $(event.currentTarget);
118		this[$this.data ("funcion")] ($this);
119        event.preventDefault ();
120    };
121
122	editor.prototype.insertarEtiqueta = function (elemento)
123	{
124		var control = elemento.get (0).tagName.toLowerCase ();
125		var etiqueta = control == "select"? elemento.val (): elemento.data ("param");
126		if (etiqueta.length > 0)
127		{
128			this.insertarTexto ("[" + etiqueta + "]" + this.obtenerSeleccion () + "[/" 
128+ etiqueta + "]");
129			if (control == "select") elemento.val ("");
130		}
131	};
132
133	editor.prototype.citar = function ()
134	{
135		var html = "<div class=\"form-group\"><label for=\"txt-form-usuario\">¿A quién quieres citar?</label><input type=\"text\" class=\"form-control\" id=\"txt-form-usuario\" autofocus required></div>";
136		html += "<div class=\"form-group\"><label for=\"txt-form-texto\">Cita</label><textarea class=\"form-control\" id=\"txt-form-texto\">" + this.obtenerSeleccion () + "</textarea></div>"
137		var form = $(html);
138		var yo = this;
139
140		bootbox.dialog ({title: "Insertar cita", message: form, animate: false, buttons: $.extend (true, {}, modalBotones, {
141			aceptar: {callback: function ()
142			{
143				yo.insertarTexto ("[cita \"" + form.find ("#txt-form-usuario").val () + "\"]" + form.find ("#txt-form-texto").val () + "[/cita]");
144			}}})});
145		form.find ("[autofocus]").focus ();
146	};
147
148	editor.prototype.insertarEnlace = function ()
149	{
150		var html = "<div class=\"form-group\"><label for=\"txt-form-url\">URL</label><input type=\"url\" class=\"form-control\" id=\"txt-form-url\" autofocus required></div>";
151		html += "<div class=\"form-group\"><label for=\"txt-form-texto\">Texto del enlace</label><input type=\"text\" class=\"form-control\" id=\"txt-form-texto\" value=\"" + this.obtenerSeleccion () + "\"></div>"
152		var form = $(html);
153		var yo = this;
154
155		bootbox.dialog ({title: "Insertar enlace", message: form, animate: false, buttons: $.extend (true, {}, modalBotones, {
156			aceptar: {callback: function ()
157			{
158				yo.insertarTexto ("[a \"" + form.find ("#txt-form-url").val () + "\" " + form.find ("#txt-form-texto").val () + "]");
159			}}})});
160		form.find ("[autofocus]").focus ();
161	};
162
163	editor.prototype.insertarImagen = function ()
164	{
165		var html = "<div class=\"form-group\"><label for=\"txt-form-url\">URL</label><input type=\"url\" class=\"form-control\" id=\"txt-form-url\" autofocus required></div>";
166		html += "<div class=\"form-check\"><label class=\"form-check-label\"><input type=\"checkbox\" class=\"form-check-input\" id=\"check-form-ampliada\" onclick=\"$('#fg-txt-form-ampliada').toggleClass ('hidden')\">Ampliar al hacer click</label></div>";
167		html += "<div class=\"form-group hidden\" id=\"fg-txt-form-ampliada\"><label for=\"txt-form-ampliada\">URL imagen ampliada</label><input type=\"text\" class=\"form-control\" id=\"txt-form-ampliada\"></div>"
168		var form = $(html);
169		var yo = this;
170
171		bootbox.dialog ({title: "Insertar imagen", message: form, animate: false, buttons: $.extend (true, {}, modalBotones, {
172			aceptar: {callback: function ()
173			{
174				var url = form.find ("#txt-form-url").val ();
175				var urlAmpliada = form.find ("#txt-form-ampliada").val ();
176				var ampliar = form.find ("#check-form-ampliada").prop ("checked");
177
178				if (ampliar && urlAmpliada.length > 0) yo.insertarTexto ("<a href=\"" + urlAmpliada + "\" class=\"lightbox\" target=\"_blank\">[img \"" + url + "\"]</a>");
179				else yo.insertarTexto ("[img \"" + url + "\"]");
180			}}})});
181		form.find ("[autofocus]").focus ();
182	};
183
184	editor.prototype.insertarAudio = function ()
185	{
186		this.insertarVideo ({titulo: "Insertar audio", atributos: {height: 100}});
187	};
188
189	editor.prototype.insertarVideo = function (opciones)
190	{
191		var html = "<div class=\"form-group\"><label for=\"txt-form-url\">URL</label><input type=\"url\" class=\"form-control\" id=\"txt-form-url\" autofocus required></div>";
192		html += "<div class=\"alert alert-warning hidden\" id=\"alert-video-txt-form-url\">La URL introducida no está soportada en uVeJuegos.com. Si piensas que debería estarlo, contacta con nosotros y estudiaremos su inclusión.</div>"
193		var form = $(html);
194		var yo = this;
195		opciones = opciones? opciones: {};
196
197		bootbox.dialog ({title: opciones.titulo? opciones.titulo: "Insertar vídeo", message: form, animate: false, buttons: $.extend (true, {}, modalBotones, {
198			aceptar: {callback: function ()
199			{
200				var url = form.find ("#txt-form-url").val ();
201				var infoVideo = obtenerVideoEmbed (url);
202				if (infoVideo.url == "")
203				{
204					$("#alert-video-txt-form-url").removeClass ("hidden");
205					return false;
206				}
207				else
208				{
209					$("#alert-video-txt-form-url").addClass ("hidden");
210					var etiqueta = "[video \"" + url + "\"";
211					if (opciones.atributos)
212					{
213						for (var atributo in opciones.atributos) etiqueta += " " + atributo + "=\"" + opciones.atributos[atributo] + "\"";
214					}
215					etiqueta += "]";
216					yo.insertarTexto (etiqueta);
217				}
218				
219			}}})});
220		form.find ("[autofocus]").focus ();
221	};
222
223	$.fn.editor = function (opciones)
224	{
225		return this.each (function ()
226		{
227			var $this = $(this);
228			if ($this.data ("editor")) return;
229			$this.data ("editor", new editor ($this, opciones));
230		});
231	};
232
233}) (jQuery);
234
235(function ($)
236{
237    var formulario = function (elemento, opciones)
238	{
239		this.form = elemento;
240        this.campoPrevisualizar = null;
241        this.capaPrevisualizar = null;
242        this.guardado = true;
243        this.enviando = false;
244        this.inicializar ();
245	};
246
247    formulario.prototype.inicializar = function ()
248    {
249    	var funcionModificado = $.proxy (this.modificado, this);
250
251        this.campoPrevisualizar = this.form.find ("input[name=previsualizar]");
252        this.form.find ("[data-previsualizar]").on ("click", $.proxy (this.previsualizar, this));
253        this.form.on ("submit", $.proxy (this.enviar, this));
254        this.form.on ("click", "select, input[type=checkbox], input[type=radio]", funcionModificado);
255        this.form.on ("change keypress", "input, textarea", funcionModificado);
256    };
257
258    formulario.prototype.modificado = function ()
259    {
260    	if (this.guardado)
261    	{
262			this.guardado = false;
263			this.form.removeClass ("guardado").addClass ("modificado");
264		}
265    };
266
267    formulario.prototype.prepararEnvio = function ()
268    {
269    	this.enviando = true;
270		this.form.addClass ("enviando");
271		this.form.val (this.form.val ().replace ("€", "&euro;"));
272    };
273
274    formulario.prototype.previsualizar = function (event)
275    {
276    	if (this.enviando) return false;
277
278		if (this.capaPrevisualizar == null)
279        {
280        	var capa= $("<div class=\"previsualizacion\"><div class=\"h4\">Previsualización</div><div class=\"foro-aportacion\"><div class=\"cuerpo\"></div></div></div>");
281        	this.form.after (capa);
282        	this.capaPrevisualizar = capa.find (".cuerpo");
283        }
284
285        this.campoPrevisualizar.val (1);
286        this.prepararEnvio ();
287
288        var yo = this;
289        var url = this.form.data ("url-previsualizacion");
290        if (url == null) url = this.form.data ("action");
291        if (url == null) url = this.form.attr ("action");
292        if (url == null) url = window.location.href;
293
294        var opciones = {url: url};
295
296		opciones.success = function (data)
297		{
298			yo.form.removeClass ("enviando");
299			yo.enviando = false;
300			yo.capaPrevisualizar.removeClass ("cargando").html (data);
301		};
302
303		opciones.error = function ()
304		{
305			yo.form.removeClass ("enviando");
306			yo.enviando = false;
307			yo.capaPrevisualizar.removeClass ("cargando").data ("No se ha podido hacer la previsualización debido a un error de comunicación con el servidor.");
308		};
309
310        this.capaPrevisualizar.html ("").addClass ("cargando");
311        this.form.ajaxSubmit (opciones);
312    };
313
314    formulario.prototype.enviar = function (event)
315    {
316        if (this.enviando)
317        {
318            event.preventDefault ();
319            return false;
320        }
321
322		var funcionValidar = this.form.data ("funcion-validar");
323		if (funcionValidar)
324		{
325			var ok = window[funcionValidar] (this);
326			if (!ok) return false;
327		}
328
329        this.campoPrevisualizar.val (0);
330        this.prepararEnvio ();
331        this.guardado = false;
332        this.form.removeClass ("guardado modificado");
333
334        var ajax = this.form.data ("ajax");
335        if (ajax != null)
336        {
337            event.preventDefault ();
338
339            var yo = this;
340            var filtro = this.form.data ("filtro");
341			var url = this.form.data ("action");
342	        if (url == null) url = this.form.attr ("action");
343	        if (url == null) url = window.location.href;
344
345	        var opciones = {url: url};
346	        if (filtro == null) opciones.dataType = "json";
347	        {
348	            opciones.dataType = "text";
349	            opciones.dataFilter = filtrarJson;
350	        }
351
352            opciones.success = function (data)
353            {
354                yo.form.removeClass ("enviando");
355                yo.enviando = false;
356                if (data.ok)
357                {
358                    var funcionOk = yo.form.data ("funcion-ok");
359                    var retorno = yo.form.data ("retorno");
360
361				    if (funcionOk) window[funcionOk] (data, yo);
362                    if (retorno) window.location.href = retorno;
363
364                    var fecha = new Date ();
365                    yo.guardado = true;
366                    yo.form.find ("data-form-fecha-guardado").html (fecha.toLocaleStr
366ing ());
367                    yo.form.addClass ("guardado");
368                }
369                if (data.mensaje && data.mensaje.length > 0) alert (data.mensaje);
370            };
371
372            opciones.error = function ()
373            {
374                yo.form.removeClass ("enviando").addClass ("modificado");
375                yo.enviando = false;
376                alert ("No se ha podido enviar el formulario debido a un error en el servidor.");
377            };
378
379            
380            this.form.ajaxSubmit (opciones);
381        }
382    };
383
384    $.fn.formulario = function (opciones)
385	{
386		return this.each (function ()
387		{
388			var $this = $(this);
389			if ($this.data ("formulario")) return;
390			$this.data ("formulario", new formulario ($this, opciones));
391		});
392	};
393    
394}) (jQuery);
395
396$(document).ready (function ($)
397{
398    $("form[data-form]").formulario ();
399    $("textarea.editor").editor ();
400});
401

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.