1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('mobile', function() {
function ChooseNetwork() {
}
cr.addSingletonGetter(ChooseNetwork);
ChooseNetwork.prototype = {
networks_: [],
showNetworks_: function(networks) {
this.networks_ = networks;
if (networks.length == 0) {
$('scanning').hidden = true;
$('choosing').hidden = true;
$('no-mobile-networks').hidden = false;
return;
}
var container = $('choosing');
container.innerHTML = '';
for (var i in networks) {
var elem = document.createElement('div');
elem.innerHTML =
'<input type="radio" name="network" id="network' + i + '" />' +
'<label for="network' + i + '" id="label' + i + '"></label>';
container.appendChild(elem);
$('label' + i).textContent = networks[i].operatorName;
if (networks[i].status == 'current') {
$('network' + i).checked = true;
$('connect').disabled = false;
} else if (networks[i].status == 'forbidden') {
$('network' + i).disabled = true;
elem.className = 'disabled';
} else {
$('network' + i).addEventListener('click', function(event) {
$('connect').disabled = false;
});
}
}
$('scanning').hidden = true;
$('choosing').hidden = false;
$('no-mobile-networks').hidden = true;
},
connect_: function() {
for (var i in this.networks_) {
if ($('network' + i).checked) {
chrome.send('connect', [this.networks_[i].networkId]);
ChooseNetwork.close();
return;
}
}
},
showScanning_: function() {
$('scanning').hidden = false;
$('choose').hidden = true;
$('no-mobile-networks').hidden = true;
}
};
ChooseNetwork.cancel = function() {
chrome.send('cancel');
ChooseNetwork.close();
};
ChooseNetwork.close = function() {
window.close();
};
ChooseNetwork.connect = function() {
ChooseNetwork.getInstance().connect_();
};
ChooseNetwork.showScanning = function() {
ChooseNetwork.getInstance().showScanning_();
};
ChooseNetwork.initialize = function() {
$('cancel').addEventListener('click', function(event) {
ChooseNetwork.cancel();
});
$('connect').disabled = true;
$('connect').addEventListener('click', function(event) {
ChooseNetwork.connect();
});
chrome.send('pageReady');
};
ChooseNetwork.showNetworks = function(networks) {
ChooseNetwork.getInstance().showNetworks_(networks);
};
// Export
return {
ChooseNetwork: ChooseNetwork
};
});
var ChooseNetwork = mobile.ChooseNetwork;
document.addEventListener('DOMContentLoaded', function() {
// TODO(dpolukhin): refactor spinner code&css to be reusable.
// Setup css canvas 'spinner-circle'
(function() {
var lineWidth = 3;
var r = 8;
var ctx = document.getCSSCanvasContext(
'2d', 'spinner-circle', 2 * r, 2 * r);
ctx.lineWidth = lineWidth;
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.strokeStyle = '#4e73c7';
ctx.beginPath();
ctx.moveTo(lineWidth / 2, r - lineWidth / 2);
ctx.arc(r, r, r - lineWidth / 2, Math.PI, Math.PI * 3 / 2);
ctx.stroke();
})();
ChooseNetwork.initialize();
});
disableTextSelectAndDrag();
|