-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone.js
More file actions
82 lines (67 loc) · 2.84 KB
/
phone.js
File metadata and controls
82 lines (67 loc) · 2.84 KB
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
/*
jquery mobule code to implement the phonelist
*/
(function phone( $ ) {
//-----------------------------------------------------------------------------------------------------------
var phoneList = null,
selectedEntry = null;
//-----------------------------------------------------------------------------------------------------------
function addEntriesFromPhonelist( uiElement, list) {
var category = null;
for ( category in list ) {
addDivider( uiElement, category );
addList( uiElement, list[ category ], category );
}
}
//-----------------------------------------------------------------------------------------------------------
function addDivider( ulElement, name ) {
var listItem = null;
listItem = '<li data-role="list-divider">' + name + '</li>';
ulElement.append( listItem );
}
//-----------------------------------------------------------------------------------------------------------
function addList( ulElement, list, category ) {
var listItem = null,
i = null;
for( i = 0; i < list.length; i++ ) {
listItem = '<li data-entry-id="' + category + '-' + i +
'" data-theme="c"><a href="#phone_entry" data-transition="slide">' +
list[ i ].name + ' (' + list[ i ].shortName + ') <br>' + list[ i ].firstNumber + '</a></li>';
ulElement.append( listItem );
}
}
//-----------------------------------------------------------------------------------------------------------
// main
//-----------------------------------------------------------------------------------------------------------
$( '#phonelist' ).live( "pagebeforecreate", function() {
$.getJSON( './phonelist.json', function gotPhoneList( phoneListAsJson ) {
return phoneListAsJson;
} ).done( function( phoneListAsJson ) {
phoneList = phoneListAsJson;
var ulElement = $( '#phoneListEntries' );
addEntriesFromPhonelist( ulElement, phoneList );
//handle selection of entry
ulElement.delegate('li', 'vclick', function( event ) {
event.stopPropagation();
selectedEntry = event.currentTarget.getAttribute( 'data-entry-id' );
});
ulElement.listview( 'refresh' );
} );
} );
$( '#phone_entry' ).live( "pagebeforeshow", function() {
if( selectedEntry ) {
var id = selectedEntry.split('-'),
phoneListEntry = phoneList[ id[ 0 ] ][ id[ 1 ] ];
$( '#name' ).html( phoneListEntry.name );
$( '#number' ).html( phoneListEntry.firstNumber );
$( '#number' ).prop( 'href', 'tel:' + phoneListEntry.firstNumber );
$( '#mobile' ).html( phoneListEntry.secondNumber || '-' );
if( phoneListEntry.secondNumber ) {
$( '#mobile' ).prop( 'href', 'tel:' + phoneListEntry.secondNumber );
}
} else {
$.mobile.changePage( '#phonelist' );
}
} );
window.scrollTo( 0, 1 );
})( $ );