Documentos de Académico
Documentos de Profesional
Documentos de Cultura
PROYECTO FINAL
- DWEC
Enric Gil Gallen
Introducción
La base del proyecto es una Web para un servicio de catering “Palacios Sucre y Sal” en la
cual le se le añadirán Script Ajax y Jquery para mejorar su usabilidad y hacerla mas
dinámica.
1º Script:
Codigo:
Fuente:
JavaScript
1º Script:
Comprueba si es la 1º vez que un usuario entra y le aparece un alert con un código de
descuento.
Este Script me pareció una gran idea para fidelizar clientes alapar que para darle un toque
distinguido a la web.
Codigo:
< script language = " JavaScript " type = " text / javascript " >
readCookie ( ) ;
función readCookie ( ) {
si ( documento . galletas == " " ) {
writeCookie ( ) ;
alertMessage ( ) ;
} else {
var the_cookie = documento . galleta ;
the_cookie = unescape ( the_cookie ) ;
the_cookie_split = the_cookie . división ( " ; " );
for ( loop = 0 ; loop < the_cookie_split . length ; loop ++ ) {
the_cookie_split [ loop ] ;
var part_of_split =
part_of_split . indexOf ( " nfti_date " )
var find_name =
if ( find_name ! = - 1 ) {
break ;
} // Cerrar si
} // Cerrar para
si ( find_name == - 1 ) {
writeCookie ( ) ;
alerta ( " Bienvenido - Alguien tu primera visita aquí tiene este codigo
de 5% de descunto. " )
} else {
alerta ( " Este texto comprueba que funciona. " ) ;
}
}
}
< / script >
Fuente: http://www.efectosjavascript.com/ultimavisita.html
2ºScript
Este Script es una cuenta atrás, la cual esta aplicada para gestionar ofertas temporales. La
función del Script es hacer pensar a los clientes que es algo especial para que realicen una
compra inmediata.
Codigo:
< script >
var no = 5 ; // número de nieve
var speed = 15 ; // un número más pequeño mueve la nieve más rápido
var snowflake = img1 ;
var ns4up = ( documento . capas ) ? 1 : 0 ; // navegador sniffer
var ie4up = ( document . all ) ? 1 : 0 ;
var dx , xp, yp ; // coordinar y variables de posición
var am , STX , pocilga ; // variables de amplitud y paso
var i , doc_width = 400 , doc_height = 500 ;
if ( ns4up ) {
doc_width = self . innerWidth ;
doc_height = auto . Altura interior ;
} else if ( ie4up ) {
doc_width= 500 ;
doc_height = 500 ;
}
dx = new Array ( ) ;
xp = new Array ( ) ;
yp = new Array ( ) ;
am = new Array ( ) ;
stx = new Array ( ) ;
sty = new Array ( ) ;
para ( i = 0 ;yo < no ; ++ i ) {
dx [ i ] = 0 ; // establecer las variables de coordenadas
xp [ i ] = Math . random ( ) * ( doc_width - 50 ) ; // establecer las variables de posición
yp [ i ] = Math . random ( ) * doc_height ;
am [ i ] = Matemáticas .aleatorio ( ) * 20 ; // establece las variables de amplitud
stx [ i ] = 0.02 + Math . random ( ) / 10 ; // establecer las variables de paso
sty [ i ] = 0.7 + Math . aleatorio ( ) ; // establece las variables de paso
if ( ns4up ) { // establece capas
if ( i == 0 ) {
document .write ( " <nombre de la capa = " punto " + i + " " izquierda = " 15 " " ) ;
documento . write ( " top = " 15 " visibility = " mostrar " > <img src = " " ); document.write
(snowflake + " " border = " 0 " > </ layer> " ) ; } else {
documento . escribir (
" <nombre de la capa = " punto " + i + " " izquierda = " 15 " " ) ;
documento . write ( " top = " 15 " visibility = " mostrar " > <img src = " " ); document.write
(snowflake + " " border = " 0 " > </ layer> " ) ;
i == 0 ) {
documento . write ( " <div id = " dot " + i + " " style = " POSITION : " );
document.write ( " absolute ; Z - INDEX : " + i + " ; VISIBILIDAD : " );
document.write ( " visible ; SUPERIOR : 15px ; IZQUIERDA : 15px ; "> <img src = " " );
document.write (copo de nieve + " " border = " 0 " > </ div> " ) ;
} demás {
documento . escribir ( " <div id = " dot " + i + " " style = " POSICIÓN : " );
document.write ( " absolute ; Z - INDEX : " + i + " ;
document.write ( " visible ; TOP : 15px ; IZQUIERDA : 15px ; " > <img src = " " );
document.write (snowflake + " " border = " 0 " > </ div> " ) ;
}
}
}
función snowNS ( ) { // Función de animación principal de Netscape
para ( i = 0 ; i < no ; ++ i ) { // iterar para cada punto
yp [ i ] + = sty [ i ] ;
if ( yp [ i ] > doc_height - 50 ) {
xp [ i ] = Matemáticas . random ( ) * ( doc_width - am [ i ] - 30 ) ;
yp [ i ] = 0 ;
stx [ i ] = 0.02 + Matemáticas . random ( ) / 10 ;
sty [ i ] = 0.7 + Matemáticas . aleatorio ( ) ;
doc_width = self . innerWidth ;
doc_height = auto . Altura interior ;
}
dx [ i ] + = stx [ i ] ;
documento . capas [ " punto "+ i ] . top = yp [ i ] ;
documento . capas [ " punto " + i ] . left = xp [ i ] + am [ i ] * Matemáticas . sin ( dx [ i ] ) ;
}
setTimeout ( " snowNS () " , velocidad ) ;
}
funciónsnowIE ( ) { // Función de animación principal IE
para ( i = 0 ; i < no ; ++ i ) { // iterar para cada punto
yp [ i ] + = sty [ i ] ;
if ( yp [ i ] > doc_height - 50 ) {
xp [ i ] = Matemáticas . aleatorio ( ) * (doc_width - am [ i ] - 30 ) ;
yp [ i ] = 0 ;
stx [ i ] = 0.02 + Matemáticas . random ( ) / 10 ;
sty [ i ] = 0.7 + Matemáticas . aleatorio ( ) ;
doc_width = document . cuerpo . clientWidth ;
doc_height =documento . cuerpo . clienteAltura ;
}
dx [ i ] + = stx [ i ] ;
documento . todo [ " punto " + i ] . estilo . pixelTop = yp [ i ] ;
documento . todo [ " punto " + i ] . estilo . pixelLeft = xp [ i] + am [ i ] * Matemáticas . sin ( dx
[i]);
}
setTimeout ( " snowIE () " , velocidad ) ;
}
if ( ns4up ) {
snowNS ( ) ;
} else if ( ie4up ) {
snowIE ( ) ;
}
< / script >< script >
var no = 5 ; // número de nieve
var speed = 15 ; // un número más pequeño mueve la nieve más rápido
var snowflake = img1 ;
var ns4up = ( documento . capas ) ? 1 : 0 ; // navegador sniffer
var ie4up = ( document . all ) ? 1 : 0 ;
var dx , xp, yp ; // coordinar y variables de posición
var am , STX , pocilga ; // variables de amplitud y paso
var i , doc_width = 400 , doc_height = 500 ;
if ( ns4up ) {
doc_width = self . innerWidth ;
doc_height = auto . Altura interior ;
} else if ( ie4up ) {
doc_width= 500 ;
doc_height = 500 ;
}
dx = new Array ( ) ;
xp = new Array ( ) ;
yp = new Array ( ) ;
am = new Array ( ) ;
stx = new Array ( ) ;
sty = new Array ( ) ;
para ( i = 0 ;yo < no ; ++ i ) {
dx [ i ] = 0 ; // establecer las variables de coordenadas
xp [ i ] = Math . random ( ) * ( doc_width - 50 ) ; // establecer las variables de posición
yp [ i ] = Math . random ( ) * doc_height ;
am [ i ] = Matemáticas .aleatorio ( ) * 20 ; // establece las variables de amplitud
stx [ i ] = 0.02 + Math . random ( ) / 10 ; / / establecer las variables de paso
sty [ i ] = 0.7 + Math . aleatorio ( ) ; / / establece las variables de paso
if ( ns4up ) { // establece capas
if ( i == 0 ) {
document .write ( " <nombre de la capa = " punto " + i + " " izquierda = " 15 " " ) ;
documento . write ( " top = " 15 " visibility = " mostrar " > <img src = " " ); document.write
(snowflake + " " border = " 0 " > </ layer> " ) ; } else {
documento . escribir (
" <nombre de la capa = " punto " + i + " " izquierda = " 15 " " ) ;
documento . write ( " top = " 15 " visibility = " mostrar " > <img src = " " ); document.write
(snowflake + " " border = " 0 " > </ layer> " ) ;
i == 0 ) {
documento . write ( " <div id = " dot " + i + " " style = " POSITION : " );
document.write ( " absolute ; Z - INDEX : " + i + " ; VISIBILIDAD : " );
document.write ( " visible ; SUPERIOR : 15px ; IZQUIERDA : 15px ; "> <img src = " " );
document.write (copo de nieve + " " border = " 0 " > </ div> " ) ;
} demás {
documento . escribir ( " <div id = " dot " + i + " " style = " POSICIÓN : " );
document.write ( " absolute ; Z - INDEX : " + i + " ;
document.write ( " visible ; TOP : 15px ; IZQUIERDA : 15px ; " > <img src = " " );
document.write (snowflake + " " border = " 0 " > </ div> " ) ;
}
}
}
función snowNS ( ) { // Función de animación principal de Netscape
para ( i = 0 ; i < no ; ++ i ) { // iterar para cada punto
yp [ i ] + = sty [ i ] ;
if ( yp [ i ] > doc_height - 50 ) {
xp [ i ] = Matemáticas . random ( ) * ( doc_width - am [ i ] - 30 ) ;
yp [ i ] = 0 ;
stx [ i ] = 0.02 + Matemáticas . random ( ) / 10 ;
sty [ i ] = 0.7 + Matemáticas . aleatorio ( ) ;
doc_width = self . innerWidth ;
doc_height = auto . Altura interior ;
}
dx [ i ] + = stx [ i ] ;
documento . capas [ " punto "+ i ] . top = yp [ i ] ;
documento . capas [ " punto " + i ] . left = xp [ i ] + am [ i ] * Matemáticas . sin ( dx [ i ] ) ;
}
setTimeout ( " snowNS () " , velocidad ) ;
}
funciónsnowIE ( ) { // Función de animación principal IE
para ( i = 0 ; i < no ; ++ i ) { // iterar para cada punto
yp [ i ] + = sty [ i ] ;
if ( yp [ i ] > doc_height - 50 ) {
xp [ i ] = Matemáticas . aleatorio ( ) * (doc_width - am [ i ] - 30 ) ;
yp [ i ] = 0 ;
stx [ i ] = 0.02 + Matemáticas . random ( ) / 10 ;
sty [ i ] = 0.7 + Matemáticas . aleatorio ( ) ;
doc_width = document . cuerpo . clientWidth ;
doc_height =documento . cuerpo . clienteAltura ;
}
dx [ i ] + = stx [ i ] ;
documento . todo [ " punto " + i ] . estilo . pixelTop = yp [ i ] ;
documento . todo [ " punto " + i ] . estilo . pixelLeft = xp [ i] + am [ i ] * Matemáticas . sin ( dx [
i ] ) ;
}
setTimeout ( " snowIE () " , velocidad ) ;
}
if ( ns4up ) {
snowNS ( ) ;
} else if ( ie4up ) {
snowIE ( ) ;
}
< / script >
Fuente:https://www.lawebdelprogramador.com/codigo/JavaScript/1430-Cuenta-atras-
hasta-una-fecha.html
3º Script
Este Script es un calendario en cual puedes introducir una fecha y te muestra un calendario
con los días que está abierto y cerrado.
Codigo:
var A_TCALCONF = {
' cssprefix ' : ' tcal ' ,
' months ' : [ ' Enero ' , ' Febrero ' , ' Marzo ' , ' Abril ' , ' Mayo ' , ' Junio ' , ' Julio ' ,
'Augost ' , ' Septimbre ' , ' Octobre ' , ' Novembre ' , ' Diciembre ' ] ,
'entre semana ' : [ ' Do ' , ' Lu ' , ' Ma ' , ' Mi ' , ' Ju ' , ' Vi ' , ' Sa ' ] ,
' longwdays ' : [ ''Domingo ' , ' Lunes ' , ' Martes ' , ' Miercoles ' , ' Jueves ' , ' Viernes '
, ' Sábado ' ] ,
' yearscroll ' : cierto , / / muestra el año de desplazamiento
' weekstart ' : 0 , // primer día de semana: 0-Su o 1-Mo
'año anterior ' : ' Año anterior ' ,
'nextyear ' : ' Próximo año ' ,
' precedente ' : ' Mes anterior ' ,
' próximo mes ' : ' Próximo mes ' ,
' formato ' : ' m / d / Y ' //' dm-Y ', Ym-d', 'l, F jS Y'
};
var A_TCALTOKENS = [
// Una representación numérico completo de un año, 4 dígitos
{ ' t ' : ' Y ' , ' R ' : ' 19 \\ d
{2} | 20 \\ d {2} ' , ' p ' : function ( d_date , n_value ) {
d_date . setFullYear ( Number ( n_value ) ) ; devolver d_date ; }, ' g ' : function ( d_date ) {
var n_year = d_date . getFullYear ( ) ; d evolver n_year ; } } ,
// Representación numérica de un mes, con ceros a la izquierda
{ ' t ' : ' m ' , ' r ' : ' 0? [1-9] | 1 [0-2] ' , ' p ' : function ( d_date ,n_value ) { d_date .
setMonth ( Number ( n_value ) - 1 ) ; devolver d_date ; } , ' g ' : function ( d_date ) { var
n_month = d_date . getMonth ( ) + 1 ; return ( n_month < 10 ? ' 0 ' : ' ' ) +n_month } } ,
// Una representación textual completa de un mes, como enero o marzo
{ ' t ' : ' F ' , ' r ' : A_TCALCONF . m eses . join ( ' | ' ) , ' p ' : function ( d_date ,
s_value ) { for ( var m = 0 ; m < 12 ; m++ ) if ( A_TCALCONF . months [ m ] == s_value ) {
d_date . setMonth ( m ) ; devolver d_date ; } } , ' g ' : function ( d_date ) { return
A_TCALCONF . meses [ d_date . getMonth ( ) ] ; } } ,
// Día del mes, 2 dígitos con ceros a la izquierda
{ ' t ' : ' d ' , ' r ' : ' 0? [1-9] | [12] [0-9] | 3 [01] ' , ' p ' : function ( d_date , n_value ) {
d_date . setDate ( Number ( n_value ) ) ; if ( d_date . getDate ( ) ! = n_value ) d_date
.setDate ( 0 ) ; return d_date } , ' g ' : f unction ( d_date ) { var n_date = d_date . getDate ( )
; return ( n_date < 10 ? ' 0 ' : ' ' ) + n_date ; } } ,
// Día del mes sin ceros a la izquierda
{ ' t ' : 'j ' , ' r ' : ' 0? [1-9] | [12] [0-9] | 3 [01] ' , ' p ' : function ( d_date , n_value ) {
d_date . setDate ( Number ( n_value ) ) ; if ( d_date . getDate ( ) ! = n_value ) d_date .
setDate ( 0 ) ; return d_date } , ' g ' : function ( d_date ) { var n_date = d_date . getDate ( )
; return n_date ; } } ,
// Una representación textual completa del día de la semana
{ ' t ' : ' l ' , ' r ' : A_TCALCONF . L ongwdays . join ( ' | ' ) , ' p ': function ( d_date ,
s_value ) { return d_date } , ' g ' : function ( d_date ) { return A_TCALCONF . longwdays [
d_date . getDay ( ) ] ; } } ,
// sufijo ordinal en inglés para el día del mes, 2 caracteres
{ ' t ' : ' S ' , ' r ' : 'st | nd | rd | th ' , ' p ' : function ( d_date , s_value ) { return d_date }
, ' g ' : function ( d_date ) { n_date = d_date . getDate ( ) ; if ( n_date % 10 == 1 && n_date !
= 11 ) return ' st ' ; si (n_date % 10 = = 2 && n_date ! = 12 ) return ' nd ' ; if ( n_date % 10
== 3 && n_date ! = 13 ) return ' rd ' ; devolver ' th ' ; } }
] ;
var a_class , s_html = ' <table id = " ' + s_pfx + ' Controls"> <tbody> <tr> '
+ ( A_TCALCONF . yearscroll ? ' <td id = " ' + s_pfx + ' PrevYear" ' +
f_tcalRelDate ( d_date) , - 1 , ' y ' ) + ' título = " ' + A_TCALCONF .prevyear + '"> </ td> ' : ' ' )
+ ' <td id =" ' + s_pfx + ' PrevMonth " ' + f_tcalRelDate ( d_date , - 1 ) + ' title
=" ' + A_TCALCONF . prevmonth + ' "> </ td> <th> '
+ A_TCALCONF . months [ d_date . getMonth ( ) ] + ' ' getFullYear ( )
+ ' </ th> <td id = " ' + s_pfx + ' NextMonth" ' + f_tcalRelDate ( d_date , 1 ) + '
title = " ' + A_TCALCONF . nextmonth + ' "> </ td> '
+ ( A_TCALCONF . Yearscroll ? ' < Td id = " ' + s_pfx + ' NextYear" ' +
f_tcalRelDate ( d_date, 1 , ' y ' ) + ' título = " ' + A_TCALCONF . Nextyear + ' "> </ td> ' : ' ' )
+ ' </ tr> </ tbody> </ table> <table id = " ' + s_pfx + ' Grid'> <tbody> <tr> ' ;
a_class = [ ] ;
n_date = d_current . getDate ( ) ;
n_month = d_current . getMonth ( ) ;
s_html + = ' <td ' + f_tcalRelDate ( d_current ) + ( a_class . length ? '
class = " ' + a_class . join ( ' ' ) + ' "> ' : ' > ' ) + n_date + ' </ td> ' ;
d_actual . setDate ( ++ n_date ) ; }
s_html
+ = ' </ tr> ' ;
}
s_html + = ' </ tbody> </ table> ' ;
devuelve s_html ;
}
var s_units = ( s_units == ' y ' ? ' FullYear ' : ' Mes ' ) ;
var d_result = new Date ( d_date ) ;
if ( d_diff ) {
d_result [ ' set ' + s_units ] ( d_date [ ' get ' + s_units ] ( ) + d_diff) ;
if ( d_result . getDate ( ) ! = d_date . getDate ( ) )
d_result . s etDate ( 0 ) ;
}
return ' onclick = "f_tcalUpdate ( ' + d_result . valueOf ( ) + ( d_diff ? ' , 1 ' : ' ' ) + ' )" '
;
}
if ( b_keepOpen ) {
var e_cal = documento . getElementById ( s_pfx ) ;
if ( ! e_cal || e_cal . style . visibility ! = ' visible ' ) return ;
e_cal . innerHTML = f_tcalGetHTML ( d_date , e_input ) ;
}
else {
e_input . valor =f_tcalGenerateDate ( d_date , A_TCALCONF . format ) ;
f_tcalCancel ( ) ;
}
}
función f_tcalOnClick ( ) {
// ver si ya se ha abierto
var s_pfx = A_TCALCONF . cssprefix ;
var s_activeClass = s_pfx + ' Activo ' ;
var b_close = f_tcalHasClass ( this , s_activeClass ) ;
var s_char , s_regexp = ' ^ ' , a_tokens = { } , a_options , n_token = 0 ;
for ( var n = 0 ; n < s_format . length ; n ++ ) {
s_char = s_format . charAt ( n ) ;
if ( A_TCALTOKENS_IDX [ s_char ] ) {
a_tokens [ s_char ] = ++ n_token ;
s_regexp + = ' ( ' + A_TCALTOKENS_IDX [ s_char ] [ ' r ' ] + ' ) ' ;
}
else if ( s_char == ' ' )
s_regexp + = ' \\ s ' ; else
s_regexp + = ( s_char . m atch (
/ [ \ w \ d ] / ) ? ' ' : ' \\ ' ) + s_char ;
}
var r_date = new RegExp ( s_regexp + ' $ ' ) ;
if ( ! s_date . match ( r_date ) ) return ;
devolver d_date ;
}
if ( b_active && f_tcalHasClass ( e_input , A_TCALCONF . cssprefix + ' Active
' ) )
devuelve e_input ;
función f_tcalInit ( ) {
ventana . A_TCALTOKENS_IDX = { } ;
for ( n = 0 ; n < A_TCALTOKENS . length ; n ++ )
A_TCALTOKENS_IDX [ A_TCALTOKENS [ n ] [ ' t ' ] ] = A_TCALTOKENS [ n
] ;
}
Fuente:
http://www.ajaxshake.com/es/JS/237901/selector-de-fechas-javascript-no-intrusivo-que-utiliz
a-mootools-mootools-datepicker.html
4º Script
Este Script es una validación de un formulario estándar de sugerencias y contactos, la cual
se asegura que no puedas poner mal es correo, que ningún campo este vació ni con
demasiados caracteres.
Codigo:
ventana . onload = function ( ) {
if ( campo . value . length > = cantidad && evento . charCode ! = 0 ) {
alerta ( " La observación no puede ser superior a 150 caracteres " ) ;
volver falsa ;
}
else {
devolver verdadero ;
}
función validacion ( ) {
if ( valornombre == null || valornombre . length == 0 || / ^ \ s + $ / . test ( valornombre
) ) {
error = verdadero ;
}
alerta ( " Formato inv lido de tel .fono. Ha de constar netamente de nueve n meros
" ) ;
error = verdadero ;
}
volver falsa ;
}
else {
devolver verdadero ;
}
AJAX
El Ajax te pasa un txt el cual tendremos la oferta de la semana. Es una forma de dar a
conocer nuevos productos o de deshacerse rápido de alimentos antes de su fecha de
caducidad.
Codigo:
< script type = " text / javascript " >
var XMLHttpRequestObject = false ;
1º Libre
El Jquery es un enlace el cual al clicar te descargas una tabla de alérgenos del producto por
$_axjax. Su función principal es dar un toque de profesionalidad y seguridad a todos los que
visualice los productos.
Codigo:
< script >
$ ( función ( ) {
función downloadLink ( id ) {
var res = $ . ajax ( ajaxOptions ) ;
var ajaxOptions = {
url : ' http://httpbin.org/status/ ' + id
} ;
res
. hecho (en AjaxDone )
. fallar (en AjaxFail )
;
}
Fuente: https://es.stackoverflow.com/questions/46951/descargar-un-archivo-con-javascript
2ºEfecto
El efecto es una transición para podes descargar la tabla de alérgenos, la cual está como
escondida detrás con un link.
Codigo:
< script >
$ ( ' # card-grid ' ) . flip ( { trigger : ' hover ' } ) ;
< / script >
< style >
. foto {
ancho : 400px ; altura : 300px ;
}
< / style >
< style >
. contenedor1 {
altura : 400px ;
}
< / style >
Fuente: https://www.youtube.com/watch?v=TYcDrgwHqWc
3ºWidget
El Widget es un ordenador para la forma de entrega de los pedidos.
Codigo:
< style >
#sortable { list - style - type : none ; margen : 0 auto ; relleno : 0 ; ancho : 60 % ; }
Li #sortable { margen : 0 3px 3px 3px ; relleno : 0. 4em ; relleno - izquierda : 1. 5em ;
fuente - tamaño : 1.4em ; }
#sortable li span { margin - left : - 1. 3em ; }
< / style >
$ ( function ( ) {
$ ( " #sortable " ) . sortable ( ) ;
$ ( " #sortable " ) . disableSelection ( ) ;
} ) ;
< / script >
Fuente: https://jqueryui.com/sortable/