Laravel 5.4 — Код для заставки javascript в блейде не запущен, но в консоли нет ошибок?

У меня есть страница блэйда на Laravel 5.4, которая позволяет пользователям вводить ответы на опрос. Система должна показывать заставку после простоя в течение определенного времени, т.е. простоя 5 минут. но заставка должна исчезнуть, когда кто-то взаимодействует со страницей. но коды не функционировали. Я проверил консоль, но в Google Chrome нет ошибок. (новичок в JavaScript)

@php
use App\Bus;
use App\Bgcroute;
use App\Surveyquestion;
use App\User;
use Controller\UserController;
@endphp
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BGC Bus Survey Page</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Cookie">
<link rel="stylesheet" href="assets/css/user.css">
<link rel="stylesheet" href="assets/css/Pretty-Footer.css">
<link rel="stylesheet" href="assets/css/Pretty-Header.css">
<link rel="stylesheet" href="assets/css/Hero-Technology.css">
<link rel="stylesheet" href="js-screensaver/screensaver.css">

<script src="js-screensaver/screensaver.js"></script>
<script src="sweetalert2.all.js"></script>
<script src="sweetalert2.min.js"></script>
<link rel="stylesheet" href="sweetalert2.min.js">
<style type="text/css">
.navbar {
margin-bottom: 0;
border-radius: 0;
background-color: #00FFFF;
color: #FFF;
padding: 1 0;
font-size: 1.2em;
border: 0;
}
.navbar-brand {
float: left;
min-height: 55px;
padding: 0 15px;
}
.img-logo{
width: 75px;
height: 60px;
}

.navbar-inverse .navbar-nav .active a, .navbar-inverse .navbar-nav .active a:focus, .navbar-inverse .navbar-nav .active a:hover {
color: #fff;
background-color: #53DFF0;
}
.navbar-inverse .nav-bar-nav li a {
color: #D5D5D5;
}
.avatar{
border-radius: 100%;
max-width: 100px;
clip: rect(10px,60px,50px,10px);

}

.startScreenSaver({
timeout: 5000,
width: 30,
height: 30,
exitTimeout: 1000,
});
</style>

<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-logo" src="img/logo.png"></a>

</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">

<form action="{{route('logout')}}" method="post">
{!!csrf_field()!!}
@if(!empty(Auth::user()->image))
<img src="{{ Auth::user()->image  }}" class="avatar" alt="" width="60" height="60">
@else
<img src={{ url('uploads/avatar.png') }} class="avatar" alt="" width="60" height="60">
@endif
<b>Your Driver of the Day, {{ Auth::user()->name  }}</b>
<button class="btn btn-danger">Log out</button>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Route/Bus Details
</button>

</form>

</ul>
</div>
</div>
</nav>


<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Select Your Desire Route</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body">

<form action="{{ route('surveysubmit') }}" >

<div class="form-group">
<h4>Select Bus</h4>
<select onchange="$('#busid').val(this.value);" class="form-control" >
@php
$display=''; $initbusid = '';
$buses = Bus::where(['archive'=>1])->orderBy('id')->get(['id','busplate']);
foreach($buses as $bus){
if(empty($initbusid)){$initbusid=$bus->id;}
$display .= '<option value='.$bus->id.'>'.$bus->busplate.'</option>';
}
echo $display;
@endphp
</select>
</div>
<div class="form-group">
<h4>Select Route</h4>
<select onchange="$('#routeid').val(this.value);" class="form-control" >
@php
$display2=''; $initrouteid = '';
$bgcroutes = Bgcroute::where(['routeloc'=>1,'archive'=>1])->orderBy('id')->get(['id','bgcbusroute']);
foreach($bgcroutes as $bgcroute){
if(empty($initrouteid)){$initrouteid=$bgcroute->id;}
$display2 .= '<option value='.$bgcroute->id.'>'.$bgcroute->bgcbusroute.'</option>';
}
echo $display2;
@endphp
</select>
</div>

<button type="button" class="btn btn-danger" data-dismiss="modal">Start Survey</button>
</form>
</div>
</div>
</div>
</div>

@php
$questions =  Surveyquestion::where('status',1)->get(['squestions','id'])->first();
@endphp

<section class="testimonials"></section>
<div class="jumbotron visible-xs-block visible-sm-block visible-md-block visible-lg-block hero-technology">
<h2 class="bg-success hero-title">{{ $questions->squestions }}</h2>
<p class="visible-xs-block visible-sm-block visible-md-block visible-lg-block visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xs-inline-block visible-sm-inline-block visible-md-inline-block visible-lg-inline-block hidden-xs hidden-sm hidden-md hidden-lg hero-subtitle">Nullam id dolor id nibh ultricies vehicula ut id elit. Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p>
<p class="text-primary bg-warning">Help Us Serve You Better</p>
<p></p>
<p class="text-center bg-primary">Rate us. Choose a smiley that Corresponds to your riding experience</p>
<div>

