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