loleaflet: add feedback handler
Change-Id: I8ef2c1afe4093e9ee867cd3130c82cbd93362eb9 Signed-off-by: Henry Castro <hcastro@collabora.com> Signed-off-by: Pedro Pinto Silva <pedro.silva@collabora.com>
This commit is contained in:
parent
22f06b6a5b
commit
8a9345e871
3 changed files with 55 additions and 2 deletions
|
@ -363,7 +363,8 @@ LOLEAFLET_JS_LST =\
|
|||
|
||||
if ENABLE_FEEDBACK
|
||||
LOLEAFLET_JS_LST +=\
|
||||
src/control/IFrameDialog.js
|
||||
src/control/IFrameDialog.js \
|
||||
src/map/handler/Map.Feedback.js
|
||||
endif
|
||||
|
||||
LOLEAFLET_JS_LST +=\
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- js-indent-level: 8 -*- */
|
||||
/*
|
||||
* L.Control.IFrameDialog
|
||||
* L.IFrameDialog
|
||||
*/
|
||||
|
||||
L.IFrameDialog = L.Class.extend({
|
||||
|
|
52
loleaflet/src/map/handler/Map.Feedback.js
Normal file
52
loleaflet/src/map/handler/Map.Feedback.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* -*- js-indent-level: 8 -*- */
|
||||
/*
|
||||
* L.Map.Feedback.
|
||||
*/
|
||||
|
||||
L.Map.mergeOptions({
|
||||
feedback: true,
|
||||
feedbackTimeout: 2000
|
||||
});
|
||||
|
||||
L.Map.Feedback = L.Handler.extend({
|
||||
|
||||
addHooks: function () {
|
||||
window.localStorage.setItem('WSDFeedbackEnabled', 'true');
|
||||
this._map.on('docloaded', this.onDocLoaded, this);
|
||||
L.DomEvent.on(window, 'message', this.onMessage, this);
|
||||
},
|
||||
|
||||
removeHooks: function () {
|
||||
L.DomEvent.off(window, 'message', this.onMessage, this);
|
||||
},
|
||||
|
||||
onDocLoaded: function () {
|
||||
setTimeout(L.bind(this.onFeedback, this), this._map.options.feedbackTimeout);
|
||||
},
|
||||
|
||||
onFeedback: function () {
|
||||
if (window.localStorage.getItem('WSDFeedbackEnabled')) {
|
||||
this._iframeDialog = L.iframeDialog(window.feebackLocation);
|
||||
this._iframeDialog.create();
|
||||
}
|
||||
},
|
||||
|
||||
onMessage: function (e) {
|
||||
var data = e.data;
|
||||
|
||||
if (data == 'never') {
|
||||
window.localStorage.removeItem('WSDFeedbackEnabled');
|
||||
this._iframeDialog.remove();
|
||||
} else if (data == 'later') {
|
||||
this._iframeDialog.remove();
|
||||
setTimeout(L.bind(this.onFeedback, this), this._map.options.feedbackTimeout);
|
||||
} else if (data == 'submit') {
|
||||
window.localStorage.removeItem('WSDFeedbackEnabled');
|
||||
this._iframeDialog.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (window.isLocalStorageAllowed) {
|
||||
L.Map.addInitHook('addHandler', 'feedback', L.Map.Feedback);
|
||||
}
|
Loading…
Reference in a new issue