_LOCK_MOVEMENT = false;
_STATUS_PLAY = false;
var servIP = _theme.server_ip || '';
var socket = io.connect(servIP, {
secure: false,
rememberTransport: false,
reconnectionAttempts: 16,
query: location.search.replace('?', '')
});
function ajax(path, callback, data) {
$.ajax({
url: path,
xhrFields: {withCredentials: true},
contentType: "application/json; charset=UTF-8",
type: data === undefined ? 'GET' : 'POST',
data: JSON.stringify(data)
}).done(function (res) {
return callback(res);
});
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
function bindEvent(element, eventName, eventHandler) {
if (element.addEventListener) {
element.addEventListener(eventName, eventHandler, false);
} else if (element.attachEvent) {
element.attachEvent('on' + eventName, eventHandler);
}
}
let nameNumber = {
'0':{class:'number n0',img: _theme.imgPath + '/cafe_project/number/0.webp'},
'1':{class:'number n1',img: _theme.imgPath + '/cafe_project/number/1.webp'},
'2':{class:'number n2',img: _theme.imgPath + '/cafe_project/number/2.webp'},
'3':{class:'number n3',img: _theme.imgPath + '/cafe_project/number/3.webp'},
'4':{class:'number n4',img: _theme.imgPath + '/cafe_project/number/4.webp'},
'5':{class:'number n5',img: _theme.imgPath + '/cafe_project/number/5.webp'},
'6':{class:'number n6',img: _theme.imgPath + '/cafe_project/number/6.webp'},
'7':{class:'number n7',img: _theme.imgPath + '/cafe_project/number/7.webp'},
'8':{class:'number n8',img: _theme.imgPath + '/cafe_project/number/8.webp'},
'9':{class:'number n9',img: _theme.imgPath + '/cafe_project/number/9.webp'},
'comma':{class:'comma',img: _theme.imgPath + '/cafe_project/number/comma.webp'},
'dot':{class:'dot',img: _theme.imgPath + '/cafe_project/number/dot.webp'},
}
function setUpShowmoney(money){
let formatCurrency = (money).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
let imagesString = ``;
let loadingEl = '
';
$('.credits > .money').html(`Credits${loadingEl}`);
if($('.mobile-container').length){
$('.mobile-container .header-mobile_container .credit .money-amount').html(loadingEl);
}
for (var i = 0; i < formatCurrency.length; i++) {
if(formatCurrency.charAt(i) == ','){
imagesString += ``;
}else if(formatCurrency.charAt(i) == '.'){
imagesString += ``;
}else{
imagesString += ``;
}
}
let fromCredit = `Credits`+imagesString;
setTimeout(function(){
$('.credits > .money').html(fromCredit);
// set layout for mobile
if($('.mobile-container').length){
let classAmountMobile = '.mobile-container .header-mobile_container .credit .money-amount';
$(classAmountMobile).css('display','none');
$(classAmountMobile).html(imagesString);
$(classAmountMobile).fadeIn(400);
}
},500);
}
var app = angular.module('mainApp', []);
var restartInt;
app.controller('gameCtrl', function ($scope, $rootScope, $timeout) {
$scope.listGames = _theme.list_game;
$scope.mainLink = window.location.href;
$scope.ready = false;
$scope.playing = true;
$scope.blocked = false;
$scope.user_data = {};
$scope.lang_list = [];
$scope.lost_connection = false;
$scope.current_game = _theme.list_game.slot.length ? 'slot' : 'fish' ; //current game provider when start
$scope.playing_gamehall = false;
// $scope.maintenance = {
// jdb : _theme.setting.maintenance_jdb,
// pg : _theme.setting.maintenance_pg,
// omg : _theme.setting.maintenance_omg
// }
$scope.lang_current = _theme.lang;
$scope.lang_list = _theme.lang_list;
$rootScope.disable_button_playgame = false;
$scope.waiting_refresh = false;
if(window.orientation == 0){
$scope.orientation = true;
}else{
$scope.orientation = false;
}
let web_location = window.location.href;
$scope.homepage = web_location.includes('station');
if(!$scope.homepage){
$("#orientation").css("display", "none");
}
if($(".container-welcome").length == 1){
$("#orientation").css("display", "none");
}
window.onorientationchange = function() {
switch (screen.orientation.type) {
case "landscape-primary":
case "landscape-secondary":
$scope.$apply(function () {
$scope.orientation = false;
});
break;
case "portrait-secondary":
case "portrait-primary":
$scope.$apply(function () {
$scope.orientation = true;
});
break;
default:
$scope.$apply(function () {
$scope.orientation = false;
});
}
}
// window.onorientationchange = function() {
// switch(window.orientation)
// {
// case 0:
// $scope.$apply(function () {
// $scope.orientation = true;
// });
// break;
// case 90:
// case -90:
// $scope.$apply(function () {
// $scope.orientation = false;
// });
// break;
// }
// };
// $scope.get_game = function(){
// ajax('/api/config', function (res) {
// if(res.enabled){
// $scope.games = res.list ;
// console.log($scope.games);
// }
// }, {
// config: 'cafe'
// });
// }
// $scope.get_game();
$scope.check_maintenance = function(){
if(!$scope.lost_connection){
ajax('/api/check_maintenance', function (res) {
// $scope.maintenance = {
// jdb : res.maintenance_jdb,
// pg : res.maintenance_pg,
// omg : res.maintenance_omg
// }
});
}
}
// $scope.check_maintenance();
$scope.play_game = function (gType, mType, gameHall, game_id) {
if($scope.lost_connection) return false ; // when lost connection and click spacebar
if(gameHall){
//if($scope.maintenance[gameHall]) return false
}
$rootScope.disable_button_playgame = true;
if(gameHall == 'JDB'){
if(gType == 'Slot') gType = 0;
if(gType == 'Fish') gType = 7;
}
if(gameHall == 'PG'){
if(gType == 'Slot') gType = 1900;
}
if(gameHall == 'OMG'){
if(gType == 'Slot') gType = 7770;
}
if(gameHall == 'JILI'){
if(gType == 'Slot' || gType == 'FISH') gType = 1200;
}
console.log('play_game');
console.log(gType);
console.log(mType);
console.log(gameHall);
console.log(game_id);
console.log('===============');
$scope.playing_gamehall = gameHall;
if (!$scope.user_data && !$scope.user_data.username) {
alert('No user login');
return $('#modal_login').modal()
}
if ($scope.playing){
$rootScope.disable_button_playgame = false;
return false;
}
$scope.modal_loading(true);
socket.emit('game_url', {
mType: mType,
gType: gType,
lang: $scope.lang_current,
gameHall: gameHall.toLowerCase(),
game_id : game_id
});
};
$scope.btn_withdraw = function () {
$scope.modal_loading(true);
$scope.ready = false;
socket.emit('withdraw_ask');
};
bindEvent(window, 'signal', function (e) {
// frame.innerHTML = e.data;
console.log('RERERER', e.data);
});
function returnModalUnavailable(reconnect = false){
let title = "System is unavailable please try to play again.";
if(reconnect) title = 'Found a problem with network and internet \r\ntry to reconnect for solve lost internet connection.'
return swal({
title: title,
type: "warning",
customClass:'modal-withdraw',
showCancelButton: false,
closeOnConfirm: true,
showLoaderOnConfirm: true,
closeOnClickOutside: false,
allowOutsideClick: false,
confirmButtonText: "ตกลง",
cancelButtonText: "ยกเลิก"
},
function (res) {
return location.reload(true);
});
}
socket
.on('connect', function () {
socket.emit('tell', 'trigger'); //Trigger socket bind with cookie
console.info('Connected!');
clearTimeout(restartInt);
$scope.$apply(function () {
$scope.lost_connection = false;
});
})
.on('reconnect', function () {
console.log('restarting !');
$scope.$apply(function () {
$scope.lost_connection = false;
});
// $scope.modal_loading(true);
// $scope.$apply(function () {
// $scope.playing=false;
// $scope.ready = true;
// $('#frame').remove();
// });
location.reload();
// return ModalUnavailable(true);
})
.on('disconnect', function (data) {
console.info('Server Stop connection!');
$scope.$apply(function () {
if(!$scope.playing){
$scope.lost_connection = true;
}else{
// $scope.lost_connection = true;
$scope.playing_gamehall = false;
$scope.playing=false;
$scope.ready = true;
$('#frame').remove();
return swal({
title: "The network is unstable.",
text: "Please wait for the browser to refresh",
closeOnClickOutside: false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
// timer: 3000,
},
function (res) {
// return location.reload(true);
});
}
});
if (data === 'transport close') {
restartInt = setTimeout(function () {
$scope.$apply(function () {
$scope.ready = false;
});
// location.reload();
}, 10000);
}
})
.on('alert', function (res) {
$scope.$apply(function (){
$scope.ready = false;
});
if(res == "LOGIN_TWICE"){
setTimeout(function(){
location.reload();
},5000);
}
})
.on('game_url', function (res) {
if(!res.success){
$rootScope.disable_button_playgame = false;
let msg = '';
switch (res.msg){
case 'Game Hall (JDB) Maintenance Can not do the transaction.':
case 'Game Hall (PG) Maintenance Can not do the transaction.':
case 'Game Hall (OMG) Maintenance Can not do the transaction.':
msg = "Game Hall (OMG) Maintenance Can not do the transaction"
break;
default :
msg = $scope.translateMessage(res.msg);
}
return swal({
title: msg,
closeOnClickOutside: false,
allowOutsideClick: false,
},
function () {
location.reload();
});
}else{
if (!res.data){
$rootScope.disable_button_playgame = false;
return swal('Cannot connect to game server, Please contact administrator.', 'error');
}
if (res.data.status !== "0000"){
$rootScope.disable_button_playgame = false;
return swal(res.data.err_text, 'error');
}
var can_play = res.data.status == "0000" && !$scope.playing;
$scope.$apply(function () {
$scope.playing = !!can_play;
});
if(res.data['path']){
if (can_play) {
$("#modal_game").append('');
setTimeout(function(){
swal.close();
$rootScope.disable_button_playgame = false;
if(res.data.html){
$("#frame").contents().find('body').html(res.data.path);
}else{
$('#frame').attr('src', res.data.path);
}
},1000);
}else{
$rootScope.disable_button_playgame = false;
return returnModalUnavailable();
}
}else{
$rootScope.disable_button_playgame = false;
return returnModalUnavailable();
}
}
})
.on('station_action', function (res) {
switch (res.action) {
case 'block':
case 'unblock':
if (!res.loging_in) {
$scope.$apply(function () {
if($scope.playing){
$scope.playing = false;
$('#frame').remove();
}
let urlParams = new URLSearchParams(window.location.search);
$scope.mainLink = window.location.origin + window.location.pathname;
$scope.mainLink += '?u=' +urlParams.get('u');
$scope.mainLink += '&p=' +urlParams.get('p');
if(res.action == 'block'){
$scope.mainLink += '&status=block';
}
setTimeout(function(){
$(location).attr('href',$scope.mainLink);
},3000);
});
// window.top.location.href = $scope.mainLink;
}
break;
case 'cashin':
startAdd(res.data.cur_balance, res.data.money);
$scope.user_data.money['total'] = res.data.cur_balance;
$scope.$apply(function () {
$scope.ready = true;
});
$('#modal_cashout').modal('hide');
_LOCK_MOVEMENT = false;
break;
case 'cashout':
$scope.$apply(function () {
$scope.ready = true;
});
$('#modal_cashout').modal('hide');
onCashout(res.data.money);
socket.emit('get_balance');
setTimeout(function(){
$('#modal_cashout').modal('hide');
},2000);
_LOCK_MOVEMENT = false;
break;
case 'cashout_reject':
$scope.$apply(function () {
$scope.ready = true;
});
$('#modal_cashout').modal('hide');
startAdd($scope.user_data.money['total'], res.data.money);
_LOCK_MOVEMENT = false;
socket.emit('get_balance');
break;
case 'reload' :
return window.location.reload();
break;
case 'stop_alarm' :
$('#alarmAlertSound')[0].pause();
$('#alarmAlertSound')[0].currentTime = 0;
$('#alarmAlert').removeClass('active');
break;
case 'enabled_gamehall':
$scope.modal_loading(true);
let data = res.data;
let gameHall = data.gamehall;
if(data.gamehall == 'jdb'){
if(data.enabled == false){
// if(! $scope.maintenance.jdb){
// $scope.maintenance.jdb = true;
// }
if($scope.playing){
return swal({
title: "Game Hall ("+ gameHall.toUpperCase() +") Disable Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
});
}else{
setTimeout(function(){
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
},1000);
}
}else{
$scope.check_maintenance();
}
}
if(data.gamehall == 'pg'){
if(data.enabled == false){
// if(!$scope.maintenance.pg){
// $scope.maintenance.pg = true;
// }
if($scope.playing){
return swal({
title: "Game Hall ("+ gameHall.toUpperCase() +") Disable Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
});
}else{
setTimeout(function(){
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
},1000);
}
}else{
$scope.check_maintenance();
}
}
if(data.gamehall == 'omg'){
if(data.enabled == false){
// if(!$scope.maintenance.omg){
// $scope.maintenance.omg = true;
// }
if($scope.playing){
return swal({
title: "Game Hall ("+ gameHall.toUpperCase() +") Disable Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
});
}else{
setTimeout(function(){
socket.emit('get_balance');
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
},1000);
}
}else{
$scope.check_maintenance();
}
}
setTimeout(function(){
$scope.$apply(function () {
$scope.ready = true;
});
swal.close();
},1000);
break;
case 'maintenance_gamehall':
let data_maintenance = res.data;
let game_hall = data_maintenance.gamehall;
if(data_maintenance.pidsetting.toString() == $scope.user_data.pid.toString()){
$scope.modal_loading(true);
if(data_maintenance.gamehall == 'jdb'){
if(data_maintenance.maintenance == true){
// $scope.maintenance.jdb = true;
if($scope.playing && $scope.playing_gamehall.toUpperCase() == 'JDB'){
return swal({
title: "Game Hall ("+ game_hall.toUpperCase() +") Maintenance Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
});
}else{
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}else{
// $scope.maintenance.jdb = false;
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}
if(data_maintenance.gamehall == 'pg'){
if(data_maintenance.maintenance == true){
// $scope.maintenance.pg = true;
if($scope.playing && $scope.playing_gamehall.toUpperCase() == 'PG'){
return swal({
title: "Game Hall ("+ game_hall.toUpperCase() +") Maintenance Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
});
}else{
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}else{
// $scope.maintenance.pg = false;
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}
if(data_maintenance.gamehall == 'omg'){
if(data_maintenance.maintenance == true){
// $scope.maintenance.omg = true;
if($scope.playing && $scope.playing_gamehall.toUpperCase() == 'OMG'){
return swal({
title: "Game Hall ("+ game_hall.toUpperCase() +") Maintenance Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
});
}else{
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}else{
// $scope.maintenance.omg = false;
setTimeout(function(){
location.reload();
// socket.emit('get_balance');
// $scope.$apply(function () {
// $scope.ready = true;
// });
// swal.close();
},1000);
}
}
if(data_maintenance.gamehall == 'jili'){
if(data_maintenance.maintenance == true){
if($scope.playing && $scope.playing_gamehall.toUpperCase() == 'JILI'){
return swal({
title: "Game Hall ("+ game_hall.toUpperCase() +") Maintenance Can not do the transaction",
closeOnClickOutside: false,
allowOutsideClick: false,
timer: 3000,
},
function () {
$scope.playing=false;
$('#frame').remove();
location.reload();
});
}else{
setTimeout(function(){
location.reload();
},1000);
}
}else{
setTimeout(function(){
location.reload();
},1000);
}
}
}
break;
case 'reload_balance' :
socket.emit('get_balance');
break;
case 'save_popular_game' :
case 'enabled_gamelist' :
case 'maintenance_gamelist' :
case 'add_gamelist' :
case 'edit_gamelist' :
let res_data = res.data;
if(res_data.pidsetting.toString() == $scope.user_data.pid.toString()){
if($scope.playing){
$scope.waiting_refresh = true;
}else{
return window.location.reload();
}
}
break;
}
})
.on('user_data', function (res) {
console.log('USER_DATA');
console.log(res);
if (!$scope.user_data.username) {
setTimeout(function () {
$(window).trigger('resize');
}, 500);
}
$scope.$apply(function () {
$scope.ready = true;
$scope.user_data = res;
_LOCK_MOVEMENT = false;
if ('money' in $scope.user_data){
setUpShowmoney($scope.user_data.money['total']);
}
});
//if cashout pending
if (res.lockmoney > 0) {
_LOCK_MOVEMENT = true;
onCashout(res.lockmoney);
setUpShowmoney($scope.user_data.money['total']);
}
// socket.emit('get_balance');
})
.on('playing_game',function(res){
console.log('PLAYING_GAME');
console.log(res);
// let pathImage = `/_global/images/reward/${res}.png`;
//why code like because first time set src to tag image and then do function on load for make sure image is loaded
//and then set background full screen to div background and fade in smooth opacity to show
// $('.img-game-reward').attr('src',pathImage).on('load',function(){
// $('.fullscreen-bg-image').css('background-image',`url('../../_global/images/reward/${res}.png')`); // absolute path from reward.html
// $('.fullscreen-bg-image').fadeIn(800);
// });
})
.on('exist_game',function(res){
console.log('EXIST_GAME');
$('.fullscreen-bg-image').fadeOut(800,function(){
$('.fullscreen-bg-image').attr('src','');
});
})
.on('get_balance',function(res){
if (res || res == 0){
setUpShowmoney(res);
}
})
.on('exit_game',function (res) {
$scope.$apply(function () {
if($scope.waiting_refresh){
return window.location.reload();
}else{
$scope.playing_gamehall = false;
$scope.playing=false;
$scope.ready = true;
$('#frame').remove();
}
});
})
.on('withdraw_answer', function (res) {
$scope.modal_loading(false);
$scope.$apply(function () {
$scope.ready = true;
});
let money = res - parseFloat(numFormat((res % 10), 2));
if(numFormat(res, 2) < 10.00){
swal({
title: "Can not withdraw the balance lower than 10 credit",
type: "warning",
customClass:'modal-withdraw',
showCancelButton: false,
closeOnConfirm: false,
showLoaderOnConfirm: true,
closeOnClickOutside: false,
allowOutsideClick: false,
confirmButtonText: "OK"
},
function () {
swal.close();
});
}else{
swal({
title: "Withdraw Cash \r\n" + numFormat(money, 2) + "",
type: "warning",
customClass:'modal-withdraw',
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
closeOnClickOutside: false,
allowOutsideClick: false,
confirmButtonText: "OK",
cancelButtonText: "Cancel"
},
function () {
_LOCK_MOVEMENT = true;
$scope.$apply(function () {
$scope.playing = false;
$('#frame').remove();
});
setTimeout(function () {
socket.emit('withdraw');
}, 2000);
});
$('#frame').focus();
}
})
.on('return_withdraw', function (data) {
console.log('with', data);
if (data.code === 'SUCCESS') {
_LOCK_MOVEMENT = true;
swal({
title: "System in progress please wait a moment...",
imageUrl: msg_img.success,
imageSize: '100x100',
confirmButtonText: "OK"
}, function () {
$scope.$apply(function () {
$scope.playing = false;
$('#frame').remove();
});
if (data.code == 'MONEY_INCORRECT') {
return;
}
});
setTimeout(function(){
swal.close();
},2000);
} else {
swal({
title: "Unable to process withdrawal",
text: "*Please contact customer service*",
// imageUrl: data.code == 'SUCCESS' ? msg_img.success : msg_img.confuse,
imageSize: '100x100',
confirmButtonText: "OK"
}, function () {
$scope.$apply(function () {
$scope.playing = false;
$('#frame').remove();
});
});
}
})
.on('session_expire'), function (res) {
console.log('session_expire');
return swal({
title: "*Session expire*",
text: "Please wait for the browser to refresh",
closeOnClickOutside: false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 3000,
},
function (res) {
return location.reload(true);
});
}
;
function onCashout(money) {
$scope.ready = false; //disable all for pending
$('#modal_cashout').modal();
$('#modal_cashout .bal').text(numFormat(money, 2));
}
$scope.$watch('blocked', function (isBlock) {
console.log('blocked', isBlock);
$scope.playing = false;
$('#frame').remove();
if (isBlock) {
$('#topLayer').addClass('blocked');
$(document).bind('keydown mousedown', function (e) {
return false
});
} else {
$('#topLayer').removeClass('blocked');
$(document).unbind('keydown mousedown');
}
});
$scope.$watch('ready', function(newVal) {
console.log('ready', newVal);
});
$scope.$watch('playing', function (isPlaying, oldVal) {
console.log('playing', isPlaying);
_STATUS_PLAY = isPlaying;
if (isPlaying) {
setTimeout(function () {
$('.btn-game-station').show();
$('#frame').focus();
}, 5000);
}
else {
socket.emit('exist_game');
//playing off
$('#frame').attr('src', '');
$('.btn-game-station').hide();
setTimeout(function () {
// $('#game-slider').slick('setPosition');
// $('#game-slider-pg').slick('setPosition');
// $('#game-slider-omg').slick('setPosition');
$('#game-slider-slot').slick('setPosition');
$('#game-slider-fish').slick('setPosition');
$(window).trigger('resize');
}, 500);
}
});
$(document).ready(function () {
onConnection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
let typeConnection = onConnection.effectiveType;
window.addEventListener('online', function(event){
console.log('listener-online');
$scope.$apply(function () {
$scope.lost_connection = false;
// setTimeout(function(){
// $(location).attr('href',$scope.mainLink);
// },3000);
// window.top.location.href = $scope.mainLink;
});
return false;
});
window.addEventListener('offline', function(event){
console.log('listener-offline');
$scope.$apply(function () {
if(!$scope.playing){
$scope.lost_connection = true;
}
if($rootScope.disable_button_playgame){
return swal({
title: "The network is unstable.",
text: "Please wait for the browser to refresh",
closeOnClickOutside: false,
allowOutsideClick: false,
showCancelButton: false,
showConfirmButton: false,
timer: 3000,
},
function (res) {
return location.reload(true);
});
}
});
});
$('.btn-game-station').hide();
//--- game box adjust (priority ordered) ---//
// var game_div_jdb = $("#jdb-game .gamelist-wrapper .swiper-slide");
// var game_div_pg = $("#pg-game .gamelist-wrapper .swiper-slide");
// var game_div_omg = $("#omg-game .gamelist-wrapper .swiper-slide");
var game_div_all_slot = $("#all-game-slot .gamelist-wrapper .swiper-slide");
var game_div_all_fish = $("#all-game-fish .gamelist-wrapper .swiper-slide");
if (_theme.device == 'desktop') {
// let amount_block = 15;
let amount_block = 12;
// for(var i = 0; i < game_div_jdb.length; i+= amount_block){
// game_div_jdb.slice(i,i+amount_block).wrapAll('');
// }
// for(var i = 0; i < game_div_pg.length; i+= amount_block){
// game_div_pg.slice(i,i+amount_block).wrapAll('');
// }
// for(var i = 0; i < game_div_omg.length; i+= amount_block){
// game_div_omg.slice(i,i+amount_block).wrapAll('');
// }
for(var i = 0; i < game_div_all_slot.length; i+= amount_block){
game_div_all_slot.slice(i,i+amount_block).wrapAll('');
}
for(var i = 0; i < game_div_all_fish.length; i+= amount_block){
game_div_all_fish.slice(i,i+amount_block).wrapAll('');
}
// for(var i = 0; i < game_div_jdb.length; i+=(i==0?12:16)) {
// game_div_jdb.slice(i, i+(i==0?12:16)).wrapAll("");
// }
//move 4 game box to left of video
// for (var i = 0; i < 4; i++) {
// game_div_jdb.eq(i).removeClass('col-sm-3').appendTo('#game-group-l');
// }
$('#game-group-r').prependTo($('.slider').eq(0));
$('#game-group-l').prependTo($('.slider').eq(0));
//--- scale screen
$(window).resize(function (evt) {
var scale = $(window).height() / $('.scale_screen').height();
$('.scale_screen').css({'-webkit-transform': 'scale(' + (scale - 0.06) + ')'});
// $('#wrap').css({ width: maxWidth * scale, height: maxHeight * scale });
});
} else {
// for(var i = 0; i < game_div_jdb.length; i+=16) {
// game_div_jdb.slice(i, i+16).wrapAll("");
// }
// for(var i = 0; i < game_div_pg.length; i+=16) {
// game_div_pg.slice(i, i+16).wrapAll("");
// }
// for(var i = 0; i < game_div_omg.length; i+=16) {
// game_div_omg.slice(i, i+16).wrapAll("");
// }
for(var i = 0; i < game_div_all_slot.length; i+=16) {
game_div_all_slot.slice(i, i+16).wrapAll("");
}
for(var i = 0; i < game_div_all_fish.length; i+=16) {
game_div_all_fish.slice(i, i+16).wrapAll("");
}
}
//--- slider
// let sliderList = $('#game-slider').slick({
// dots: true,
// arrows: true,
// lazyLoad: 'ondemand',
// autoplay: false,
// autoplaySpeed: 500,
// pauseOnHover: false,
// pauseOnFocus: false,
// slidesToShow: 1,
// slidesToScroll: 1,
// infinite: false
// });
// sliderList.slick("slickSetOption", "accessibility", false);
// sliderList.slick("slickSetOption", "draggable", true);
// sliderList.slick("slickSetOption", "swipe", true);
// sliderList.slick("slickSetOption", "touchMove", true);
// let sliderList_pg = $('#game-slider-pg').slick({
// dots: true,
// arrows: true,
// lazyLoad: 'ondemand',
// autoplay: false,
// autoplaySpeed: 500,
// pauseOnHover: false,
// pauseOnFocus: false,
// slidesToShow: 1,
// slidesToScroll: 1,
// infinite: false
// });
// sliderList_pg.slick("slickSetOption", "accessibility", false);
// sliderList_pg.slick("slickSetOption", "draggable", true);
// sliderList_pg.slick("slickSetOption", "swipe", true);
// sliderList_pg.slick("slickSetOption", "touchMove", true);
// let sliderList_omg = $('#game-slider-omg').slick({
// dots: true,
// arrows: true,
// lazyLoad: 'ondemand',
// autoplay: false,
// autoplaySpeed: 500,
// pauseOnHover: false,
// pauseOnFocus: false,
// slidesToShow: 1,
// slidesToScroll: 1,
// infinite: false
// });
// sliderList_omg.slick("slickSetOption", "accessibility", false);
// sliderList_omg.slick("slickSetOption", "draggable", true);
// sliderList_omg.slick("slickSetOption", "swipe", true);
// sliderList_omg.slick("slickSetOption", "touchMove", true);
let sliderList_allSlot = $('#game-slider-slot').slick({
dots: true,
arrows: true,
lazyLoad: 'ondemand',
autoplay: false,
autoplaySpeed: 500,
pauseOnHover: false,
pauseOnFocus: false,
slidesToShow: 1,
slidesToScroll: 1,
infinite: false
});
sliderList_allSlot.slick("slickSetOption", "accessibility", false);
sliderList_allSlot.slick("slickSetOption", "draggable", true);
sliderList_allSlot.slick("slickSetOption", "swipe", true);
sliderList_allSlot.slick("slickSetOption", "touchMove", true);
let sliderList_allFish = $('#game-slider-fish').slick({
dots: true,
arrows: true,
lazyLoad: 'ondemand',
autoplay: false,
autoplaySpeed: 500,
pauseOnHover: false,
pauseOnFocus: false,
slidesToShow: 1,
slidesToScroll: 1,
infinite: false
});
sliderList_allFish.slick("slickSetOption", "accessibility", false);
sliderList_allFish.slick("slickSetOption", "draggable", true);
sliderList_allFish.slick("slickSetOption", "swipe", true);
sliderList_allFish.slick("slickSetOption", "touchMove", true);
//---video playing
var curVid = 0;
videoList = shuffleArray(videoList);
if ($('#vidRank').length) {
$('#vidRank')
.bind('ended', function () {
curVid++;
if (curVid >= videoList.length) curVid = 0; //loop
$(this)
.attr('src', videoList[curVid].src)
.get(0)
.load()
// .play()
;
})
.trigger('ended')
.get(0).volume = 0.2
;
}
});
$scope.switch_game = function(game){
$scope.current_game = game;
$('.focus_target').removeClass('focus_target');
if($scope.current_game == 'slot'){
$("#all-game-slot").css("display", "block");
$("#all-game-fish").css("display", "none");
$('#game-slider-slot').get(0).slick.setPosition();
$($('#all-game-slot .slick-active .gamelist-item')[0]).addClass('focus_target');
}
if($scope.current_game == 'fish'){
$("#all-game-slot").css("display", "none");
$("#all-game-fish").css("display", "block");
$('#game-slider-fish').get(0).slick.setPosition();
$($('#all-game-fish .slick-active .gamelist-item')[0]).addClass('focus_target');
}
// if(game == 'jdb'){
// $("#jdb-game").css("display", "block");
// $("#pg-game").css("display", "none");
// $("#omg-game").css("display", "none");
// $('#game-slider').get(0).slick.setPosition();
// $($('#jdb-game .slick-active .gamelist-item')[0]).addClass('focus_target');
// }
// if(game == 'pg'){
// $("#jdb-game").css("display", "none");
// $("#pg-game").css("display", "block");
// $("#omg-game").css("display", "none");
// $('#game-slider-pg').get(0).slick.setPosition();
// $($('#pg-game .slick-active .gamelist-item')[0]).addClass('focus_target');
// }
// if(game == 'omg'){
// $("#jdb-game").css("display", "none");
// $("#pg-game").css("display", "none");
// $("#omg-game").css("display", "block");
// $('#game-slider-omg').get(0).slick.setPosition();
// $($('#omg-game .slick-active .gamelist-item')[0]).addClass('focus_target');
// }
}
setTimeout(function(){
$scope.switch_game($scope.current_game);
},1000);
$scope.modal_loading = function(status){
let loadingEl = '';
swal({
title: "Now loading . . .",
text: loadingEl,
html: true,
customClass:'modal-withdraw',
closeOnClickOutside: false,
allowOutsideClick: false,
showConfirmButton: false,
},
function () {
if(!status){
return false;
}
});
}
$scope.choose_lang = function(){
let html_select_language = '';
if($scope.lang_list){
for(let i = 0; i < $scope.lang_list.length ; i++){
html_select_language += '
';
}
}
swal({
title: 'Select Language',
text: html_select_language,
html: true,
customClass:'modal-withdraw',
closeOnClickOutside: false,
allowOutsideClick: false,
showConfirmButton: false,
showCancelButton: true,
cancelButtonText: "Cancel"
},
function () {
});
}
$scope.translateMessage = function (text, data) {
switch (text) {
case "USER_NOT_CREDIT":
err = "You do not have enough. Please top-up your account to continue.";
break;
case "USER_NOT_EXIST":
err = "USER NOT EXIST Please contact customer service.";
break;
case "GAME_USER_DATA_NOT_EXIST":
err = "USER DATA NOT EXIST Please contact customer service.";
break;
case "Transfer duplicate. please try again":
err = "Transfer duplicate. Please try again after 30 seconds.";
break;
default:
err = text;
}
return err;
}
$scope.setPathImageGame = function (gameHall, gameType,type,gameName,thumbnail) {
let lang = 'en';
if (_theme.lang === 'zh_CN') {
lang = 'cn';
}
let pathImageGame = {
'JDB': `${_theme['imgPath']}/gamelist/jdb_gamelist/${type}_${lang}.webp`,
'PG': `${_theme['imgPath']}/gamelist/pg_gamelist/${type}_${lang}.webp`,
'JILI': `${_theme['imgPath']}/gamelist/jili_gamelist/${type}_${lang}.webp`,
}
if(gameHall.toLowerCase() === 'omg'){
const options = {
cn: {
origin: 'cn',
replace: 'sc',
},
};
const short77_gamelist = ['en', 'mm', 'ph', 'sc', 'th'];
const updatedLangs = short77_gamelist.map(lang => {
for (const key in options) {
if (options[key].origin === lang) {
return options[key].replace;
}
}
return lang;
});
const targetLang = options[lang] ? options[lang].replace : lang;
const isActive = updatedLangs.includes(targetLang);
const currentLang = isActive ? targetLang : 'en';
pathImageGame[gameHall] = `${_theme['imgPath']}/gamelist/short77_gamelist/${type}_${currentLang}.webp`;
}
return pathImageGame[gameHall];
}
});
//--------------Video-------------------//
var videoList = [
// {
// src: "/_global/images/video/HD720_FormosaBear_SCH.mp4",
// gameId: 8006
// },
// {
// src: "/_global/images/video/HD720_LuckyDragons_SCH.mp4",
// gameId: 8001
// },
// {
// src: "/_global/images/video/HD720_LuckyLion_SCH.mp4",
// gameId: 8014
// },
// // {
// // src: "/_global/images/video/HD720_MahJong_SCH.mp4",
// // gameId: ''
// // },
// {
// src: "/_global/images/video/HD720_Llama_SCH.mp4",
// gameId: 8005
// },
// {
// src: "/_global/images/video/HD720_WinningMask_SCH.mp4",
// gameId: 8003
// }
];
_timeSave = null;
_clickSave = null;
let elFocus,column,groupFruit,wrapperChild,id_column;
$(document).ready(function () {
$('button').on('mouseup touchend', function (e) {
$(this).blur();
});
//keydown in menu select game
$(document).keydown(function(event) {
if(_LOCK_MOVEMENT){ return;}
let keycode = event.keyCode || event.which;
moveTarget(keycode,moment().format('x'));
// $('#game_cashout').html(keycode);
});
//init first game item focus
setTimeout(function(){
// $('#game-group-l').children().first().addClass('focus_target');
// $('#game-slider').children().first().addClass('focus_target');
// $($('[data-slick-index="0"] > .gamelist-item')[0]).addClass('focus_target');
$('.check-listener').click();
}, 1200);
$('.gamelist-item').on('click',function(){
$('.focus_target').removeClass('focus_target');
$(this).addClass('focus_target');
$('.check-listener').click();
$('.swiper-wrapper.gamelist-wrapper').click();
$('.container.scale_screen').click();
elFocus = $('.focus_target');
id_column = elFocus.closest('.slick-slider').attr('id');
column = elFocus.closest('#'+id_column+' .slider.slick-slide').attr('data-slick-index');
// column = elFocus.closest('.slider.slick-slide').attr('data-slick-index');
groupFruit = elFocus.closest('#game-group-l').length;
wrapperChild = elFocus.parent().children().length;
setTimeout(()=>{
$('.check-listener').click();
$('.swiper-wrapper.gamelist-wrapper').click();
$('.container.scale_screen').click();
},20);
});
$('#game_menu').on('click',function(){
setTimeout(function(){
socket.emit('get_balance');
socket.emit('exit_game');
},500);
});
$(document).on("click",".slick-next.slick-arrow",function() {
let curActive = $('.slider.slick-active').attr('data-slick-index');
let focus = $('.focus_target');
id_column = focus.closest('.slick-slider').attr('id');
focus.removeClass('focus_target');
$('#'+id_column+' .slick-active > .gamelist-item:first-child').addClass('focus_target');
// $('.slick-active > .gamelist-item:first-child').addClass('focus_target');
});
$(document).on("click",".slick-prev.slick-arrow",function() {
let curActive = $('.slider.slick-active').attr('data-slick-index');
let focus = $('.focus_target');
// if(focus.is(':first-child')){
// focus.removeClass('focus_target');
// $('.slick-active > .gamelist-item:last-child').addClass('focus_target');
// }else{
// focus.removeClass('focus_target');
// $('.slick-active > .gamelist-item:first-child').addClass('focus_target');
// }
id_column = focus.closest('.slick-slider').attr('id');
column = focus.closest('#'+id_column+' .slider.slick-slide').attr('data-slick-index');
if(column != 0){
focus.removeClass('focus_target');
$('#'+id_column+' .slick-active > .gamelist-item:last-child').addClass('focus_target');
}
console.log('move by click button');
});
$(document).on("click",".slick-dots > .slick-active",function(){
let focus = $('.focus_target');
id_column = focus.closest('.slick-slider').attr('id');
focus.removeClass('focus_target');
$('#'+id_column+' .slick-active > .gamelist-item:first-child').addClass('focus_target');
// $('.slick-active > .gamelist-item:first-child').addClass('focus_target');
});
$(document).on('click','#alarmAlert',function(){
$(this).addClass('active');
socket.emit('call_staff');
$('#alarmAlertSound')[0].loop = true;
$('#alarmAlertSound')[0].play();
// setTimeout(function(){
// $('#alarmAlert').removeClass('active');
// },3500);
});
$(document).on('click','.btn-play',function(){
$(this).attr('disabled',true);
let _this = this;
setTimeout(function(){
$(_this).attr("disabled", false);
$(_this).removeAttr("disabled");
}, 1500);
});
$(document).on('click','.sweet-overlay',function(){
});
$(document).on('click','[ng-click="btn_withdraw()"]',function(){
});
const listsAllGameMobile = document.querySelectorAll('.listgames-mobile_container');
listsAllGameMobile.forEach(el => {
const listItems = el.querySelectorAll('.game-item-mobile');
const n = el.children.length;
let totalDiv2 = Math.ceil(n/2);
el.style.setProperty('--total', totalDiv2);
});
// detectReactionUser();
let count_click_data = 0;
$(document).on('click','.machine-no-data',function(){
count_click_data ++;
if(count_click_data == 5){
location.reload();
}
});
});
function changeLanguage(lang_code){
ajax('/script', function (res) {
if (res.success){
loading();
location.reload();
}else{
swal.close();
}
}, {method: 'lang', val: lang_code});
}
function loading(){
let loadingEl = '';
swal({
title: "Now loading . . .",
text: loadingEl,
html: true,
customClass:'modal-withdraw',
closeOnClickOutside: false,
allowOutsideClick: false,
showConfirmButton: false,
},
function () {
});
}
function detectReactionUser(){
let timeLimit = 300; // 5 minnutes = 300 secounds
let startTime = 0;
let loopCountActive = setInterval(function(){
if(_STATUS_PLAY){
startTime = 0;
}
startTime++;
if(startTime > timeLimit){
if($('#topLayer').length){
return window.location.reload();
}
}
},1000);
$(document).keydown(function(event) {
if(_LOCK_MOVEMENT){ return;}
let keycode = event.keyCode || event.which;
console.log('keydown');
startTime = 0;
});
$(document).on('click mousedown mouseenter mouseup', function () {
console.log('Mouse');
startTime = 0;
});
}
window.onload = function(){
var ifr = document.getElementById('frame');
if(ifr){
ifr.onload = function(){
$('#frame').focus();
};
}
};
function moveTarget(direction,timePress){
elFocus = $('.focus_target');
id_column = elFocus.closest('.slick-slider').attr('id');
column = elFocus.closest('#'+id_column+' .slider.slick-slide').attr('data-slick-index');
// column = elFocus.closest('.slider.slick-slide').attr('data-slick-index');
groupFruit = elFocus.closest('#game-group-l').length;
wrapperChild = elFocus.parent().children().length;
//this code fixed bug click quikly right and left error change position wrong
if(_clickSave && _timeSave){
if(_clickSave == 39 && direction == 37){
if(elFocus.is(':first-child')){
let timeDistance = parseInt(timePress,10) - parseInt(_timeSave,10);
if(timeDistance < 680) return;
}
}
if(_clickSave == 37 && direction == 39){
if(elFocus.is(':last-child')){
let timeDistance = parseInt(timePress,10) - parseInt(_timeSave,10);
if(timeDistance < 680) return;
}
}
}
_timeSave = timePress;
_clickSave = direction;
switch (direction) {
case 37: moveLeft(); break; //(arrow)left
case 38: moveUp(); break; // (arrow)up
case 39: moveRight(); break; // (arrow)right
case 40: moveDown(); break; // (arrow)down
case 32: moveSpaceBar(); break; // space-bar
case 27: backToMenu(); break; // esc
case 8: goCashOut(); break; // esc
default:
break;
}
function goCashOut(){
$('#game_cashout').click();
}
function backToMenu(){
if($('.modal-withdraw').length){
$('.modal-withdraw button.cancel').click();
return;
}
$('#game_menu').click();
}
function moveLeft(){
//check first game back to top
if(column == 0){
// let checkFirst = $('[data-slick-index="0"] > .gamelist-item')[0];
// if($(checkFirst).hasClass('focus_target')){
// return;
// }
if(!elFocus.is(':first-child')){
if(elFocus.is(':first-child') && groupFruit)return;
elFocus.removeClass('focus_target');
elFocus.prev().addClass('focus_target');
}
}else{
if(elFocus.is(':first-child')){
// if($('button.slick-prev').attr('aria-disabled') === 'false'){
$('button.slick-prev').click();
$('.check-listener').click();
elFocus.removeClass('focus_target');
$('#'+id_column+' .slick-active > .gamelist-item:last-child').addClass('focus_target');
console.log('move element');
// }
}else{
elFocus.removeClass('focus_target');
elFocus.prev().addClass('focus_target');
}
}
$('.check-listener').html('left');
}
function moveRight(){
$('.check-listener').html('right');
if(groupFruit && !elFocus.next().length){
elFocus.removeClass('focus_target');
// let next = $('[data-slick-index="0"] > .gamelist-item')[0];
// $(next).addClass('focus_target');
}else{
//detect last child in colum
if(elFocus.is(':last-child')){
if($('button.slick-next').attr('aria-disabled') === 'false'){
$('button.slick-next').click();
$('.check-listener').click();
elFocus.removeClass('focus_target');
$('#'+id_column+' .slick-active > .gamelist-item:first-child').addClass('focus_target');
}
}else{
elFocus.removeClass('focus_target');
elFocus.next().addClass('focus_target');
}
}
return;
}
function moveUp(){
$('.check-listener').html('up');
let current = $('.slick-active > .gamelist-item.focus_target');
let index = current.index();
let prevs = '';
for(let k = 0; k < 4;k++){
prevs +='.prev()';
}
if(index >= 4 && index <= 11){
elFocus.removeClass('focus_target');
eval('elFocus'+prevs+'.addClass("focus_target")');
}
}
function moveDown(){
let current = $('.slick-active > .gamelist-item.focus_target');
let nexts = '';
for(let k = 0; k < 4;k++){
nexts +='.next()';
}
let index = current.index();
if(wrapperChild >= 0 && wrapperChild <= 4){
}else if(wrapperChild > 4 && wrapperChild <=8){
if(index >= 0 && index <= 3){
moveNexts();
}
}else if(wrapperChild > 8 && wrapperChild <= 12){
if(index >= 0 && index <= 7){
moveNexts();
}
}else if(wrapperChild > 12){
if(index >= 0 && index <= 11){
moveNexts();
}
}
function moveNexts(){
if(elFocus.next().next().next().next().hasClass('gamelist-item')){
elFocus.removeClass('focus_target');
eval('elFocus'+nexts+'.addClass("focus_target")');
}else{
elFocus.removeClass('focus_target');
$('.slick-active > .gamelist-item:last-child').addClass('focus_target');
}
}
$('.check-listener').html('down');
}
function moveSpaceBar(){
let disable_button = $('#page').injector().get('$rootScope').disable_button_playgame;
let maintenance_game = $(elFocus).find('button.btn-play').prop('disabled');
if(!disable_button && !maintenance_game){
$(elFocus).find('button.btn-play').click();
$('.check-listener').html('space-bar');
}
}
}
function shuffleArray(array) {
var m = array.length, t, i;
// While there remain elements to shuffle
while (m) {
// Pick a remaining element…
i = Math.floor(Math.random() * m--);
// And swap it with the current element.
t = array[m];
array[m] = array[i];
array[i] = t;
}
return array;
}
//----- Add balance -----//
function numFormat(num, toFixed) {
var f;
if (toFixed) {
f = parseFloat(num).toFixed(toFixed);
} else {
f = Math.round(num).toString();
}
return f.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
}
var adding = {
playing: false
};
function startAdd(currentBalance, addBy) {
if (adding.playing) return false;
adding.playing = true;
$('.bg-cashin-block').addClass('active');
var b = '#cashin-block';
$(b+' .cur').text(numFormat(currentBalance, 2));
$(b+' .add').text(numFormat(addBy, 2));
$(b+' .bal').text(numFormat(parseFloat(currentBalance) + parseFloat(addBy), 2));
$(b)
.addClass('in')
.delay(800)
.queue(function (next) {
$(b+' .bal').addClass('blink');
next();
})
.delay(2000)
.queue(function (next) {
$(b+' .bal').removeClass('blink');
next();
})
.delay(4500)
.queue(function (next) {
$(b).removeClass('in');
$('.bg-cashin-block').removeClass('active');
adding.playing = false;
next();
})
;
socket.emit('get_balance');
}
//----- End Add balance -----//