diff options
| author | Jaysinh Shukla <jsh@openerp.com> | 2015-01-22 16:14:50 +0100 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2015-01-22 17:02:17 +0100 |
| commit | 1c91e27c8c8cb7492d26f03e27c4991b53a1675d (patch) | |
| tree | 9baff2a62a02669a12190169a08b587955c0688b /addons/website/static/src | |
| parent | 88a9a45cf20ffd8afc201f818a451bfeee8ba7d0 (diff) | |
[IMP] website: added social share widget
A new widget has been developed that allows to share content on social networks.
It is displayed like a simple share link in a popover for four social networks
(facebook, twitter, linkedin, google+ (really ?)).
Courtesy of RD India: Ajay Patel (apa@odoo.com), Jaysinh Shukla (jsh@odoo.com)
Courtesy of use Merge: Damien Bouvy (dbo@odoo.com)
Diffstat (limited to 'addons/website/static/src')
| -rw-r--r-- | addons/website/static/src/js/website.share.js | 79 | ||||
| -rw-r--r-- | addons/website/static/src/xml/website.share.xml | 15 |
2 files changed, 94 insertions, 0 deletions
diff --git a/addons/website/static/src/js/website.share.js b/addons/website/static/src/js/website.share.js new file mode 100644 index 00000000000..69742d8e93d --- /dev/null +++ b/addons/website/static/src/js/website.share.js @@ -0,0 +1,79 @@ +(function () { + 'use strict'; + + var _t = openerp._t; + var website = openerp.website; + var qweb = openerp.qweb; + website.add_template_file('/website/static/src/xml/website.share.xml'); + + website.social_share = openerp.Widget.extend({ + template: 'website.social_hover', + /** + :param element: element to bind popover + :param social_list: list of social media strings available from + ['facebook','twitter', 'linkedin', 'google-plus'] + :param hashtags: string of hashtags for twitter + */ + init: function (parent) { + this._super.apply(this, arguments); + this.element = parent; + if (parent.data('social')) { + this.social_list = (parent.data('social')).split(); + } else { + this.social_list = ['facebook','twitter', 'linkedin', 'google-plus']; + } + this.hashtags = parent.data('hashtags') || ''; + this.renderElement(); + this.bind_events(); + }, + bind_events: function () { + $('.oe_social_facebook').click($.proxy(this.renderSocial, this, 'facebook')); + $('.oe_social_twitter').click($.proxy(this.renderSocial, this, 'twitter')); + $('.oe_social_linkedin').click($.proxy(this.renderSocial, this, 'linkedin')); + $('.oe_social_google-plus').click($.proxy(this.renderSocial, this, 'google-plus')); + }, + renderElement: function () { + this.$el.append( + qweb.render('website.social_hover', {medias: this.social_list})); + //we need to re-render the element on each hover; popover has the nasty habit of not hiding but completely removing its + // code from the page + //so the binding is lost if we simply trigger on hover. + this.element.popover({ + 'content': this.$el.html(), + 'placement': 'bottom', + 'container': this.element, + 'html': true, + 'trigger': 'manual', + 'animation': false, + }).popover("show").on("mouseleave", function () { + var self = this; + setTimeout(function () { + if (! $(".popover:hover").length) { + $(self).popover("destroy"); + } + }, 200); + }); + }, + renderSocial: function(social) { + var url = document.URL.split(/[?#]/)[0]; // get current url without query string + var title = document.title.split(" | ")[0]; // get the page title without the company name + var hashtags = ' #'+ document.title.split(" | ")[1].replace(' ','') + ' ' + this.hashtags; // company name without spaces (for hashtag) + var social_network = { + 'facebook':'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url), + 'twitter': 'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(url) + '&text=' + encodeURIComponent(title + hashtags + ' - ' + url), + 'linkedin': 'https://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title), + 'google-plus': 'https://plus.google.com/share?url=' + encodeURIComponent(url) + }; + if (! _.contains(_.keys(social_network), social)) return; + var window_height = 500, window_width = 500; + window.open(social_network[social], '', 'menubar=no, toolbar=no, resizable=yes, scrollbar=yes, height=' + window_height + ',width=' + window_width); + }, + }); + + // Initialize all social_share links when ready + website.ready().done(function() { + $('.oe_social_share').mouseenter(function() { + new website.social_share($(this)); + }); + }); +})();
\ No newline at end of file diff --git a/addons/website/static/src/xml/website.share.xml b/addons/website/static/src/xml/website.share.xml new file mode 100644 index 00000000000..832dc9698a8 --- /dev/null +++ b/addons/website/static/src/xml/website.share.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<templates id="template" xml:space="preserve"> + <t t-name="website.social_hover"> + <div class="row clearfix" style='font-size:16px'> + <div class="col-xs-12 css_editable_mode_hidden"> + <t t-foreach="medias" t-as="media"> + <a style="cursor: pointer" t-attf-class="fa-stack fa-lg share #{media}"> + <span class="fa fa-square fa-stack-2x"></span> + <span t-attf-class="oe_social_#{media} fa fa-#{media} fa-stack-1x fa-inverse"></span> + </a> + </t> + </div> + </div> + </t> +</templates> |
