From 178521ee01e8cdab1be958102603c0905ba21633 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 7 Apr 2016 11:51:07 -0300 Subject: [PATCH] Clean js code --- static/js/index.js | 48 ++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index f625449..b260457 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -31,7 +31,7 @@ function snackbarLog(givenMessage) { } function updateBitrateField() { - $('#bitrateField').html($('#bitrateSlider')[0].value + " Mbps"); + $('#bitrateField').html($('#bitrateSlider').val() + " Mbps"); } function moduleDidLoad() { @@ -60,10 +60,9 @@ function moduleDidLoad() { // because the user can change the target host at any time, we continually have to check function updateTarget() { - target = $('#GFEHostIPField')[0].value; + target = $('#GFEHostIPField').val(); if (target == null || target == "") { - var e = $("#selectHost")[0]; - target = e.options[e.selectedIndex].value; + target = $("#selectHost option:selected").val(); } if(api && api.address != target) { @@ -95,25 +94,29 @@ function pairPushed() { api = new NvHTTP(target, myUniqueid); } - $('#pairButton')[0].innerHTML = 'Pairing...'; + if(api.paired) { + return; + } + + $('#pairButton').html('Pairing...'); snackbarLog('Attempting pair to: ' + target); var randomNumber = String("0000" + (Math.random()*10000|0)).slice(-4); var pairingDialog = document.querySelector('#pairingDialog'); - document.getElementById('pairingDialogText').innerHTML = 'Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete'; + $('#pairingDialogText').html('Please enter the number ' + randomNumber + ' on the GFE dialog on the computer. This dialog will be dismissed once complete'); pairingDialog.showModal(); console.log('sending pairing request to ' + target + ' with random number ' + randomNumber); api.pair(randomNumber).then(function (paired) { if (!paired) { snackbarLog('Pairing failed'); - $('#pairButton')[0].innerHTML = 'Pairing Failed'; - document.getElementById('pairingDialogText').innerHTML = 'Error: Pairing failed'; + $('#pairButton').html('Pairing Failed'); + $('#pairingDialogText').html('Error: Pairing failed'); if (api.currentGame != 0) snackbarLog(target + ' is already in game. Cannot pair!'); return; } - $('#pairButton')[0].innerHTML = 'Paired'; + $('#pairButton').html('Paired'); snackbarLog('Pairing successful'); pairingDialog.close(); @@ -153,19 +156,18 @@ function showAppsPushed() { // Most likely, the user just hit the 'retrieve app list' button again $('#selectGame').empty(); } - for (var i = 0; i < appList.length; i++) { // programmatically add each app - var opt = document.createElement('option'); - opt.appendChild(document.createTextNode(appList[i])); - opt.value = appList[i].id; - opt.innerHTML = appList[i].title; - $('#selectGame')[0].appendChild(opt); - } + + appList.forEach(function (app) { + $('#selectGame').append($('