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