var $this = this;
$(document).on('click', '.share', function () {
var f = 'send' + ucfirst($(this).data('service'));
- $this[f]();
+ var url = $(this).data("url");
+ if (url == undefined || url == null || url == 'undefined') {
+ url = '';
+ }
+ $this[f](url);
$(this).closest('.mview').find('.back').click();
return false;
});
+
+ $(document).on('click touchend', '[data-action="share"]', function () {
+ $this.fluidbook.menu.openView("share", $(this).data('extra'));
+ return false;
+ });
}
}
FluidbookShare.prototype = {
isEnabled: function () {
- return this.fluidbook.datas.share && this.getShareURL() !== false;
+ return this.fluidbook.datas.share && this.getShareURL('') !== false;
+ },
+
+ getFluidbookURL: function () {
+ var l = window.location.toString();
+ var e = l.split("#");
+ return e[0];
},
- getShareURL: function () {
- var res = false;
- if (this.fluidbook.support.offline || this.fluidbook.datas.phonegap) {
- if (this.fluidbook.datas.offlineLink != '' && this.fluidbook.datas.offlineLink != 'http://') {
- res = this.fluidbook.datas.offlineLink;
+ getShareURL: function (url) {
+
+ if (url == undefined || url == 'undefined' || url == null || url == false) {
+ url = '';
+ }
+ if (url == '') {
+ var res = false;
+ if (this.fluidbook.support.offline || this.fluidbook.datas.phonegap) {
+ if (this.fluidbook.datas.offlineLink != '' && this.fluidbook.datas.offlineLink != 'http://') {
+ res = this.fluidbook.datas.offlineLink;
+ }
+ } else {
+ res = this.getFluidbookURL();
+ }
+ return res;
+ }
+
+ var e = url.split(':');
+ console.log(e);
+ if (e.length == 1) {
+ return relativeToAbsoluteURL(url);
+ } else {
+ if (e[0] == 'http' || e[0] == 'https') {
+ return url
+ } else if (e[0] == 'article') {
+ console.log(e[1]);
+ return relativeToAbsoluteURL('./p/' + this.getSEOArticle(e[1]).url);
}
+ }
+ },
+
+ getShareTitle: function (url) {
+ if (url == '') {
+ return this.fluidbook.datas.title;
} else {
- var l = window.location.toString();
- var e = l.split("#");
- res = e[0];
+ var e = url.split(':');
+ if (e[0] == 'article') {
+ return this.getSEOArticle(e[1]).title;
+ }
}
- return res;
+ return this.fluidbook.datas.title;
+ },
+
+ getSEOArticle: function (title) {
+ return this.fluidbook.datas.seoArticles[title];
},
- getShareLinks: function (hideLabels) {
+ getShareLinks: function (hideLabels, url) {
var shareLinks = {},
shareHTML = '';
+ if (url == undefined || url == 'undefined') {
+ url == '';
+ }
+
hideLabels = hideLabels || false;
if (this.fluidbook.datas.friend) {
// Generate links
for (var shareType in shareLinks) {
if (shareLinks.hasOwnProperty(shareType)) { // Ensure we don't get inherited properties
- shareHTML += '<li data-level="0"><a href="#" data-service="' + shareType + '" class="share level0">';
+ shareHTML += '<li data-level="0"><a href="#" data-service="' + shareType + '" data-url="' + url + '" class="share level0">';
shareHTML += getSpriteIcon('share-' + shareType);
if (!hideLabels) {
shareHTML += ' ' + shareLinks[shareType];
return '<ul class="chapters shareList">' + shareHTML + '</ul>';
},
- openShare: function (p1, p2, callback) {
-
+ openShare: function (url, p2, callback) {
+ console.log('open share');
var view;
+ if (url == undefined || url == null || url == 'undefined' || !url) {
+ url = '';
+ }
view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
view += '<div class="content">';
- view += this.getShareLinks();
+ view += this.getShareLinks(false, url);
view += '</div>';
;
},
- sendEmail: function () {
- window.location = 'mailto:?subject=' + encodeURIComponent(this.fluidbook.datas.title) + '&body=' + encodeURIComponent(this.fluidbook.datas.title + ' : ' + this.getShareURL());
+ sendEmail: function (url) {
+ window.location = 'mailto:?subject=' + encodeURIComponent(this.getShareTitle(url)) + '&body=' + encodeURIComponent(this.getShareTitle(url) + ' : ' + this.getShareURL(url));
this.fluidbook.stats.track(5);
},
- sendTwitter: function () {
- this.fluidbook.service.open('twitterShare', {
- url: this.getShareURL(),
- post: this.fluidbook.datas.twitter_description.replace('%title%', this.fluidbook.datas.title)
- }, 'width=650,height=400');
+ sendTwitter: function (url) {
+ var tweet = this.fluidbook.datas.twitter_description.replace('%title%', this.getShareTitle(url))
+ tweet = tweet.replace('%short%', '');
+ tweet = tweet.replace('%url%', '');
+
+ this.fluidbook.wopen('http://twitter.com/intent/tweet?source=webclient&url=' + encodeURIComponent(this.getShareURL(url)) + '&text=' + encodeURIComponent(tweet), 'share_twitter', 'width=650,height=400');
this.fluidbook.stats.track(13);
},
- sendFacebook: function () {
- this.fluidbook.service.open('facebookShare', {
- url: this.getShareURL()
- }, 'width=650,height=400');
+ sendFacebook: function (url) {
+ this.fluidbook.wopen('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(this.getShareURL(url)), 'share_facebook', 'width=650,height=400');
this.fluidbook.stats.track(12);
},
- sendGoogleplus: function () {
- this.fluidbook.service.open('googleplusShare', {
- url: this.getShareURL()
- }, 'width=650,height=400');
+ sendGoogleplus: function (url) {
+ this.fluidbook.wopen('https://plus.google.com/share?url=' + encodeURIComponent(this.getShareURL(url)), 'share_googleplus', 'width=600,height=600');
this.fluidbook.stats.track(12);
},
- sendLinkedin: function () {
- this.fluidbook.service.open('linkedinShare', {
- url: this.getShareURL()
- }, 'width=650,height=400');
+ sendLinkedin: function (url) {
+ this.fluidbook.wopen('https://www.linkedin.com/cws/share?url=' + encodeURIComponent(this.getShareURL(url)) + '&isFramed=true&_ts=' + Date.now(), 'share_linkedin', 'width=650,height=400');
this.fluidbook.stats.track(12);
},
- sendViadeo: function () {
- this.fluidbook.service.open('viadeoShare', {
- url: this.getShareURL()
- }, 'width=650,height=400');
+ sendViadeo: function (url) {
+ this.fluidbook.wopen('http://www.viadeo.com/shareit/share/?url=' + encodeURIComponent(this.getShareURL(url)), 'share_viadeo', 'width=650,height=400');
this.fluidbook.stats.track(12);
},
};
\ No newline at end of file
function isMobile(returnTrueIfTouch) {
- if(returnTrueIfTouch==undefined){
- returnTrueIfTouch=true;
+ if (returnTrueIfTouch == undefined) {
+ returnTrueIfTouch = true;
}
var ua = navigator.userAgent;
var devices = ['iphone', 'ipad', 'ipod', 'droid', 'blackberry', 'mobile', 'htc', 'samsung', 'nokia', 'archos', 'galaxy', 'motorola', 'pad', 'tab', 'slate', 'motorola', 'symbian', 'phone', 'nintendo', 'playstation', 'touch', 'webos', 'ericsson'];
return '<svg ' + a.join(' ') + '><use xlink:href="#' + icon + '" /></svg>';
}
+function relativeToAbsoluteURL(relative) {
+ console.log(relative);
+ var link = document.createElement("a");
+ link.href = relative;
+ return link.href;
+}
+
function blur() {
if ($(":focus").length > 0) {
var tmp = document.createElement("input");
}
}
-function array_diff(a,b){
+function array_diff(a, b) {
return a.filter(function (i) {
return b.indexOf(i) < 0;
});