src/widgets/Social.js
author ymh <ymh.work@gmail.com>
Wed, 04 Sep 2024 17:32:50 +0200
changeset 1072 ac1eacb3aa33
parent 1071 02c04d2c8fd8
permissions -rw-r--r--
Migrate source and build to vite.js
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
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     2
import _ from "lodash";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     3
import jQuery from "jquery";
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     4
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     5
import socialStyles from "./Social.module.css";
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
     6
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     7
const Social = function (ns) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     8
  return class extends ns.Widgets.Widget {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
     9
    constructor(player, config) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    10
      super(player, config);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    11
    }
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    12
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    13
    static defaults = {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    14
      text: "",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    15
      url: "",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    16
      show_url: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    17
      show_twitter: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    18
      show_fb: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    19
      show_gplus: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    20
      show_mail: true,
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    21
    };
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    22
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    23
    static template =
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    24
      '<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}}">' +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    25
      '</a><div class="Ldt-Social-UrlPop"><input class="Ldt-Social-Input"/></div></div>{{/show_url}}' +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    26
      '{{#show_fb}}<a href="#" target="_blank" class="Ldt-Social-Fb Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Facebook"></a>{{/show_fb}}' +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    27
      '{{#show_twitter}}<a href="#" target="_blank" class="Ldt-Social-Twitter Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Twitter"></a>{{/show_twitter}}' +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    28
      '{{#show_gplus}}<a href="#" target="_blank" class="Ldt-Social-Gplus Ldt-Social-Ext Ldt-TraceMe" title="{{l10n.share_on}} Google+"></a>{{/show_gplus}}' +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    29
      '{{#show_mail}}<a href="#" target="_blank" class="Ldt-Social-Mail Ldt-TraceMe" title="{{l10n.share_mail}}"></a>{{/show_mail}}</span>';
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    30
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    31
    static messages =  {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    32
      fr: {
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    33
        share_on: "Partager sur",
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    34
        share_mail: "Envoyer par courriel",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    35
        share_link: "Partager le lien hypertexte",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    36
        copy: "Copier",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    37
      },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    38
      en: {
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    39
        share_on: "Share on",
927
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    40
        share_mail: "Share by e-mail",
977a39c4ee80 Added URL Copy function to the Social Widget
veltr
parents: 924
diff changeset
    41
        share_link: "Share hypertext link",
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    42
        copy: "Copy",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    43
      },
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    44
    };
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    45
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    46
    draw() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    47
      this.renderTemplate();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    48
      this.clipId = _.uniqueId("Ldt-Social-CopyBtn-");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    49
      this.$.find(".Ldt-Social-CopyBtn").attr("id", this.clipId);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    50
      var _this = this;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    51
      this.$.find(".Ldt-Social-Url")
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    52
        .click(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    53
          _this.toggleCopy();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    54
          return false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    55
        })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    56
        .on("dragstart", function (e) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    57
          e.originalEvent.dataTransfer.setData("text/x-iri-title", _this.text);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    58
          e.originalEvent.dataTransfer.setData("text/x-iri-uri", _this.url);
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    59
        });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    60
      this.$.find(".Ldt-Social-Input").focus(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    61
        this.select();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    62
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    63
      this.$.find(".Ldt-Social-Ext").click(function () {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    64
        window.open(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    65
          jQuery(this).attr("href"),
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    66
          "_blank",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    67
          "height=300,width=450,left=100,top=100,toolbar=0,menubar=0,status=0,location=0"
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    68
        );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    69
        return false;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    70
      });
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    71
      this.updateUrls(this.url, this.text);
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
    72
    }
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    73
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    74
    toggleCopy() {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    75
      var _pop = this.$.find(".Ldt-Social-UrlPop");
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    76
      _pop.toggle();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    77
      this.$.find(".Ldt-Social-Input").val(this.url).focus();
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    78
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    79
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    80
    updateUrls(_url, _text) {
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    81
      this.url = _url;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    82
      this.text = _text;
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    83
      this.$.find(".Ldt-Social-Fb").attr(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    84
        "href",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    85
        "http://www.facebook.com/share.php?" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    86
          jQuery.param({ u: _url, t: _text })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    87
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    88
      this.$.find(".Ldt-Social-Twitter").attr(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    89
        "href",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    90
        "https://twitter.com/intent/tweet?" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    91
          jQuery.param({ url: _url, text: _text })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    92
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    93
      this.$.find(".Ldt-Social-Gplus").attr(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    94
        "href",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    95
        "https://plus.google.com/share?" +
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    96
          jQuery.param({ url: _url, title: _text })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    97
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    98
      this.$.find(".Ldt-Social-Mail").attr(
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
    99
        "href",
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
   100
        "mailto:?" + jQuery.param({ subject: _text, body: _text + ": " + _url })
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
   101
      );
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
   102
    }
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
   103
  };
1013
392ddcd212d7 Throwed in a bunch of semicolons
veltr
parents: 993
diff changeset
   104
};
924
64c2eaafe5e2 Modifications for LDT-Platform
veltr
parents:
diff changeset
   105
1072
ac1eacb3aa33 Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents: 1071
diff changeset
   106
export { Social, socialStyles };