Retour à la documentation
/**
* @class spw.widgets.SpwShareMap
*/
define(["dojo/_base/declare", "spw/api/SpwBaseTemplatedWidget", "dojo/_base/lang",
"spw/api/StateManager", "dojo/i18n!./nls/SpwQuerySearch", "dojo/text!./templates/SpwShareMap.html",
"dojo/query","dojo/mouse","dojo/dom-construct","dojo/_base/array","dojo/on", "dijit/Dialog",
"dijit/form/TextBox", "dijit/form/Button","http://w.sharethis.com/button/buttons.js", "dojo/NodeList-traverse"],
function(declare, SpwBaseTemplatedWidget, lang,
StateManager, labels, template,
query,mouse,construct,array,on, Dialog){
return declare("spw.widgets.SpwShareMap", [SpwBaseTemplatedWidget], /** @lends spw.widgets.SpwShareMap.prototype */{
templateString: template,
labels: labels,
iconClass:"ShareMapIcon",
buttonType: 'chicklet',
mailSubject: null,
mailBody: null,
_shareButtons : null,
/**
* @constructs
* @param config
*/
constructor: function(){
if(stLight)
stLight.options({publisher: "9eee3fe5-6b70-4220-880c-a3068e89b6d9",onhover:false});
},
postCreate: function(){
this.inherited(arguments);
},
startup: function(){
this.inherited(arguments);
},
onActivate: function(){
this.inherited(arguments);
if(!this._shareButtons){
this._shareButtons = {};
if(this.sharingButtons){
var shareButtonsZone = null;
var shareButtonsTable = query("#shareButtonsTable")[0];
if(!this.orientation || this.orientation=="horizontal")
{
construct.create("tr",{id:"shareButtonsTR"},shareButtonsTable);
shareButtonsZone = query("#shareButtonsTR")[0];
}
array.forEach(this.sharingButtons,lang.hitch(this,function(service,idx){
var parentElement = null;
if(this.orientation && this.orientation=="vertical")
{
construct.create("tr",{id:"shareButtonsTR"+idx},shareButtonsTable);
parentElement = query("#shareButtonsTR"+idx)[0];
}
else{
parentElement = shareButtonsZone;
}
var identifier = "shareButton"+idx;
this._shareButtons[identifier] = new Object();
this._shareButtons[identifier].service = service;
construct.create("td",{id:identifier+"td"},parentElement);
var td = query("#"+identifier+"td")[0];
on(td,mouse.enter,lang.hitch(this,this._enterButton));
construct.create("span",{id:identifier+"span","class":"shareButton","st_via":"Geoviewer SPW","st_title":""},td);
this._shareButtons[identifier].shareButtonSpan = query("#"+identifier+"span");
this.createShareThisButton(identifier);
}));
}
}
},
_enterButton: function(evt){
if(evt.target.id.indexOf("shareButton") == 0){
var identifier = evt.currentTarget.id.substring(0, evt.currentTarget.id.length - 2);
if(this._shareButtons[identifier].shareButtonSpan.children()[0])
this._shareButtons[identifier].shareButtonSpan.children()[0].remove();
this.createShareThisButton(identifier);
}
},
createShareThisButton: function(identifier){
if(this._shareButtons[identifier].service == 'mailto'){
var subject = this.mailSubject ? this.mailSubject : "Geoviewer SPW";
var body = this.mailBody ? this.mailBody.replace("${URL}", StateManager.getInstance().getCompleteUrl()) : StateManager.getInstance().getCompleteUrl();
var btnNode = construct.toDom(
'<span style="text-decoration:none;color:#000000;display:inline-block;cursor:pointer;" class="stButton">'+
'<a href="mailto:?subject='+subject+'&body='+ body +'">'+
'<span class="'+ (this.buttonType == 'large' ? 'stLarge' : 'chicklets') + '" style="background-image: url(http://w.sharethis.com/images/email_'+ (this.buttonType == 'large' ? 32 : 16) + '.png);"></span>'+
'<img src="http://w.sharethis.com/images/check-big.png" style="position: absolute; top: -7px; right: -7px; width: 19px; height: 19px; max-width: 19px; max-height: 19px; display: none;" />'+
'</a>'+
'</span>');
construct.place(btnNode, document.getElementById(identifier+"span"));
} else if(this._shareButtons[identifier].service == 'link'){
var btnNode = construct.toDom(
'<span style="text-decoration:none;color:#000000;display:inline-block;cursor:pointer;" class="stButton">'+
'<a href="javascript:void(0);">'+
'<span class="'+ (this.buttonType == 'large' ? 'stLarge' : 'chicklets') + '" style="background-image: url('+this.imagesPath+'url_view_'+ (this.buttonType == 'large' ? 32 : 16) + '.png);"></span>'+
'<img src="http://w.sharethis.com/images/check-big.png" style="position: absolute; top: -7px; right: -7px; width: 19px; height: 19px; max-width: 19px; max-height: 19px; display: none;" />'+
'</a>'+
'</span>');
on(btnNode, 'click', lang.hitch(this, this.showUrlDialog));
construct.place(btnNode, document.getElementById(identifier+"span"));
} else {
stWidget.addEntry({
"service":this._shareButtons[identifier].service,
"element": document.getElementById(identifier+"span"),
"url":StateManager.getInstance().getCompleteUrl(),
"title":"Geoviewer",
"type":this.buttonType,
"text":""
});
}
},
showUrlDialog: function(){
new Dialog({ title: "Url partagée", content: "<div style='width:400px;max-height:125px;word-break:break-all;overflow:auto;'><a target='_blank' href='"+StateManager.getInstance().getCompleteUrl()+"'>"+StateManager.getInstance().getCompleteUrl()+"</a></div>"}).show();
}
});
});