web/res/metadataplayer/Social.js
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Mon, 15 Oct 2012 17:08:27 +0200
changeset 697 41c0587ec73f
parent 694 e9400c80e1e4
child 719 d0d3a9369f84
permissions -rw-r--r--
add iri as partner
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     1
// TODO: Open share links in a small window
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     2
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     3
IriSP.Widgets.Social = function(player, config) {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     4
    IriSP.Widgets.Widget.call(this, player, config);
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
     5
    ZeroClipboard.setMoviePath( IriSP.getLib('zeroClipboardSwf') );
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     6
}
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     7
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     8
IriSP.Widgets.Social.prototype = new IriSP.Widgets.Widget();
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     9
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    10
IriSP.Widgets.Social.prototype.defaults = {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    11
    text: "",
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    12
    url: "",
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    13
    show_url: true,
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    14
    show_twitter: true,
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    15
    show_fb: true,
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    16
    show_gplus: true,
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    17
    show_mail: true
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    18
}
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    19
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    20
IriSP.Widgets.Social.prototype.template =
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    21
    '<span class="Ldt-Social">{{#show_url}}<div class="Ldt-Social-Url-Container"><a href="#" target="_blank" class="Ldt-Social-Square Ldt-Social-Url Ldt-TraceMe" title="{{l10n.share_link}}">'
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
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}}'
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    23
    + '{{#show_fb}}<a href="#" target="_blank" class="Ldt-Social-Fb Ldt-TraceMe" title="{{l10n.share_on}} Facebook"></a>{{/show_fb}}'
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    24
    + '{{#show_twitter}}<a href="#" target="_blank" class="Ldt-Social-Twitter Ldt-TraceMe" title="{{l10n.share_on}} Twitter"></a>{{/show_twitter}}'
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    25
    + '{{#show_gplus}}<a href="#" target="_blank" class="Ldt-Social-Gplus Ldt-TraceMe" title="{{l10n.share_on}} Google+"></a>{{/show_gplus}}'
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    26
    + '{{#show_mail}}<a href="#" target="_blank" class="Ldt-Social-Mail Ldt-TraceMe" title="{{l10n.share_mail}}"></a>{{/show_mail}}</span>';
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    27
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    28
IriSP.Widgets.Social.prototype.messages = {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    29
    "fr": {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    30
        share_on: "Partager sur",
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    31
        share_mail: "Envoyer par courriel",
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    32
        share_link: "Partager le lien hypertexte",
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    33
        copy: "Copier"
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    34
    },
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    35
    "en" : {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    36
        share_on: "Share on",
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    37
        share_mail: "Share by e-mail",
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    38
        share_link: "Share hypertext link",
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    39
        copy: "Copy"
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    40
    }
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    41
}
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    42
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    43
IriSP.Widgets.Social.prototype.draw = function() {
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    44
    this.renderTemplate();
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    45
    this.clipId = IriSP._.uniqueId("Ldt-Social-CopyBtn-");
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    46
    this.$.find(".Ldt-Social-CopyBtn").attr("id", this.clipId);
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    47
    var _this = this;
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    48
    this.$.find(".Ldt-Social-Url").click(function() {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    49
        _this.toggleCopy();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    50
        return false;
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    51
    });
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    52
    this.$.find(".Ldt-Social-Input").focus(function() {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    53
        this.select();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    54
    });
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    55
    this.updateUrls(this.url, this.text);
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    56
}
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    57
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    58
IriSP.Widgets.Social.prototype.toggleCopy = function() {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    59
    var _pop = this.$.find(".Ldt-Social-UrlPop");
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    60
    _pop.toggle();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    61
    if (_pop.is(":visible")) {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    62
        if (typeof this.clip == "undefined") {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    63
            this.clip = new ZeroClipboard.Client();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    64
            this.clip.setHandCursor( true );
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    65
            this.clip.glue(this.clipId);
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    66
            var _this = this;
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    67
            this.clip.addEventListener( 'onMouseUp', function() {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    68
                _pop.hide();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    69
                _this.clip.hide();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    70
            });
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    71
        }
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    72
        this.clip.show();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    73
        this.clip.setText( this.url );
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    74
        this.$.find(".Ldt-Social-Input").val(this.url).focus();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    75
    } else {
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    76
        this.clip.hide();
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    77
    }
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    78
}
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    79
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    80
IriSP.Widgets.Social.prototype.updateUrls = function(_url, _text) {
694
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    81
    this.url = _url;
e9400c80e1e4 Updated Metadataplayer
Raphael Velt <raph.velt@gmail.com>
parents: 654
diff changeset
    82
    this.text = _text;
654
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    83
    this.$.find(".Ldt-Social-Fb").attr("href", "http://www.facebook.com/share.php?" + IriSP.jQuery.param({ u: _url, t: _text }));
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    84
    this.$.find(".Ldt-Social-Twitter").attr("href", "https://twitter.com/intent/tweet?" + IriSP.jQuery.param({ url: _url, text: _text }));
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    85
    this.$.find(".Ldt-Social-Gplus").attr("href", "https://plusone.google.com/_/+1/confirm?" + IriSP.jQuery.param({ url: _url, title: _text }));
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    86
    this.$.find(".Ldt-Social-Mail").attr("href", "mailto:?" + IriSP.jQuery.param({ subject: _text, body: _text + ": " + _url }));
a5977736d2b0 Corrected metadataplayer bug
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    87
}