2016-05-08 16:31:58 +00:00
function inputPhoneMatrice ( a ) { this . container = a } inputPhoneMatrice . prototype = { container : this . container } ;
2016-05-24 09:51:46 +00:00
inputPhoneMatrice . prototype . fieldsToStorage = function ( ) { console . log ( "MATRICE: FIELDS TO STORAGE" ) ; var a = ( new FormDeflater ( this . container , [ "input" ] , [ "data-name" ] ) ) . deflate ( ) ; crc32 ( JSON . stringify ( a ) ) ; var d = { } , b ; for ( b in a ) if ( a [ b ] instanceof Array ) for ( var g in a [ b ] ) null == d [ b ] && ( d [ b ] = [ ] ) , d [ b ] . push ( parseInt ( a [ b ] [ g ] ) ) ; else null !== a [ b ] && ( null == d [ b ] && ( d [ b ] = [ ] ) , d [ b ] . push ( parseInt ( a [ b ] ) ) ) ; lsi . set ( "p_matrice" , 0 , d ) } ;
inputPhoneMatrice . prototype . storageToFields = function ( ) { console . log ( "MATRICE: STORAGE TO FIELDS" ) ; var a = lsi [ "export" ] ( "p_fiches" ) , d = lsi . get ( "p_matrice" , 0 ) , b = lsi [ "export" ] ( "p_contacts" ) , g = [ ] , f ; for ( f in a ) - 1 == g . indexOf ( a [ f ] . contact ) && g . push ( a [ f ] . contact ) ; a = "<table class='line'>" ; for ( f = 0 ; f < g . length ; f ++ ) { var e = b [ f ] , a = a + "<tr>" ; 0 < f ? ( a += '<td style="text-align: right;">' , a += e . username , a += "</td>" ) : a += "<td></td>" ; for ( var c = 0 ; c < g . length ; c ++ ) if ( c < g . length - 1 ) { var h = b [ c ] ; 0 == f ? ( a += "<td>" , a += '<span style="writing-mode: vertical-lr; text-align: right;">' ,
2016-05-27 14:32:26 +00:00
a += h . username , a += "</span>" ) : c < f ? ( a += "<td>" , a += "<input type='checkbox' name='matrice_" + e . uid + "_" + h . uid + "' data-name='" + e . uid + "' value='" + h . uid + "' id='p_matrice_" + e . uid + "_" + h . uid + "'" , null != d [ f ] && - 1 < d [ f ] . indexOf ( c ) && ( a += " checked" ) , a += " >" , a += "<label for='p_matrice_" + e . uid + "_" + h . uid + "'></label>" ) : a += "<td class='hidden'>" ; a += "</td>" } a += "</tr>" } this . container . innerHTML = a + "</table>" } ;
2016-05-24 09:51:46 +00:00
inputPhoneMatrice . prototype . attach = function ( ) { console . log ( "MATRICE: ATTACH" ) ; lsi . createDataset ( "p_matrice" ) ; this . storageToFields ( ) ; var a = this ; this . container . addEventListener ( "click" , function ( d ) { a . fieldsToStorage ( ) ; a . storageToFields ( ) } , ! 1 ) } ; inputPhoneMatrice . prototype . parseGrid = function ( ) { var a = $$ ( ".matrice-panel input[data-name][value]" ) , d ; for ( d in a ) if ( a [ d ] instanceof Element ) { var b = a [ d ] . getData ( "name" ) , g = a [ d ] . value ; this . sGrid [ b ] instanceof Array || ( this . sGrid [ b ] = [ ] ) ; this . sGrid [ b ] [ g ] = a [ d ] } } ;
inputPhoneMatrice . prototype . snake = function ( ) { this . sVelocity = [ 0 , 0 ] ; this . sLength = 2 ; this . sStack = [ ] ; this . sKeys = [ ] ; this . sGrid = [ ] ; this . sRoutine = this . sTarget = null ; var a = this ; this . parseGrid ( ) ; var d = parseInt ( this . sGrid . length / 2 ) , b = parseInt ( this . sGrid [ d ] . length / 2 ) ; this . sStack . push ( this . sGrid [ d ] [ b ] ) ; for ( var d = ! 1 , g , f ; ! d ; ) g = Math . floor ( Math . random ( ) * this . sGrid . length ) , f = Math . floor ( Math . random ( ) * this . sGrid [ g ] . length ) , d = ( d = null != this . sGrid [ g ] && null != this . sGrid [ g ] [ f ] ) && - 1 == this . sStack . indexOf ( this . sGrid [ g ] [ f ] ) ; this . sTarget =
this . sGrid [ g ] [ f ] ; document . body . addEventListener ( "keydown" , function ( e ) { - 1 < [ 37 , 38 , 39 , 40 ] . indexOf ( e . keyCode ) && - 1 == a . sKeys . indexOf ( e . keyCode ) && a . sKeys . push ( e . keyCode ) } , ! 1 ) ; document . body . addEventListener ( "keyup" , function ( e ) { var c = a . sKeys . indexOf ( e . keyCode ) ; - 1 < [ 37 , 38 , 39 , 40 ] . indexOf ( e . keyCode ) && - 1 < c && a . sKeys . splice ( c ) } , ! 1 ) ; this . sRoutine = setInterval ( function ( ) { - 1 < a . sKeys . indexOf ( 37 ) ? a . sVelocity [ 0 ] = - 1 : - 1 < a . sKeys . indexOf ( 39 ) && ( a . sVelocity [ 0 ] = 1 ) ; - 1 < a . sKeys . indexOf ( 38 ) ? a . sVelocity [ 1 ] = - 1 : - 1 < a . sKeys . indexOf ( 40 ) ?
a . sVelocity [ 1 ] = 1 : 0 != a . sVelocity [ 0 ] && ( a . sVelocity [ 1 ] = 0 ) ; - 2 == a . sKeys . indexOf ( 37 ) + a . sKeys . indexOf ( 39 ) && 0 != a . sVelocity [ 1 ] && ( a . sVelocity [ 0 ] = 0 ) ; var e = a . sStack [ a . sStack . length - 1 ] , c = parseInt ( e . getData ( "name" ) ) , e = parseInt ( e . value ) , e = ( e + a . sVelocity [ 0 ] ) % a . sGrid [ c ] . length ; 0 > e && ( e = a . sGrid [ c ] . length - 1 ) ; c = ( c + a . sVelocity [ 1 ] ) % a . sGrid . length ; 0 >= c && ( c = e + 1 ) ; if ( null == a . sGrid [ c ] || null == a . sGrid [ c ] [ e ] ) c = a . sGrid . length - 1 ; if ( null != a . sGrid [ c ] && null != a . sGrid [ c ] [ e ] ) { if ( a . sGrid [ c ] [ e ] . checked ) if ( a . sGrid [ c ] [ e ] . id == a . sTarget . id ) { a . sLength ++ ;
for ( var d = ! 1 , b , f ; ! d ; ) b = Math . floor ( Math . random ( ) * a . sGrid . length ) , f = Math . floor ( Math . random ( ) * a . sGrid [ b ] . length ) , d = ( d = null != a . sGrid [ b ] && null != a . sGrid [ b ] [ f ] ) && - 1 == a . sStack . indexOf ( a . sGrid [ b ] [ f ] ) ; a . sTarget = a . sGrid [ b ] [ f ] } else a . sStack [ a . sStack . length - 1 ] . id != a . sGrid [ c ] [ e ] . id && ( console . log ( a . sStack [ a . sStack . length - 1 ] . id , a . sGrid [ c ] [ e ] . id ) , alert ( "vous avez perdu! Score: " + ( a . sLength - 2 ) ) , clearInterval ( a . sRoutine ) ) ; a . sStack . push ( a . sGrid [ c ] [ e ] ) } var c = [ ] , g ; for ( g in a . sStack ) b = a . sStack [ g ] . getData ( "name" ) , f = a . sStack [ g ] . value ,
null == c [ b ] && ( c [ b ] = [ ] ) , c [ b ] . push ( parseInt ( f ) ) ; null != a . sTarget && ( b = a . sTarget . getData ( "name" ) , f = a . sTarget . value , null == c [ b ] && ( c [ b ] = [ ] ) , c [ b ] . push ( parseInt ( f ) ) ) ; lsi . set ( "p_matrice" , 0 , c ) ; a . storageToFields ( ) ; a . parseGrid ( ) ; g = a . sStack . length ; g >= a . sLength && ( a . sStack = a . sStack . slice ( 1 + g - a . sLength ) ) ; document . location = "#snake" } , 200 ) } ;