function isMobile() { if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(window.navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(window.navigator.userAgent.substr(0,4))) return true; else return false; } var sez = 'home'; var act = 'view'; var lang = 'en'; var arr_voci = ["home", "coll", "user", "stats", "auction", "users"]; var isBlockerLoad = 0; var isBlockerMsg = isBlockerPopup = 0; var isShowRarity = 0; var isShowPreview = 0; var isHideUsers = 1; var isHideMobileUsers = 1; var isHideMobileTotals = 1; var isHideHomeDetails = {user:[], global:[]}; var arrSelectedRowFigure = []; var fastload = ''; var currentT = currentF = 0; var currentBgFigure = currentBorderColorFigure = ''; var currentNumColors = 0; var currentLayout = "grid"; var onMobile = isMobile(); var ms = (navigator.userAgent.match(/SAMSUNG|SGH-[I|N|T]|GT-[I|P|N]|SM-[N|P|T|Z|G]|SHV-E|SCH-[I|J|R|S]|SPH-L/i))?250:0; var elMain = null; var elBody = null; var elMenuSx = null; var elMenuDx = null; var touchXstart = 0 var touchXend = 0 var touchXminimum = 50; var elDisplay = {"blockermsg":'', "blockerpopup":'', "blockerfloor":'', "modal-chart":'', "menusx":'', "menudx":''}; var elRoot = document.querySelector(':root'); var elRootStyle = getComputedStyle(elRoot); var overallCollection = {}; var homeColors = {user:{}, global:{}}; var customUserValues = { evaluateMe: function(what, val){ return (!isNaN(val) ? val : this[what][val])*1 }, cwf: { variable: 'w_tdfigures', default: parseInt(elRootStyle.getPropertyValue( (onMobile ? '--m_w_tdfigures_default' : '--w_tdfigures_default') )), current: function(){ return this.evaluateMe('cwf', "default") }, max: (onMobile ? 260 : 300), min: (onMobile ? 100 : 120), step: 20 }, twf: { variable: 't_tdfigures', default: parseInt(elRootStyle.getPropertyValue( (onMobile ? '--m_t_tdfigures_default' : '--t_tdfigures_default') )), current: function(){ return this.evaluateMe('twf', "default") }, max: (onMobile ? 120 : 220), min: (onMobile ? 60 : 60), step: 10 } }; var arrLayouts = {}; $(document).ready(function(){ //main elMain = document.getElementById('tblmain'); elMenuSx = document.getElementById('menusx'); elMenuDx = document.getElementById('menudx'); elBody = document.body; if(onMobile) { loadSwipeLogic(); window.addEventListener("resize", manageOrientation); window.addEventListener("pageshow", manageOrientation); manageOrientation(); elBody.style.webkitTouchCallout = 'none'; elBody.style.webkitUserSelect = 'none'; elBody.style.khtmlUserSelect = 'none'; elBody.style.mozUserSelect = 'none'; elBody.style.msUserSelect = 'none'; elBody.style.userSelect = 'none'; elBody.style.webkitTapHighlightColor = 'rgba(0,0,0,0)'; elBody.style.outline = 0; $("#mobile_tbl_totals").click(function() { hideShowMobileTotals("#mobile_tbl_totals_div") }); $("#mobile_tbl_user_list").click(function() { hideShowMobileUsers("#mobile_tbl_user_list_div") }); } else { window.addEventListener("resize", updateFixedTableColorsPosition); } //logo $("#logo").click(function() { goto("home"); }); //users $("input[name=usernamechoice]").on('change', function() { changeNamesUserList($('input[name=usernamechoice]:checked').val()); fixPosFixedTableColors(); }); //msg close $(".closemsg").click(function() { hideBlockerMsg(); }); //popup close $(".closepopup").click(function() { hideBlockerPopup(); }); //login $("#submitlog").click(function(){ callAjax("POST", "checkLogin.php", {l:$("#username").val(), p:$("#password").val()}); //preventDefault(); }); $("#submitlog2").click(function(){ callAjax("POST", "checkLogin.php", {l:$("#username").val(), p:$("#password").val(), d:$("#device").val(), auto:$("#automatic_login").is(":checked")}); //preventDefault(); }); //register $("#submitreghome").click(function(){ callAjax("POST", "checkRegister.php", {l:$("#txtloginreg").val(), e:$("#txtemailreg").val(), p:$("#txtpwdreg").val(), p2:$("#txtpwdreg2").val(), fbn:$("#txtfbnamereg").val(), c:$("#txtcaptcha").val(), a:$("#txtanswerreg").val(), x:$("#strcheck").val()}); }); //update $("#submitmodhome").click(function(){ callAjax("POST", "checkUpdate.php", {l:$("#txtloginmod").val(), e:$("#txtemailmod").val(), fbn:$("#txtfbnamemod").val(), op:$("#txtpwdoldmod").val(), p:$("#txtpwdmod").val(), p2:$("#txtpwdmod2").val(), idu:$("#idu").val()}); }); //hover menu voci //$("[class^=mn_]").click(function() { resetBgVoci(this); }); $("#mn_id_home").click(function() { goto("home") }); $("#mn_id_coll").click(function() { goto("collection&act=manage") }); //$("#mn_id_coll").click(function() { goto("collection&act=manage&idt=0&idf=0") }); $("#mn_id_account").click(function() { goto("account") }); $("#mn_id_prefs").click(function() { goto("prefs") }); $("#mn_id_stats").click(function() { goto("stats&act=sums") }); //$("#mn_id_stats").click(function() { goto("stats&act=sums&idt=0&idf=0") }); $("#mn_id_auction").click(function() { goto("auction") }); $("#mn_id_users").click(function() { hideShowUsers(this); fixPosFixedTableColors(); /*resetBgVoci(this);*/ }); //home color details faction $(".homedetails_user").click(function() { hideShowHomeColorDetails('user', this); }); $(".homedetails_global").click(function() { hideShowHomeColorDetails('global', this); }); $(".truser").click(function() { gotoUserColl(this) }); //$(".truser").hover(function() { $(".user").addClass('truserhover'); }, function() { $(this).removeClass('trueserhover'); }); if(fastload!="") doFastLoad(fastload); }); function overallSet(idf, overall) { overallCollection[idf] = {tot:overall[0], coll:overall[1]}; } function userValueSet(what, val, overwrite) { val = (!isNaN(val)) ? val : customUserValues.evaluateMe(what, val); let variableName = customUserValues[what].variable; if(!isNaN(val)) { elRoot.style.setProperty( (onMobile ? '--m_'+variableName : '--'+variableName), val+"px" ); customUserValues[what].current = val; } else { elRoot.style.setProperty( (onMobile ? '--m_'+variableName : '--'+variableName), window[val]+"px" ); customUserValues[what].current = window[val]; } updateFixedTableColorsPosition(); //console.log(what+' : '+val+' : '+variableName); } function userValuePlus(what, toy, fac) { customUserValues[what].current*= 1; //console.log((customUserValues[what].current+customUserValues[what].step), customUserValues[what].max); if((customUserValues[what].current+customUserValues[what].step)<=customUserValues[what].max) { elRoot.style.setProperty( (onMobile ? '--m_'+customUserValues[what].variable : '--'+customUserValues[what].variable), (customUserValues[what].current+customUserValues[what].step)+'px' ); customUserValues[what].current = customUserValues[what].current+customUserValues[what].step; document.getElementById(what+"_usr_value_text").innerHTML = customUserValues[what].current+"px"; console.log('set: '+'--m_'+customUserValues[what].variable+' to: '+(customUserValues[what].current+customUserValues[what].step)); userValueSet(what, customUserValues[what].current, true); //updateFixedTableColorsPosition(); callAjax("POST", "saveSettings.php", {"action":"uservalue", namevalue:what, value:customUserValues[what].current, "mobile":onMobile, "idt":toy, "idf":fac, "idu":0}); } } function userValueMinus(what, toy, fac) { customUserValues[what].current*= 1; //console.log((customUserValues[what].current+customUserValues[what].step), customUserValues[what].max); if((customUserValues[what].current-customUserValues[what].step)>=customUserValues[what].min) { elRoot.style.setProperty( (onMobile ? '--m_'+customUserValues[what].variable : '--'+customUserValues[what].variable), (customUserValues[what].current-customUserValues[what].step)+'px' ); customUserValues[what].current = customUserValues[what].current-customUserValues[what].step; document.getElementById(what+"_usr_value_text").innerHTML = customUserValues[what].current+"px"; userValueSet(what, customUserValues[what].current, true); //updateFixedTableColorsPosition(); callAjax("POST", "saveSettings.php", {"action":"uservalue", namevalue:what, value:customUserValues[what].current, "mobile":onMobile, "idt":toy, "idf":fac, "idu":0}); } } function hideShowUsers(el) { if(isHideUsers) { $("#divusers").slideDown('fast'); isHideUsers = 0; $(el).addClass('mn_id_users_clicked'); } else { $("#divusers").slideUp('fast'); isHideUsers = 1; $(el).removeClass('mn_id_users_clicked'); } } function hideShowHomeColorDetails(who, el) { let idt = $(el).attr("idt"); let idf = $(el).attr("idf"); let tfname = $(el).attr("tfname"); if(isHideHomeDetails[who][idf]==undefined) { $("#divhomedetails_"+who+"_"+idf).slideDown('fast'); isHideHomeDetails[who][idf] = 1; $(el).attr("src", "_img/icon_color_close.png"); if(homeColors[who][idf]==undefined) { callAjax("GET", "loadHomeColors.php", {"action":who+"colors", idt:idt, idf:idf, who:who, tfname:tfname, "mobile":onMobile, "idu":0}).then(function(){ homeColors[who][idf] = true; }); } } else { $("#divhomedetails_"+who+"_"+idf).slideUp('fast'); delete isHideHomeDetails[who][idf]; $(el).attr("src", "_img/icon_color_open.png"); } } function loadHomeUserColors(who, idf, out) { window.setTimeout(function(){ $("#divhomedetails_"+who+"_"+idf).css({"background":"none"}); $("#divhomedetails_"+who+"_"+idf).html(out); }, 500); } function hideShowMobileUsers(label) { if(isHideMobileUsers) { $(label).slideDown('fast'); isHideMobileUsers = 0; } else { $(label).slideUp('fast'); isHideMobileUsers = 1; } } function hideShowMobileTotals(label) { if(isHideMobileTotals) { $(label).slideDown('fast'); isHideMobileTotals = 0; } else { $(label).slideUp('fast'); isHideMobileTotals = 1; } } function changeNamesUserList(val) { $(".truser").each(function(index) { var tempTitle = $(this).attr("title"); var tempHtml = $(this).children(".user").html(); //alert(tempTitle+tempHtml); $(this).attr("title", tempHtml); $(this).children(".user").html(tempTitle); }); } function gotoUserColl(el) { //alert("carico "+$(el).attr("id")); //var myhref = 'collection&fastload=view|'+$(el).attr("id")+'|0|0'; var myhref = 'collection&act=view&idu='+$(el).attr("id")+'&idt=0&idf=0'; goto(myhref); } function loadFirstFaction(idf) { //console.log('============= '+idf); //css selected checkFactionsVoice($('#idf_'+idf)); //load figures loadFigures($('#idf_'+idf), "", 0); if(!onMobile) { checkFactionsVoice($('#drop_idf_'+idf)); } } function loadFactions(el, userClick=false) { if(userClick && currentT==$(el).attr("idt")) return; //alert($(el).attr("idu")+" - "+$(el).attr("sez")+" - "+$(el).attr("act")+" - "+$(el).attr("idt")+" - "+lang) showBlockerLoad(); callAjax("GET", "loadFactions.php", {idu:$(el).attr("idu"), sez:$(el).attr("sez"), act:$(el).attr("act"), idt:$(el).attr("idt"), relff:$(el).attr("relff"), lang:lang}); //tolgo tutto resetToylinesVoices(); checkToylinesVoice('#idt_'+$(el).attr("idt")); if(!onMobile) { checkToylinesVoice('#drop_idt_'+$(el).attr("idt")); } } function loadFigures(el, callback, preload, userClick=false) { if(userClick && currentF==$(el).attr("idf")) return; //alert("carico "+$(el).attr("idt")); var sez = $(el).attr("sez"); var act = $(el).attr("act"); if(preload) showBlockerLoad(); let mobilePrefix = onMobile ? "m_" : ""; let idt = $(el).attr("idt"); let idf = $(el).attr("idf"); //overwrite the noimage preview noImageToylinesDefault = arrNoImageToylineFactions[idf]; //noImageToylinesDefault = arrNoImageToylines[idt]; if(sez=="collection") switch(act) { case "manage": callAjax("GET", mobilePrefix+"collectionManage.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; case "view": callAjax("GET", mobilePrefix+"collectionView.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; } else if(sez=="stats") switch(act) { case "sums": callAjax("GET", mobilePrefix+"collectionSums.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; case "compare": callAjax("GET", "collectionCompare.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), iduc1:0, iduc2:0, lang:lang}); break; //case "colors": callAjax("GET", "collectionSums.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; //case "qtas": callAjax("GET", "collectionSums.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; //case "commons": callAjax("GET", "collectionSums.php", {idu:$(el).attr("idu"), sez:sez, act:act, idf:$(el).attr("idf"), lang:lang}); break; } //tolgo tutto resetFactionsVoices(); checkFactionsVoice('#idf_'+$(el).attr("idf")); if(!onMobile) { checkFactionsVoice($('#drop_idf_'+$(el).attr("idf"))); } updateCurrentToyFac($(el).attr("idt"), $(el).attr("idf")); if (typeof callback === "function") callback(); } function updateCurrentToyFac(t, f) { //alert(t+" - "+f); currentT = t; currentF = f; } function addVal(el, strinputval, oldval, val) { //console.log("strinputval:"+strinputval+", oldqta: "+oldval+", qta: "+val); let strtok; let positiveNum = false; if(val!=oldval) { if( ($.isNumeric(val) && (val.toString().indexOf('.')!=1)) || val=="") { callAjax("GET", "saveQtaUpdate.php", {strinputval:strinputval, idel:$(el).attr("id"), oldval:oldval, val:val}); positiveNum = !isNaN(val) && val>0 ? true : false; } else { callError("Warning, please input a numerical value greater than zero.") emptyQtaVal(el, 1); positiveNum = false; } if(currentLayout=="tiles") { strtok = strinputval.split("_"); if(positiveNum) document.querySelector("#td_figure_"+strtok[2]+"_"+strtok[1]+" a").setAttribute("style", ""); else document.querySelector("#td_figure_"+strtok[2]+"_"+strtok[1]+" a").setAttribute("style", "color:var(--figure_missing);"); } } } function addListenerGeneralOptions() { $("#opt_visibility").click(function() { toggleStat = parseInt($('input#series_visibility').val())==0 ? 1 : 0; callAjax("POST", "saveSettings.php", {action:'visibility', value:toggleStat, mobile:onMobile, idf:$("#opt_visibility").attr("idf"), idu:0}).then(function(data) { //console.log(data); $('input#series_visibility').val(data.return.visibility); $("#opt_visibility").attr("src", "_img/"+(data.return.visibility==1 ? "icon_private.png" : "icon_public.png")); }); }); $("#opt_contributions").click(function() { callAjax("GET", "popupLoadContributions.php", {idf:$("#opt_contributions").attr("idf"), lang:lang}); }); } function emptyQtaVal(el, focus) { $(el).val(""); if(focus) setTimeout(function() { $(el).focus(); }, 0); } function callAjax(how, where, what) { //alert(how+" - "+where+" - "+JSON.stringify(what)); return new Promise(function(resolve, reject) { $.ajax({ type: how, url: where, data: what, dataType: "json", processdata: true, success: function(json) { if(json) { manageAjaxResponse(json).then(function(){ resolve(json); //console.log("DONE"); }); } }, error: function(json, status, error) { //return json; callError(json.message); //console.log("err-> "+error); //alert("status-> "+status); resolve(); } }); }); } function manageAjaxResponse(json) { return new Promise(function(resolve, reject) { if(json.response==false) { if(json.message!="") callError(json.message); if(json.return.reason && json.return.reason=="wrong_captcha") refreshCaptcha(); resolve(); } else { if(json.message!="") callMessage(json.message); switch(json.action) { //--------------------- case "saveQtaUserColl": updateTotalsFigures(json.return.idel, json.return.idelvalue, json.return.strinputval, currentT, currentF); updateInputQtaValue(json.return.idel, json.return.idelvalue, json.return.strinputval, json.return.empty); break; //--------------------- case "loadFacUserColl": $("#span_factions").html(json.out); if(!onMobile) $("#dropdown_factions").html(json.return.dropdown); else $("#jsnofigures").html(json.return.jsnofigure); addListenerFactionsVoices(); ///////////////////////////////////////////////// if(sez=="collection") { $("#divfigures").html(""); switch(act) { case "manage": loadFirstFaction(json.return.relff); break; case "view": loadFirstFaction(json.return.relff); break; } } else if(sez=="stats") { $("#divstats").html(""); loadFirstFaction(json.return.relff); } //hide blocker - NOPE, it'll hide by loadFigures //hideBlockerLoad(); break; //--------------------- case "loadUserColl": $("#divfigures").html(json.out); if(onMobile) fillMenuDxOptions(json.return.menudx); dragColumnTotalColors(json.return.layout, json.return.idf, json.return.idu, json.return.jsoncolors); formatQtaRows(json.return.layout, json.return.act, currentT, currentF); formatTableTotalColors(); formatFixedTableColors(); formatCustomColorsQta(json.return.act); onBlurQtaCells(); onChangeOrderGroup(); addListenerQtaScroll(); addListenerUserMenu(act); addListenerTrFigures(json.return.layout, json.return.act, currentT, currentF); addListenerLayoutButton(); addListenerTtip(); addListenerDetailsMf(); addListenerTableDivider(); addListenerGeneralOptions(); //set user values (cwf, twf) for(var u=0; u= colorsBarPos) $("#scrollfixedcolors").css({'top':'0px'}); else $("#scrollfixedcolors").css({'top':'-500px'}); }); } } } function dragColumnTotalColors(layout, idf, idu, ordercolors) { if(layout=="tiles") return; //console.log(ordercolors); //var table = $('#tblcolororiginal'); $('#tblcolororiginal').dragtable({ persistState: function(table) { table.el.find('th').each(function(i){ if(this.id != '') {table.sortOrder[this.id]=i;} //alert(this.clone()); }); //alert("--> "+table.sortOrder); callAjax("GET", "saveColorsOrder.php", {idu:idu, idf:idf, order:JSON.stringify(table.sortOrder)}) //alert($('#tblcolororiginal tbody')); cloneThColors(Object.keys(ordercolors).length); }, maxMovingRows:1, restoreState: ordercolors }); cloneThColors(Object.keys(ordercolors).length); } function fillMenuDxOptions(data) { //alert(data); $('#divoptions').empty(); $('#divoptions').append(data); } function cloneThColors(i) { //remove previous $('#tblcolorfixed tr').remove(); //tbl fixed colors var tblfixedcolor = $('#tblcolorfixed'); //row with colors var thcolors = $('#tblcolororiginal tr:first').clone(); tblfixedcolor.append(thcolors); //row to mantain the correct th width var dummytdqtas = ''; if(onMobile) { for(var r=0; r 160) { textColor = lightenHex(objColor[4], -15); textShadow = 'none'; } else { textColor = lightenHex("#ffffff", -15); textShadow = '1px 1px 0px #000000'; } //console.log(objColor[0]+' '+groupColor+' bright: '+brightness); //label group $("[id^=tilelabelgroup_"+r+"_0]").css({"color":textColor, "background-color":groupColor, "text-shadow":textShadow}); //$("[id^=tilelabelgroup_"+r+"_0]").css({"color":lightenHex(objColor[4], -15), "background-color":lightenHex(objColor[2], 50)}); //singletile $("[id^=tiles_color_"+r+"]").css({"color":objColor[4], "background-color":objColor[5]}); //color $("[id^=tdheadercolor_"+r+"]").css({"text-shadow":colorShadow}); $("[id^=tdsumcolor_"+r+"]").css({"text-shadow":colorShadow}); } } function lightenHex(hex, pct) { //console.log(arguments); const h = hex.replace(/^#/, ''); const r = parseInt(h.slice(0,2),16); const g = parseInt(h.slice(2,4),16); const b = parseInt(h.slice(4,6),16); const p = Math.max(-100, Math.min(100, pct)) / 100; const mix = (c) => Math.round(c + (255 - c) * p); const toHex = n => n.toString(16).padStart(2,'0'); return '#' + toHex(mix(r)) + toHex(mix(g)) + toHex(mix(b)); } function hexToRgb(hex) { hex = hex.replace('#',''); if(hex.length === 3) hex = hex.split('').map(c=>c+c).join(''); const int = parseInt(hex,16); return { r: (int>>16)&255, g: (int>>8)&255, b: int&255 }; } function perceivedBrightness(r,g,b) { return Math.sqrt(0.299 * r*r + 0.587 * g*g + 0.114 * b*b); } function formatQtaRows(layout, actpage, idtoy, idfac) { //alert("fac_"+idtoy+"_"+idfac); if(arrToylineColors["fac_"+idtoy+"_"+idfac]!=undefined) { for(var i=0; i tbody > tr > .tdqta').each(async function(index) { //let arrTip = $(this).attr('tip').split("|"); removeThumbImageQtaFigures(this, index); }); isShowPreview = 0; manageAjaxResponse({"response":true, "message":"", "action":"loadUserCollFake", "return":{"idf":fac, "layout":myswitch}}); } else if(myswitch=="graph") { const tdFigs = document.querySelectorAll(".tdfigures"); tdFigs.forEach(function(item) { item.style.height = "92px"; }); $('.singletblcolor > tbody > tr > .tdqta').each(async function(index) { let arrTip = $(this).attr('tip').split("|"); await injectThumbImageQtaFigures(this, fac, arrTip, index); }); isShowPreview = 1; manageAjaxResponse({"response":true, "message":"", "action":"loadUserCollFake", "return":{"idf":fac, "layout":myswitch}}); } if(saveMe) { callAjax("POST", "saveSettings.php", {action:'layout', layout:myswitch, mobile:onMobile, idf:fac, idu:0}); } } function injectThumbImageQtaFigures(el, fac, arrTip, index) { return new Promise(function(resolve) { let name = arrTip[0]; let color = arrTip[1]; let path = null; let src = null; let noFigure = null; //console.log(el); let divImg = document.createElement('div'); let img = document.createElement('img'); divImg.id = "div_prev_figure_"+index; divImg.style.margin = "8px auto"; divImg.style.width = "48px"; divImg.style.height = "48px"; if(arrTip[3]=="") { src = noImageToylinesDefault; //src = "_img/nofigure.png"; img.src = src; img.style.boxShadow = 'none'; img.style.opacity = 0.5; noFigure = true; path = src; } else { src = "doThumb.php?what=sculpt&fac="+fac+"&src="+arrTip[3]+"&maxx=48&maxy=48&crop=squarew"; img.src = src; img.style.boxShadow = '#b0b0b0 0 0px 1px 1px'; noFigure = false; path = "doResize.php?what=sculpt&src="+arrTip[3]+"&maxx=500&maxy=500"; } img.style.width = "100%"; img.style.borderRadius = "2px"; divImg.appendChild(img); //hide the tip icon let iconPrev = el.querySelector('[id^="iconprev_'); if(iconPrev) iconPrev.style.display = "none"; //disable the percentage height of the input let inputQta = el.querySelector('.inputqta'); if(inputQta) { if(inputQta.value=="") inputQta.placeholder="0"; color = color=="_DEFAULT_" ? "" : "("+color+")"; if(onMobile) { inputQta.style.height = "26px"; img.addEventListener("click", function(){ showImage(path, 0, 85, ""+name+"
"+color+"") }); } else { inputQta.style.height = "26px"; img.addEventListener("click", function(){ showImage(path, 600, 0, ""+name+"
"+color+"") }); } } else { //figure not exists img.src = "_img/spacer.png"; divImg.style.height = "76px"; img.style.boxShadow = 'none'; } //add the image el.insertBefore(divImg, el.firstChild); }); } function removeThumbImageQtaFigures(el, index) { let toRemove = document.getElementById("div_prev_figure_"+index); if(toRemove) { //remove the image el.removeChild(toRemove); //enable the percentage height of the input let inputQta = el.querySelector('.inputqta'); if(inputQta) { inputQta.style.height = "80%"; inputQta.removeAttribute("placeholder"); } //show the tip icon let iconPrev = el.querySelector('[id^="iconprev_'); if(iconPrev) iconPrev.style.display = "block"; } } //change all the qtabgcolor in stats function changeBgColorsQtaStatsFigures(myswitch) { showBlockerLoad(); if(myswitch==1) { /* //for(var i=0; i tbody > tr > .tdqta').each(function(index) { var myqta = (+($(this).find('span:first').text())>0)?+($(this).find('span:first').text()):0; //alert(myqta); for(var o=0; o maj && myqta < min ) { //alert("QTA: "+myqta+", MAJ:"+maj+", MIN:"+min) $(this).css({"background-color":objRarityColor[o][4]}); break; } } }); isShowRarity = 1; } else { for(var i=0; i tbody > tr > td > .viewqta').each(function(index){ var myqta = (+($(this).text())>0)?+($(this).text()):0; //alert(myqta); for(var o=0; o min && myqta < maj ) { //alert("QTA: "+myqta+", MAJ:"+maj+", MIN:"+min) $(this).css({"background-color":objRarityColor[o][4]}); } } }); */ /* //for every figure for(var p=0; p<40; p++) { var myqta = (+($("[id=field_"+r+"_"+p+"]").text())>0)?+($("[id=field_"+r+"_"+p+"]").text()):0; //alert(myqta) //for every label for(var o=0; o min && myqta < maj ) { alert("QTA_"+r+"_"+p+": "+myqta+", MAJ:"+maj+", MIN:"+min) $("[id=field_"+r+"_"+p+"]").css({"background-color":objRarityColor[o][4]}); } } } */ } function formatTableRarityColors() { for(var i=0; i"+newvalue+", OLD->"+oldvalue); //user session total OK if(summed==1) $("#tot_user").html( parseInt($("#tot_user").html()) + parseInt(newvalue) - parseInt(oldvalue) ); //my faction totals OK $("#my_faction_totals_"+idt+"_"+idf).html( parseInt($("#my_faction_totals_"+idt+"_"+idf).html()) + parseInt(newvalue) - parseInt(oldvalue) ); } function updateTotalsFigures(idel, newvalue, strinput, idt, idf) { arr_str = strinput.split("_"); oldvalue = $("#"+idel).attr("oldvalue"); id_user = arr_str[0]; num_row = arr_str[1]; num_col = arr_str[2]; summed = arr_str[arr_str.length-1]; id_color = arrToylineColors["fac_"+idt+"_"+idf][num_col][6]; if(newvalue=="") newvalue = 0; if(oldvalue=="") oldvalue = 0; //alert("NEW->"+newvalue+", OLD->"+oldvalue); //FOR FIGURES ONLY, NOT PACKAGE, CARDS, ETC. if(summed==1) { //user session total in welcome OK $("#tot_user").html( parseInt($("#tot_user").html()) + parseInt(newvalue) - parseInt(oldvalue) ); //global toyline table total OK $("#spantoylinetot_"+idt).html( parseInt($("#spantoylinetot_"+idt).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //userlist total OK $("#userlistqta_"+id_user).html( parseInt($("#userlistqta_"+id_user).html()) + parseInt(newvalue) - parseInt(oldvalue) ); } //global total OK STAMPATA SOLO NELLA HOME //$("#spantoylinetotalone").html( parseInt($("#spantoylinetotalone").html()) + parseInt(newvalue) - parseInt(oldvalue) ); //my table totals OK $("#my_totals").html( parseInt($("#my_totals").html()) + parseInt(newvalue) - parseInt(oldvalue) ); //single color table total OK $("#sum_color_"+num_col).html( parseInt($("#sum_color_"+num_col).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //global single color table total OK $("#spantotcolor_"+idt+"_"+idf+"_"+id_color).html( parseInt($("#spantotcolor_"+idt+"_"+idf+"_"+id_color).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //global faction total OK $("#spanfactiontot_"+idt+"_"+idf).html( parseInt($("#spanfactiontot_"+idt+"_"+idf).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //horizontal total OK $("#sum_figure_"+num_row).html( parseInt($("#sum_figure_"+num_row).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //single color missing / my missings OK if(oldvalue==0) { $("#miss_color_"+num_col).html( parseInt($("#miss_color_"+num_col).html()) - 1 ); $("#my_missings").html( parseInt($("#my_missings").html()) - 1 ); //overall overallCollection[idf].coll = overallCollection[idf].coll + 1; } else if(newvalue==0) { $("#miss_color_"+num_col).html( parseInt($("#miss_color_"+num_col).html()) + 1 ); $("#my_missings").html( parseInt($("#my_missings").html()) + 1 ); //overall overallCollection[idf].coll = overallCollection[idf].coll - 1; } //overall $("#my_overall").html( parseInt( (100/overallCollection[idf].tot)*overallCollection[idf].coll) ); //my faction totals in loadFactions OK $("#my_faction_totals_"+idt+"_"+idf).html( parseInt($("#my_faction_totals_"+idt+"_"+idf).html()) + parseInt(newvalue) - parseInt(oldvalue) ); //mobile menudx totals if(onMobile) $("#menusx_totals_"+idt+"_"+idf).html( parseInt($("#menusx_totals_"+idt+"_"+idf).html()) + parseInt(newvalue) - parseInt(oldvalue) ); } function changeOrderGroup(el, idu, sez, act, idt, idf, val) { //alert("idu:"+idu+", idf:"+idf+", val: "+val); callAjax("GET", "saveOrderGroup.php", {idu:idu, sez:sez, act:act, idt:idt, idf:idf, val:val}) } function onChangeOrderGroup() { $('[name="ordergroup_switch"]').change(function() { var orderidf = $(this).attr("idf"); var orderidu = $(this).attr("idu"); var ordersez = $(this).attr("sez"); var orderact = $(this).attr("act"); var orderidt = $(this).attr("idt"); changeOrderGroup(this, orderidu, ordersez, orderact, orderidt, orderidf, $(this).val()); }); } function onBlurQtaCells() { $( ".inputqta" ).blur(function() { var strinputval = $(this).attr("inputval"); addVal(this, strinputval, $(this).attr("oldvalue"), $(this).val()); }); } function showBlockerLoad() { if(!isBlockerLoad) $("#blockerload").fadeIn(300, function(){ isBlockerLoad = 1; }); } function hideBlockerLoad() { $("#blockerload").fadeOut(300, function(){ isBlockerLoad = 0; }); } function showBlockerLoadFigures() { if(!isBlockerLoad) $("#blockerloadfigures").fadeIn(300, function(){ isBlockerLoad = 1; }); } function hideBlockerLoadFigures() { $("#blockerloadfigures").fadeOut(300, function(){ isBlockerLoad = 0; }); } function showBlockerMsg() { if(!isBlockerMsg) { //$("#blocker").fadeIn(300); $("#blockermsg").fadeIn(300, function(){ isBlockerMsg = 1; }); } } function hideBlockerMsg() { $("#blockermsg").fadeOut(300, function(){ isBlockerMsg = 0; }); //$("#blocker").fadeOut(300); hideBlockerLoad(); } function showBlockerPopup() { if(!isBlockerPopup) { //$("#blocker").fadeIn(200); $("#blockerpopup").fadeIn(200, function(){ document.getElementById('idcontentpopup').scrollTop = 0; isBlockerPopup = 1;}); } } function hideBlockerPopup() { document.getElementById('idcontentpopup').scrollTop = 0; $("#blockerpopup").fadeOut(200, function(){ isBlockerPopup = 0; document.getElementById('idcontentpopup').scrollTop = 0; }); //$("#blocker").fadeOut(200); } function callError(t) { //alert("ERR-> "+t); $("#idcontentmsg").html(t); showBlockerMsg(); } function callMessage(t) { $("#idcontentmsg").html(t); showBlockerMsg(); } function addListenerTtip() { $('td[tip]').each(function(index) { let timer; let that = $(this); //block context menu $(this).contextmenu(function(e) { if( e.button == 2 ) { $(this).trigger('click'); return false; } }); //for each preview found $(this).find('.trcorner.pointer').hover(function() { if(timer) { clearTimeout(timer); timer = null; } timer = setTimeout(function() { var arrTip = that.attr('tip').split("|"); if(arrTip.length>0) { //console.log(arrTip); //getContentTtip(arrTip[0], arrTip[1], arrTip[3]); that.miniTip({ content: getContentTtip(arrTip[0], arrTip[1], arrTip[2]), delay: 0, anchor: 'e', aHide: false, fadeIn: 100, fadeOut: 50, maxW: '300px', offset: 15, event: 'none', doShow: true, show: loadSrcTip(arrTip[2], arrTip[3]) }); } }, 300); }, //out function() { that.miniTip({doHide:true}); if(timer) { clearTimeout(timer); timer = null; } }); }); /* $('td[tip]').each(function(index) { $(this).contextmenu(function(e) { if( e.button == 2 ) { var arrTip = $(this).attr('tip').split("|"); if(arrTip.length>0) { $(this).miniTip({ content: getContentTtip(arrTip[0], arrTip[1], arrTip[2]), delay: 500, anchor: 'e', aHide: false, maxW: '300px', maxH: '300px', offset: 15, event: 'click' }); $(this).trigger('click'); return false; } } }); }); */ } function getContentTtip(f, c, i) { //alert(arguments); c = c=="_DEFAULT_" ? "" : c; return '
'+f+'
'+c+'
'; } function loadSrcTip(what, src) { try { setTimeout(function() { let tipImg = document.querySelector('#miniTip_t_content img'); let srcImg = "doResize.php?what="+what+"&src="+src+"&maxx=250&maxy=250&crop=squarew"; tipImg.src = srcImg; }, 200); } catch(err) {console.log(err);} } function showCookieDisclaimer(el) { //console.log(el.checked); if(el.checked) { callMessage('By selecting this functionality, I\'m aware that cookies containing anonymized data will be created to securely store my collection numbers without retaining any personally identifiable information.'); } } function addListenerToylinesVoices(){$(".radiustoy").click(function() { loadFactions(this, true) });} function addListenerFactionsVoices(){$(".radiusfac").click(function() { loadFigures(this, "", 1, true) });} function addListenerCompareButton(){$("#btcompare").click(function() { var myiduc1 = $("#userCompare1").val(); var myiduc2 = $("#userCompare2").val(); //alert(myiduc1+myiduc2); if(myiduc1==0 || myiduc2==0) callError("Please select two users."); else { goto($(this).attr('sez')+'&act=compare&idt=1&idf='+$(this).attr('idf')+'&iduc1='+myiduc1+'&iduc2='+myiduc2); } });} function addListenerRarityButton(){$("input[name=rarity_switch]").on('change', function() { changeBgColorsQtaStatsFigures($('input[name=rarity_switch]:checked').val()); });} function addListenerLayoutButton(){$("input[name=layout_switch]").on('change', function() { manageLayout($(this).attr('idf'), $('input[name=layout_switch]:checked').val(), true); });} function addListenerResetCompareButton(){$("#btresetcompare").click(function() { goto($(this).attr('sez')+'&act='+$(this).attr('act')+'&idt=1&idf='+$(this).attr('idf')); });} function resetToylinesVoices(){$(".radiustoy").removeClass('selectedtoy');} function resetFactionsVoices(){$(".radiusfac").removeClass('selectedfac');} function checkToylinesVoice(el){$(el).addClass('selectedtoy');} function checkFactionsVoice(el){$(el).addClass('selectedfac');} function goto(href){document.location = '?sez='+href;} function sleep(millis, callback) { setTimeout(function() { callback(); } , millis); } function addslashes(str) { return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); } Object.size = function(obj) { var size = 0, key; for (key in obj) { if (obj.hasOwnProperty(key)) size++; } return size; }; function alertj(j){console.log(JSON.stringify(j, null, 2))} function alert(t){console.log(t)}; function manageOrientation() { //alert(window.innerWidth+" - "+window.innerHeight); setTimeout(function(){ if(isLandscape()) { //hide all other elements for(let el in elDisplay) { let myel = document.getElementById(el); elDisplay[el] = myel.style.display; myel.style.display = "none"; } changeVisibilityMain('none'); elBody.style.backgroundImage = "url('_img/_orientation.png')"; elBody.style.backgroundRepeat = "no-repeat"; elBody.style.backgroundSize = "45vh"; elBody.style.backgroundPosition = "center"; //elBody.style.backgroundColor = "#424251"; elBody.style.marginBottom = "100vh"; } else { changeVisibilityMain(''); elBody.style.backgroundImage = 'none'; elBody.style.marginBottom = "0"; //show all other elements for(let el in elDisplay) { let myel = document.getElementById(el); myel.style.display = elDisplay[el]; elDisplay[el] = ""; } } }, ms); } function changeVisibilityMain(w) { elMain.style.display = w; } function isLandscape() { if(window.self!==window.top) return document.documentElement.clientWidth>document.documentElement.clientHeight; else { let screenCondition = onMobile ? window.innerWidth>window.innerHeight : screen.width>screen.height; if(/iP[ao]d|iPhone/i.test(window.navigator.userAgent)) { if(90===window.orientation || -90===window.orientation) return true; } else if( (screen.orientation!=undefined && (90===screen.orientation.angle || -90===screen.orientation.angle)) || screenCondition) { return true; } } return false; } function loadSwipeLogic() { elMenuSx.addEventListener('touchstart', function(e) { touchXstart = e.changedTouches[0].screenX; }) elMenuSx.addEventListener('touchend', function(e) { touchXend = e.changedTouches[0].screenX; checkSwipeDirection(); }) elMenuDx.addEventListener('touchstart', function(e) { touchXstart = e.changedTouches[0].screenX; }) elMenuDx.addEventListener('touchend', function(e) { touchXend = e.changedTouches[0].screenX; checkSwipeDirection(); }) } function checkSwipeDirection() { if(Math.abs(touchXend-touchXstart) < touchXminimum || isLandscape() || (!menusxOp && !menudxOp)) return; if(touchXendtouchXstart) { //console.log('swiped right!'); if(menudxOp) closeMenu('dx'); } } //moving divider logic function addListenerTableDivider() { return; if(onMobile) { let tablecoll = document.getElementById('tblcorecoll'); let tdfigures = document.getElementById('figures'); let tdqtas = document.getElementById('qtas'); let divider = document.getElementById('divider'); let tablefigures = document.getElementById('tablefigures'); let fixedlabelfigure = document.querySelector('#scrollfixedcolors .tdlabelfiguresfixed'); divider.addEventListener('touchstart', function(ev) //dragme.addEventListener('mousedown', function(ev) { const startX = ev.touches[0].clientX; //const startX = ev.clientX; const startWidth = divider.offsetWidth; const rectFigures = tdfigures.getBoundingClientRect(); const rectQta = tdqtas.getBoundingClientRect(); divider.style.background = "red"; const onMove = function(ev) { console.log(rectFigures); //console.log(ev); const deltaMov = ev.touches[0].clientX - startX; //tablefigures.style.width = 'calc(100% + '+deltaMov+'px)'; //tdfigures.style.width = 'calc(50% + '+deltaMov+'px)'; //tdqtas.style.width = 'calc(50% - '+deltaMov+'px)'; if((rectFigures.width + deltaMov)>130 && (rectFigures.width + deltaMov)<260) { //console.log(rectFigures.width); fixedlabelfigure.style.width = (rectFigures.width + deltaMov)+'px'; tdfigures.style.width = (rectFigures.width + deltaMov)+'px'; tdqtas.style.width = (rectQta.width - deltaMov)+'px'; } /* const deltaMov = ev.clientX - startX; tdfigures.style.width = (rectFigures.width + deltaMov)+'px'; tdqtas.style.width = (rectQta.width - deltaMov)+'px'; */ //console.log(deltaMov); //console.log('fig: '+tdfigures.style.width+' + '+deltaMov); //console.log('qta: '+tdqtas.style.width+' - '+deltaMov); }; const onUp = function(ev) { divider.style.background = "black"; tablecoll.removeEventListener('touchmove', onMove); document.body.removeEventListener('touchend', onUp); //tablecoll.removeEventListener('mousemove', onMove); //document.body.removeEventListener('mouseup', onUp); }; tablecoll.addEventListener('touchmove', onMove); document.body.addEventListener('touchend', onUp); //tablecoll.addEventListener('mousemove', onMove); //document.body.addEventListener('mouseup', onUp); }); } } /*////////////////////////////////////////////////////////////*/ /*////////////////////////////////////////////////////////////*/ /*////////////////////////////////////////////////////////////*/ /* function doFastLoad(str) { arrEl = str.split("|"); //creo un elemento finto e lo uso if(arrEl[2]>0) { var myT = $('').attr('sez',sez).attr('act',arrEl[0]).attr('idu',arrEl[1]).attr('idt',arrEl[2]); loadFactions(myT); checkToylinesVoice($('#idt_'+arrEl[2])); if(arrEl[3]>0) { var myF = $('').attr('sez',sez).attr('act',arrEl[0]).attr('idu',arrEl[1]).attr('idt',arrEl[2]).attr('idf',arrEl[3]); loadFigures(myF, sleep(1000, function(){ checkFactionsVoice($('#idf_'+arrEl[3])); })); } } } */ //////////////////////////////////////////////////////////////////////////////// function handleDragStart({target, dataTransfer}) { if(target.className.includes(dvoice)) { draggable = target; draggable.classList.add(voicedrag); dataTransfer.effectAllowed = 'move'; dataTransfer.setData('text', draggable.innerHTML); } } function handleDragOver(evt) { if(draggable) { evt.preventDefault(); evt.dataTransfer.dropEffect = 'move'; } } function handleDragEnter({target}) { if(draggable) { target.classList.add(voiceover); } } function handleDragLeave({target}) { if(draggable) { target.classList.remove(voiceover); } } function handleDragEnd() { draggable = null; items.forEach(function(item) { item.classList.remove(voiceover); item.classList.remove(voicedrag); item.classList.remove(listover); }); } function handleDrop(evt) { if(draggable === null) return; evt.stopPropagation(); evt.stopImmediatePropagation(); evt.preventDefault(); if(draggable !== this) { swapDom(draggable, evt); } } function swapDom(dragged, e) { e.preventDefault(); e.target.classList.remove(voiceover); if(dragged) { if(e.target.classList.contains(droot)) { e.target.appendChild(dragged); e.target.classList.remove(listover); } else if(e.target.classList.contains(dvoice)) { e.target.parentNode.insertBefore(dragged, e.target); } } } function handleContainerDragEnter(e) { if(e.target.classList.contains(droot)) { e.target.classList.add(listover); } } function handleContainerDragLeave(e) { if(e.target.classList.contains(droot)) { e.target.classList.remove(listover); } } function emptyMePrefs() { var listoriginal = document.getElementById('toylist_original'); var listcustom = document.getElementById('toylist_custom'); var divs = listcustom.querySelectorAll('div'); for(var i=0; i