Permalink
Aug 8, 2015
Aug 8, 2015
Apr 2, 2016
Oct 17, 2016
Nov 8, 2016
Aug 8, 2015
Apr 2, 2016
Aug 8, 2015
Nov 2, 2017
Aug 8, 2015
Aug 8, 2015
Oct 17, 2016
Nov 8, 2016
Oct 17, 2016
Aug 8, 2015
Oct 17, 2016
Oct 17, 2016
Aug 8, 2015
Aug 8, 2015
Aug 10, 2015
Nov 2, 2017
Aug 8, 2015
Aug 10, 2015
Aug 8, 2015
Aug 10, 2015
Apr 23, 2016
Aug 8, 2015
Aug 8, 2015
Nov 8, 2016
Nov 8, 2016
Nov 8, 2016
Oct 17, 2016
Oct 17, 2016
Aug 8, 2015
Aug 10, 2015
Aug 8, 2015
Aug 8, 2015
Aug 8, 2015
Nov 2, 2017
Aug 8, 2015
Aug 8, 2015
Aug 8, 2015
Aug 8, 2015
Aug 8, 2015
Newer
100644
319 lines (280 sloc)
11.2 KB
2
(
function
(
$
)
{
3
4
$
.
googlePlaces
=
function
(
element
,
options
)
{
8
placeId
:
'ChIJN1t_tDeuEmsRUsoyG83frY4'
// placeId provided by google api documentation
9
,
render
:
[
'reviews'
]
14
,
schema
:
{
15
displayElement
:
'#schema'
16
,
type
:
'Store'
17
,
beforeText
:
'Google Users Have Rated'
18
,
middleText
:
'based on'
19
,
afterText
:
'ratings and reviews'
21
,
address
:
{
22
displayElement
:
"#google-address"
23
}
24
,
phone
:
{
25
displayElement
:
"#google-phone"
26
}
28
displayElement
:
"#google-static-map"
29
,
width
:
512
30
,
height
:
512
31
,
zoom
:
17
32
,
type
:
"roadmap"
38
39
var
plugin
=
this
;
40
41
plugin
.
settings
=
{
}
42
43
var
$element
=
$
(
element
)
,
44
element
=
element
;
45
46
plugin
.
init
=
function
(
)
{
47
plugin
.
settings
=
$
.
extend
(
{
}
,
defaults
,
options
)
;
48
plugin
.
settings
.
schema
=
$
.
extend
(
{
}
,
defaults
.
schema
,
options
.
schema
)
;
49
$element
.
html
(
"
+
plugin
.
settings
.
map_plug_id
+
"'>
"
)
;
// create a plug for google to load data into
50
initialize_place
(
function
(
place
)
{
51
plugin
.
place_data
=
place
;
55
56
if
(
plugin
.
settings
.
render
.
indexOf
(
'rating'
)
>
-
1
)
{
57
renderRating
(
plugin
.
place_data
.
rating
)
;
58
}
59
// render specified sections
60
if
(
plugin
.
settings
.
render
.
indexOf
(
'reviews'
)
>
-
1
)
{
61
renderReviews
(
plugin
.
place_data
.
reviews
)
;
65
}
66
if
(
plugin
.
settings
.
render
.
indexOf
(
'address'
)
>
-
1
)
{
67
renderAddress
(
68
capture_element
(
plugin
.
settings
.
address
.
displayElement
)
69
,
plugin
.
place_data
.
adr_address
70
)
;
71
}
72
if
(
plugin
.
settings
.
render
.
indexOf
(
'phone'
)
>
-
1
)
{
73
renderPhone
(
74
capture_element
(
plugin
.
settings
.
phone
.
displayElement
)
75
,
plugin
.
place_data
.
formatted_phone_number
76
)
;
77
}
78
if
(
plugin
.
settings
.
render
.
indexOf
(
'staticMap'
)
>
-
1
)
{
79
renderStaticMap
(
80
capture_element
(
plugin
.
settings
.
staticMap
.
displayElement
)
81
,
plugin
.
place_data
.
formatted_address
82
)
;
83
}
84
if
(
plugin
.
settings
.
render
.
indexOf
(
'hours'
)
>
-
1
)
{
85
renderHours
(
86
capture_element
(
plugin
.
settings
.
hours
.
displayElement
)
87
,
plugin
.
place_data
.
opening_hours
88
)
;
89
}
92
addSchemaMarkup
(
93
capture_element
(
plugin
.
settings
.
schema
.
displayElement
)
94
,
plugin
.
place_data
95
)
;
100
}
)
;
101
}
102
103
var
capture_element
=
function
(
element
)
{
104
if
(
element
instanceof
jQuery
)
{
105
return
element
;
106
}
else
if
(
typeof
element
==
'string'
)
{
107
try
{
108
var
ele
=
$
(
element
)
;
109
if
(
ele
.
length
)
{
111
}
else
{
112
throw
'Element ['
+
element
+
'] couldnt be found in the DOM. Skipping '
+
element
+
' markup generation.'
;
113
}
114
}
catch
(
e
)
{
120
var
initialize_place
=
function
(
c
)
{
121
var
map
=
new
google
.
maps
.
Map
(
document
.
getElementById
(
plugin
.
settings
.
map_plug_id
)
)
;
122
123
var
request
=
{
124
placeId
:
plugin
.
settings
.
placeId
125
}
;
126
127
var
service
=
new
google
.
maps
.
places
.
PlacesService
(
map
)
;
128
129
service
.
getDetails
(
request
,
function
(
place
,
status
)
{
130
if
(
status
==
google
.
maps
.
places
.
PlacesServiceStatus
.
OK
)
{
131
c
(
place
)
;
132
}
133
}
)
;
134
}
135
136
var
sort_by_date
=
function
(
ray
)
{
137
ray
.
sort
(
function
(
a
,
b
)
{
138
var
keyA
=
new
Date
(
a
.
time
)
,
139
keyB
=
new
Date
(
b
.
time
)
;
140
// Compare the 2 dates
141
if
(
keyA
<
keyB
)
return
-
1
;
142
if
(
keyA
>
keyB
)
return
1
;
143
return
;
144
}
)
;
145
return
ray
;
146
}
147
148
var
filter_minimum_rating
=
function
(
reviews
)
{
149
for
(
var
i
=
reviews
.
length
-
1
;
i
>=
;
i
--
)
{
150
if
(
reviews
[
i
]
.
rating
<
plugin
.
settings
.
min_rating
)
{
151
reviews
.
splice
(
i
,
1
)
;
152
}
153
}
154
return
reviews
;
155
}
156
157
var
renderRating
=
function
(
rating
)
{
158
var
html
=
""
;
159
var
star
=
renderAverageStars
(
rating
)
;
160
html
=
"
"
;
161
$element
.
append
(
html
)
;
162
}
163
164
var
renderReviews
=
function
(
reviews
)
{
165
reviews
=
sort_by_date
(
reviews
)
;
166
reviews
=
filter_minimum_rating
(
reviews
)
;
167
var
html
=
""
;
168
var
row_count
=
(
plugin
.
settings
.
max_rows
>
)
?
plugin
.
settings
.
max_rows
-
1
:
reviews
.
length
-
1
;
169
// make sure the row_count is not greater than available records
170
row_count
=
(
row_count
>
reviews
.
length
-
1
)
?
reviews
.
length
-
1
:
row_count
;
172
var
stars
=
renderStars
(
reviews
[
i
]
.
rating
)
;
173
var
date
=
convertTime
(
reviews
[
i
]
.
time
)
;
175
}
;
176
$element
.
append
(
html
)
;
177
}
179
var
renderHours
=
function
(
element
,
data
)
{
180
if
(
element
instanceof
jQuery
)
{
181
var
html
=
"
-
"
182
data
.
weekday_text
.
forEach
(
function
(
day
)
{
183
html
+=
"
"
+
day
+
"
"
;
184
}
)
;
185
html
+=
"
"
;
186
element
.
append
(
html
)
;
188
}
189
190
var
renderStaticMap
=
function
(
element
,
data
)
{
191
if
(
element
instanceof
jQuery
)
{
192
var
map
=
plugin
.
settings
.
staticMap
;
193
element
.
append
(
194
"
+
195
"?size="
+
map
.
width
+
"x"
+
map
.
height
+
196
"&zoom="
+
map
.
zoom
+
197
"&maptype="
+
map
.
type
+
198
"&markers=size:large%7Ccolor:red%7C"
+
data
+
"'>"
+
199
"
"
)
;
202
203
var
renderAddress
=
function
(
element
,
data
)
{
204
if
(
element
instanceof
jQuery
)
{
205
element
.
append
(
data
)
;
207
}
208
209
var
renderPhone
=
function
(
element
,
data
)
{
210
if
(
element
instanceof
jQuery
)
{
211
element
.
append
(
data
)
;
212
}
213
}
214
215
var
initRotation
=
function
(
)
{
216
var
$reviewEls
=
$element
.
children
(
'.review-item'
)
;
217
var
currentIdx
=
$reviewEls
.
length
>
?
:
false
;
218
$reviewEls
.
hide
(
)
;
219
if
(
currentIdx
!==
false
)
{
220
$
(
$reviewEls
[
currentIdx
]
)
.
show
(
)
;
222
if
(
++
currentIdx
>=
$reviewEls
.
length
)
{
223
currentIdx
=
;
224
}
225
$reviewEls
.
hide
(
)
;
226
$
(
$reviewEls
[
currentIdx
]
)
.
fadeIn
(
'slow'
)
;
227
}
,
plugin
.
settings
.
rotateTime
)
;
228
}
229
}
230
231
var
renderStars
=
function
(
rating
)
{
232
var
stars
=
"
-
"
;
234
// fill in gold stars
235
for
(
var
i
=
;
i
<
rating
;
i
++
)
{
237
}
;
238
239
// fill in empty stars
240
if
(
rating
<
5
)
{
241
for
(
var
i
=
;
i
<
(
5
-
rating
)
;
i
++
)
{
243
}
;
244
}
245
stars
=
stars
+
"
"
;
246
return
stars
;
247
}
248
249
var
renderAverageStars
=
function
(
rating
)
{
250
var
stars
=
"
- " + rating + " " ;
251
var
activeStars
=
parseInt
(
rating
)
;
252
var
inactiveStars
=
5
-
activeStars
;
253
var
width
=
(
rating
-
activeStars
)
*
100
+
'%'
;
254
255
// fill in gold stars
256
for
(
var
i
=
;
i
<
activeStars
;
i
++
)
{
257
stars
+=
"
"
;
258
}
;
259
260
// fill in empty stars
261
if
(
inactiveStars
>
)
{
262
for
(
var
i
=
;
i
<
inactiveStars
;
i
++
)
{
263
if
(
i
===
)
{
264
stars
+=
"
+
width
+
"'>
"
;
265
}
else
{
266
stars
+=
"
"
;
267
}
268
}
;
269
}
270
stars
+=
"
"
;
271
return
stars
;
272
}
273
274
var
convertTime
=
function
(
UNIX_timestamp
)
{
275
var
a
=
new
Date
(
UNIX_timestamp
*
1000
)
;
276
var
months
=
[
'Jan'
,
'Feb'
,
'Mar'
,
'Apr'
,
'May'
,
'Jun'
,
'Jul'
,
'Aug'
,
'Sep'
,
'Oct'
,
'Nov'
,
'Dec'
]
;
277
var
time
=
months
[
a
.
getMonth
(
)
]
+
' '
+
a
.
getDate
(
)
+
', '
+
a
.
getFullYear
(
)
;
278
return
time
;
279
}
304
plugin
.
init
(
)
;
306
}
307
308
$
.
fn
.
googlePlaces
=
function
(
options
)
{
309
310
return
this
.
each
(
function
(
)
{
312
var
plugin
=
new
$
.
googlePlaces
(
this
,
options
)
;
314
}
315
}
)
;
316
317
}
318