-
Notifications
You must be signed in to change notification settings - Fork 2
/
gtm.js
105 lines (83 loc) · 3.05 KB
/
gtm.js
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
function wp_media_link(link_text, image_post_id) {
return "<A href='" + wp_media_url(image_post_id) + "' target='_blank'>" + link_text + "</A>";
}
function wp_media_url(image_post_id) {
// return "/wp-admin/upload.php?item=" + image_post_id + "&mode=grid";
return "/wp-admin/post.php?post=" + image_post_id + "&action=edit";
}
function gtm_action_link(action, text, params) {
pkv = [];
for (key in params) {
val = params[key];
pkv.push(key + '=' + encodeURIComponent(val));
}
qstr = pkv.join('&');
// return "<A href='/wp-admin/post.php?&action=' + action + (qstr ? ("&" + qstr) : "") + "' target='_blank'>" + text + "</A>";
return "<A href='/wp-admin/upload.php?page=gtm&action=" + action + (qstr ? ("&" + qstr) : "") + "' target='_blank'>" + text + "</A>";
}
function mst_render(id,vars) {
var tmpl_script = jQuery('head').find(id).html();
return Mustache.render(tmpl_script, vars);
}
function mst_render_html(id,vars){
var tmpl_script = $('head').find(id).html();
console.log(tmpl_script);
return Mustache.to_html(tmpl_script, vars);
}
function isAdmin() {
return location.href.indexOf('wp-admin') > -1;
}
function gtmOverlayModalIframe(url) {
$('body').append(mst_render('#mst_overlay_modal_iframe', {url: url}));
_overlayModaljQueryUIdialog('#overlay_modal');
}
function _overlayModaljQueryUIdialog(selector) {
jQuery(selector).dialog({
width: 0.95 * document.body.clientWidth,
height: document.body.clientHeight,
modal: true
}
);
}
function gtmOverlayModal(html) {
jQuery('body').append(mst_render('#mst_overlay_modal', {html: html}));
_overlayModaljQueryUIdialog('#overlay_modal');
}
function initMustacheTemplates() {
jQuery.get("/wp-content/plugins/geotagged-media/gtm.mst", {}).success(function (response) {
console.log("Mustache templates file loaded!");
mustache_tmpl = jQuery.parseHTML(response, document, true);
jQuery('head').append(mustache_tmpl);
});
}
function gtmOverlayModalUrl(url) {
jQuery.get(url).success(function (resp) {
console.log('gtm_html_url response', resp);
gtmOverlayModal(resp);
});
}
function moveToNewCenter(map, lat, long) {
console.log('moveToNewCenter', map, lat, long);
var res = map.getView().getResolution();
var coordinates = [parseFloat(long), parseFloat(lat)];
var projected = ol.proj.fromLonLat(coordinates);
var view = map.getView();
console.log('view', view);
console.log('getLayers', map.getLayers());
view.animate({
center: projected,
duration: 50
});
}
function initDismissableButtonAction() {
jQuery(document).on('click', '#gtm_activation_notice .notice-dismiss', function (evt) {
console.log('Clicked dismiss!');
jQuery.get(ajaxurl + "?action=dismiss_activation_notice")
.success(function (response) {
console.log('dismisson_activation_notice', response);
});
});
}
function isMapDrawn() {
return jQuery('canvas').length > 0;
}