src/widgets/Social.js
author cavaliet
Thu, 02 Jan 2014 16:40:25 +0100
branchnew-model
changeset 1019 3ab36f402b0c
parent 927 977a39c4ee80
child 1020 198c2b79f5e1
permissions -rw-r--r--
update widgets after enhance in annotation platform.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     1
// TODO: Open share links in a small window
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     2
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     3
IriSP.Widgets.Social = function(player, config) {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     4
    IriSP.Widgets.Widget.call(this, player, config);
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
     5
    ZeroClipboard.setMoviePath( IriSP.getLib('zeroClipboardSwf') );
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
     6
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     7
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     8
IriSP.Widgets.Social.prototype = new IriSP.Widgets.Widget();
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     9
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    10
IriSP.Widgets.Social.prototype.defaults = {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    11
    text: "",
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    12
    url: "",
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    13
    show_url: true,
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    14
    show_twitter: true,
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    15
    show_fb: true,
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    16
    show_gplus: true,
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    17
    show_mail: true
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    18
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    19
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    20
IriSP.Widgets.Social.prototype.template =
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    21
    '<span class="Ldt-Social">{{#show_url}}<div class="Ldt-Social-Url-Container"><a href="#" draggable="true" target="_blank" class="Ldt-Social-Square Ldt-Social-Url Ldt-TraceMe" title="{{l10n.share_link}}">'
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    22
    + '</a><div class="Ldt-Social-UrlPop"><input class="Ldt-Social-Input"/><div class="Ldt-Social-CopyBtn">{{l10n.copy}}</div></div></div>{{/show_url}}'
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    23
    + '{{#show_fb}}<a href="#" target="_blank" class="Ldt-Social-Fb Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Facebook"></a>{{/show_fb}}'
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    24
    + '{{#show_twitter}}<a href="#" target="_blank" class="Ldt-Social-Twitter Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Twitter"></a>{{/show_twitter}}'
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    25
    + '{{#show_gplus}}<a href="#" target="_blank" class="Ldt-Social-Gplus Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Google+"></a>{{/show_gplus}}'
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    26
    + '{{#show_mail}}<a href="#" target="_blank" class="Ldt-Social-Mail Ldt-TraceMe" title="{{l10n.share_mail}}"></a>{{/show_mail}}</span>';
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    27
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    28
IriSP.Widgets.Social.prototype.messages = {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    29
    "fr": {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    30
        share_on: "Partager sur",
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    31
        share_mail: "Envoyer par courriel",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    32
        share_link: "Partager le lien hypertexte",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    33
        copy: "Copier"
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    34
    },
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    35
    "en" : {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    36
        share_on: "Share on",
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    37
        share_mail: "Share by e-mail",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    38
        share_link: "Share hypertext link",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    39
        copy: "Copy"
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    40
    }
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    41
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    42
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    43
IriSP.Widgets.Social.prototype.draw = function() {
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    44
    this.renderTemplate();
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    45
    this.clipId = IriSP._.uniqueId("Ldt-Social-CopyBtn-");
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    46
    this.$.find(".Ldt-Social-CopyBtn").attr("id", this.clipId);
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    47
    var _this = this;
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    48
    this.$.find(".Ldt-Social-Url").click(function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    49
        _this.toggleCopy();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    50
        return false;
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    51
    }).on("dragstart", function(e) {
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    52
    	e.originalEvent.dataTransfer.setData("text/x-iri-title",_this.text);
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    53
    	e.originalEvent.dataTransfer.setData("text/x-iri-uri",_this.url);
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    54
    });
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    55
    this.$.find(".Ldt-Social-Input").focus(function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    56
        this.select();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    57
    });
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    58
    this.$.find(".Ldt-Social-Ext").click(function() {
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    59
        window.open(
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    60
            IriSP.jQuery(this).attr("href"),
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    61
            "_blank",
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    62
            "height=300,width=450,left=100,top=100,toolbar=0,menubar=0,status=0,location=0");
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    63
        return false;
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    64
    });
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    65
    this.updateUrls(this.url, this.text);
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    66
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    67
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    68
IriSP.Widgets.Social.prototype.toggleCopy = function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    69
    var _pop = this.$.find(".Ldt-Social-UrlPop");
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    70
    _pop.toggle();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    71
    if (_pop.is(":visible")) {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    72
        if (typeof this.clip == "undefined") {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    73
            this.clip = new ZeroClipboard.Client();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    74
            this.clip.setHandCursor( true );
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    75
            this.clip.glue(this.clipId);
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    76
            var _this = this;
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    77
            this.clip.addEventListener( 'onMouseUp', function() {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    78
                _pop.hide();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    79
                _this.clip.hide();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    80
            });
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    81
        }
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    82
        this.clip.show();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    83
        this.clip.setText( this.url );
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    84
        this.$.find(".Ldt-Social-Input").val(this.url).focus();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    85
    } else {
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    86
        this.clip.hide();
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    87
    }
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    88
};
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    89
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    90
IriSP.Widgets.Social.prototype.updateUrls = function(_url, _text) {
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    91
    this.url = _url;
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    92
    this.text = _text;
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    93
    this.$.find(".Ldt-Social-Fb").attr("href", "http://www.facebook.com/share.php?" + IriSP.jQuery.param({ u: _url, t: _text }));
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    94
    this.$.find(".Ldt-Social-Twitter").attr("href", "https://twitter.com/intent/tweet?" + IriSP.jQuery.param({ url: _url, text: _text }));
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    95
    this.$.find(".Ldt-Social-Gplus").attr("href", "https://plus.google.com/share?" + IriSP.jQuery.param({ url: _url, title: _text }));
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    96
    this.$.find(".Ldt-Social-Mail").attr("href", "mailto:?" + IriSP.jQuery.param({ subject: _text, body: _text + ": " + _url }));
1019
3ab36f402b0c update widgets after enhance in annotation platform.
cavaliet
parents: 927
diff changeset
    97
};