<input type="hidden" name="driverid" id="driverid" value="{{ Auth::user()->id }}"/>
<input type="hidden" name="busid" id="busid" value="{{ $initbusid }}"/>
<input type="hidden" name="routeid" id="routeid" value="{{ $initrouteid }}"/>
<input type="hidden" name="questionid"  id="questionid" value="{{ $questions->id }}"/>
<input type="hidden" name="responseid" id="responseid"/>
<table class="table">
<thead>
<tr>
<th class="info visible-xs-block visible-sm-block visible-md-block visible-lg-block visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xs-inline-block">
<img class="img-rounded" src="assets/img/person-clipart-silhouette-blue-14518-blue-man-design.png" height="100">
<a href="#" onclick="$('#responseid').val('1');surveyvote();">   <img src="assets/img/inlove.gif" height="70" id="loveid"> </a>
<a href="#" onclick="$('#responseid').val('2');surveyvote();"> <img src="assets/img/like.gif" height="90" id="likeid"></a>
<a href="#" onclick="$('#responseid').val('3');surveyvote();"> <img src="assets/img/facepalm.gif" height="70" id="faceid"> </a>
<a href="#" onclick="$('#responseid').val('4');surveyvote();"> <img src="assets/img/cry.gif" height="70" id="cryid"> </a>
</th>
<th
class="danger visible-xs-block visible-sm-block visible-md-block visible-lg-block visible-xs-inline visible-sm-inline visible-md-inline visible-lg-inline visible-xs-inline-block">
<img class="img-rounded" src="assets/img/pink-female-symbol-190136.png" width="40" height="100">
<a href="#" onclick="$('#responseid').val('5');surveyvote();"> <img src="assets/img/inlove.gif" height="70" id="loveid2"> </a>
<a href="#" onclick="$('#responseid').val('6');surveyvote();"> <img src="assets/img/like.gif" height="90" id="likeid2"> </a>
<a href="#" onclick="$('#responseid').val('7');surveyvote();"> <img src="assets/img/facepalm.gif" height="70" id="faceid2"> </a>
<a href="#" onclick="$('#responseid').val('8');surveyvote();"> <img src="assets/img/cry.gif" height="70" id="cryid2"> </a>
</th>
</tr>
</thead>
<tbody>
<tr></tr>
<tr></tr>
</tbody>
<caption> </caption>
</table>

</div>
<p>For Comments/Feedback Email us at [email protected]</p>
</div>
<div class="container">
<div class="table-responsive">
<table class="table">
<thead>
<tr></tr>
</thead>
<tbody>
<tr></tr>
<tr></tr>
</tbody>
</table>
</div>
</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>

<script type="text/javascript">
$(document).ready(function(e){

});

function surveyvote(){
driverid = $('#driverid').val();
busid = $('#busid').val();
routeid = $('#routeid').val();
questionid = $('#questionid').val();
responseid =  $('#responseid').val();
$.ajax({
"type":"get",
"url": "{{ route('surveyvoting')  }}",
"data": '&driverid='+driverid+'&busid='+busid+'&routeid='+routeid+'&questionid='+questionid+'&responseid='+responseid,
"success":function(result){
// Do something you want!

swal({
title: 'Thank You!',
//text: 'I will close in 3 seconds.',
timer: 1000,
onOpen: () => {
swal.showLoading()
}
}).then((result) => {
if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.timer
) {
console.log('I was closed by the timer')
}
})
}
});


}
</script>
<script type="text/javascript">

var screenSaver = {};


function startScreenSaver(options) {

//* attach event listeners to exit screensaver
attachScreenSaverEventListeners();

if(!screenSaver.initiated) {

//* set screensaver options
screenSaver.options = {

timeout: options.timeout || 5000, //* default timer to start screensaver is 10 minutes

width: options.width || 25,   //* default width is 25rem

height: options.height || 25, //* default height is 25rem

exitTimeout: options.exitTimeout || null, //* default timer to exit screensaver is disabled

}

//* create elements
var overlay = document.createElement("div");

overlay.setAttribute('class', 'screensaver-overlay');

document.body.appendChild(overlay);

var createBadge = document.createElement("div");

createBadge.setAttribute('id', 'saver-badge');

document.body.appendChild(createBadge);

createBadge.style.width = screenSaver.options.width + 'rem';

createBadge.style.height = screenSaver.options.height + 'rem';

}

document.getElementsByTagName("body")[0].classList.remove('screensaver');

screenSaver.initiated = true;

screenSaver.setTimeoutValue = screenSaver.options.timeout;

screenSaver.setTimeoutExit = screenSaver.options.timeoutExit;

screenSaver.setTimeout = null; //* clear timeout

screenSaver.inProgress = false;

screenSaver.timerStarted = false;

clearTimeout(screenSaver.setTimeout);

screenSaver.setTimeout = setTimeout(function() {

document.getElementsByTagName("body")[0].classList.add('screensaver');

screenSaver.inProgress = true;

var saverBadge = document.getElementById("saver-badge");

clearInterval(screenSaver.setInterval); //* clear badge display interval

screenSaver.setInterval = null;

//* get dimensions in em
var windowHeight = window.outerHeight / parseFloat(window.getComputedStyle(document.getElementsByTagName("body")[0], null).getPropertyValue('font-size'));

var windowWidth = window.outerWidth / parseFloat(window.getComputedStyle(document.getElementsByTagName("body")[0], null).getPropertyValue('font-size'));

screenSaver.setInterval = setInterval(function() {

if (screenSaver.inProgress === true) {

saverBadge.classList.remove('visible');

setTimeout(function() {

saverBadge.offsetWidth = saverBadge.offsetWidth;

saverBadge.classList.add('visible');

},1);

var saverTopValue = Math.floor(Math.random() * windowHeight) - screenSaver.options.width;

var saverLeftValue = Math.floor(Math.random() * windowWidth) - screenSaver.options.height;

if (saverTopValue <= 0) { //* make sure the badge doesn't go off the screen

saverTopValue = saverTopValue + 15;

}

if (saverLeftValue <= 0) {

saverLeftValue = saverLeftValue + 15;

}

saverBadge.style.top = saverTopValue + 'rem';

saverBadge.style.left = saverLeftValue + 'rem';

if(screenSaver.timerStarted === false && screenSaver.options.exitTimeout != null) {

startScreenSaverTimer();

}
}
}, 6000);

}, screenSaver.setTimeoutValue);
}

function startScreenSaverTimer() {

screenSaver.timerStarted = true;

setTimeout(function() {

stopScreenSaver();

}, screenSaver.setTimeoutExit);

}

function stopScreenSaver() {

startScreenSaver();

clearInterval(screenSaver.setInterval);

document.getElementsByTagName("body")[0].classList.remove('screensaver');

screenSaver.timerStarted = false;

}

function attachScreenSaverEventListeners() {

var events = ['touchstart', 'mousedown', 'mousemove', 'touchmove', 'keypress', 'scroll'];

var resetScreenSaver = function(e) {

if (screenSaver.inProgress) {

e.stopPropagation();

e.preventDefault();

}

clearTimeout(screenSaver.setTimeout);

clearInterval(screenSaver.setInterval);

document.getElementsByTagName("body")[0].classList.remove('screensaver');

startScreenSaver();

}

var checkClick = function(e) {

if (screenSaver.inProgress) {

startScreenSaver();

}

}

var bindEvents = function(eventName) {

document.addEventListener(eventName, screenSaver.initialize);

//* bind click as fallback for touchstart and mousedown
document.addEventListener('click', checkClick);

}

var unbindEvents = function(eventName) {

document.removeEventListener(eventName, screenSaver.initialize);

}

}

</script>


</body>

</html>

Вот связанные файлы, которые, я думаю, связаны со сценарием или JavaScript

CSS файл screensaver.css

body.screensaver #saver-badge {
opacity: 0;
display: block;
position: absolute;
filter: "progid:DXImageTransform.Microsoft.Dropshadow(OffX=12, OffY=12,Color='#444')";
filter: url(#drop-shadow);
-webkit-filter: drop-shadow(12px 12px 20px rgba(0,0,0,0.5));
filter: drop-shadow(12px 12px 20px rgba(0,0,0,0.5));
background: url(../img/vwd.png) center;
background-size: contain;
z-index: 1001;
}

body.screensaver #saver-badge.visible {
-webkit-animation: fadeBadge 6s;
-moz-animation:    fadeBadge 6s;
-o-animation:      fadeBadge 6s;
animation:         fadeBadge 6s;
opacity: 1;
}

body.screensaver .screensaver-overlay {
background: #000;
opacity: .5;
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
z-index: 1000;
}

#saver-badge {
display: none;
}

@-webkit-keyframes fadeBadge {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-moz-keyframes fadeBadge {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@-o-keyframes fadeBadge {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 0;
}
}
@keyframes fadeBadge {
0% {
opacity: 0;
}
20% {
opacity: 1;
}
80% {
opacity: 1;
}
100% {
opacity: 0;
}
}

JS файл
screensaver.js

var screenSaver = {};


function startScreenSaver(options) {

//* attach event listeners to exit screensaver
attachScreenSaverEventListeners();

if(!screenSaver.initiated) {

//* set screensaver options
screenSaver.options = {

timeout: options.timeout || 60000, //* default timer to start screensaver is 10 minutes

width: options.width || 25,   //* default width is 25rem

height: options.height || 25, //* default height is 25rem

exitTimeout: options.exitTimeout || null, //* default timer to exit screensaver is disabled

}

//* create elements
var overlay = document.createElement("div");

overlay.setAttribute('class', 'screensaver-overlay');

document.body.appendChild(overlay);

var createBadge = document.createElement("div");

createBadge.setAttribute('id', 'saver-badge');

document.body.appendChild(createBadge);

createBadge.style.width = screenSaver.options.width + 'rem';

createBadge.style.height = screenSaver.options.height + 'rem';

}

document.getElementsByTagName("body")[0].classList.remove('screensaver');

screenSaver.initiated = true;

screenSaver.setTimeoutValue = screenSaver.options.timeout;

screenSaver.setTimeoutExit = screenSaver.options.timeoutExit;

screenSaver.setTimeout = null; //* clear timeout

screenSaver.inProgress = false;

screenSaver.timerStarted = false;

clearTimeout(screenSaver.setTimeout);

screenSaver.setTimeout = setTimeout(function() {

document.getElementsByTagName("body")[0].classList.add('screensaver');

screenSaver.inProgress = true;

var saverBadge = document.getElementById("saver-badge");

clearInterval(screenSaver.setInterval); //* clear badge display interval

screenSaver.setInterval = null;

//* get dimensions in em
var windowHeight = window.outerHeight / parseFloat(window.getComputedStyle(document.getElementsByTagName("body")[0], null).getPropertyValue('font-size'));

var windowWidth = window.outerWidth / parseFloat(window.getComputedStyle(document.getElementsByTagName("body")[0], null).getPropertyValue('font-size'));

screenSaver.setInterval = setInterval(function() {

if (screenSaver.inProgress === true) {

saverBadge.classList.remove('visible');

setTimeout(function() {

saverBadge.offsetWidth = saverBadge.offsetWidth;

saverBadge.classList.add('visible');

},1);

var saverTopValue = Math.floor(Math.random() * windowHeight) - screenSaver.options.width;

var saverLeftValue = Math.floor(Math.random() * windowWidth) - screenSaver.options.height;

if (saverTopValue <= 0) { //* make sure the badge doesn't go off the screen

saverTopValue = saverTopValue + 15;

}

if (saverLeftValue <= 0) {

saverLeftValue = saverLeftValue + 15;

}

saverBadge.style.top = saverTopValue + 'rem';

saverBadge.style.left = saverLeftValue + 'rem';

if(screenSaver.timerStarted === false && screenSaver.options.exitTimeout != null) {

startScreenSaverTimer();

}
}
}, 6000);

}, screenSaver.setTimeoutValue);
}

function startScreenSaverTimer() {

screenSaver.timerStarted = true;

setTimeout(function() {

stopScreenSaver();

}, screenSaver.setTimeoutExit);

}

function stopScreenSaver() {

startScreenSaver();

clearInterval(screenSaver.setInterval);

document.getElementsByTagName("body")[0].classList.remove('screensaver');

screenSaver.timerStarted = false;

}

function attachScreenSaverEventListeners() {

var events = ['touchstart', 'mousedown', 'mousemove', 'touchmove', 'keypress', 'scroll'];

var resetScreenSaver = function(e) {

if (screenSaver.inProgress) {

e.stopPropagation();

e.preventDefault();

}

clearTimeout(screenSaver.setTimeout);

clearInterval(screenSaver.setInterval);

document.getElementsByTagName("body")[0].classList.remove('screensaver');

startScreenSaver();

}

var checkClick = function(e) {

if (screenSaver.inProgress) {

startScreenSaver();

}

}

var bindEvents = function(eventName) {

document.addEventListener(eventName, screenSaver.initialize);

//* bind click as fallback for touchstart and mousedown
document.addEventListener('click', checkClick);

}

var unbindEvents = function(eventName) {

document.removeEventListener(eventName, screenSaver.initialize);

}

for (var i=0;i<events.length;i++) {

bindEvents(events[i]);

}

}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]