src/widgets/Tweet.js
changeset 1013 392ddcd212d7
parent 1002 a86208b60c91
child 1072 ac1eacb3aa33
equal deleted inserted replaced
1012:7e18d953a1f8 1013:392ddcd212d7
    25             "color" : "#05aae6"
    25             "color" : "#05aae6"
    26         }
    26         }
    27     ],
    27     ],
    28     annotation_type: "tweet",
    28     annotation_type: "tweet",
    29     pin_at_start: false
    29     pin_at_start: false
    30 }
    30 };
    31 
    31 
    32 IriSP.Widgets.Tweet.prototype.messages = {
    32 IriSP.Widgets.Tweet.prototype.messages = {
    33     "fr": {
    33     "fr": {
    34         retweet: "Retweeter",
    34         retweet: "Retweeter",
    35         reply: "Répondre",
    35         reply: "Répondre",
    48         close_widget: "Close tweet display",
    48         close_widget: "Close tweet display",
    49         original_time: "Tweet sent at: ",
    49         original_time: "Tweet sent at: ",
    50         video_time: "Video time: ",
    50         video_time: "Video time: ",
    51         show_original: "Show original"
    51         show_original: "Show original"
    52     }
    52     }
    53 }
    53 };
    54 
    54 
    55 IriSP.Widgets.Tweet.prototype.template =
    55 IriSP.Widgets.Tweet.prototype.template =
    56     '<div class="Ldt-Tweet-Widget"><div class="Ldt-Tweet-Inner"><div class="Ldt-Tweet-PinClose-Buttons">'
    56     '<div class="Ldt-Tweet-Widget"><div class="Ldt-Tweet-Inner"><div class="Ldt-Tweet-PinClose-Buttons">'
    57     + '<a href="#" class="Ldt-Tweet-Pin Ldt-TraceMe{{#pin_at_start}} active" title="{{l10n.dont_keep_visible}}{{/pin_at_start}}{{^pin_at_start}}" title="{{l10n.keep_visible}}{{/pin_at_start}}"></a>'
    57     + '<a href="#" class="Ldt-Tweet-Pin Ldt-TraceMe{{#pin_at_start}} active" title="{{l10n.dont_keep_visible}}{{/pin_at_start}}{{^pin_at_start}}" title="{{l10n.keep_visible}}{{/pin_at_start}}"></a>'
    58     + '<a href="#" class="Ldt-Tweet-Close Ldt-TraceMe" title="{{l10n.close_widget}}"></a>'
    58     + '<a href="#" class="Ldt-Tweet-Close Ldt-TraceMe" title="{{l10n.close_widget}}"></a>'
    69     this.renderTemplate();
    69     this.renderTemplate();
    70     this.pinned = this.pin_at_start;
    70     this.pinned = this.pin_at_start;
    71     var _this = this;
    71     var _this = this;
    72     this.$.find(".Ldt-Tweet-Pin").click(function() {
    72     this.$.find(".Ldt-Tweet-Pin").click(function() {
    73         _this.pinned = !_this.pinned;
    73         _this.pinned = !_this.pinned;
    74         var _el = IriSP.jQuery(this)
    74         var _el = IriSP.jQuery(this);
    75         if (_this.pinned) {
    75         if (_this.pinned) {
    76             _el.addClass("active").attr("title",_this.l10n.dont_keep_visible);
    76             _el.addClass("active").attr("title",_this.l10n.dont_keep_visible);
    77             _this.cancelTimeout();
    77             _this.cancelTimeout();
    78         } else {
    78         } else {
    79             _el.removeClass("active").attr("title",_this.l10n.keep_visible);
    79             _el.removeClass("active").attr("title",_this.l10n.keep_visible);
    87     this.getWidgetAnnotations().forEach(function(_annotation) {
    87     this.getWidgetAnnotations().forEach(function(_annotation) {
    88         _annotation.on("click", function() {
    88         _annotation.on("click", function() {
    89             _this.show(_annotation);
    89             _this.show(_annotation);
    90         });
    90         });
    91     });
    91     });
    92 }
    92 };
    93 
    93 
    94 IriSP.Widgets.Tweet.prototype.show = function(_tweet) {
    94 IriSP.Widgets.Tweet.prototype.show = function(_tweet) {
    95     if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") {
    95     if (typeof _tweet !== "undefined" && typeof _tweet.source !== "undefined") {
    96         var extend = [
    96         var extend = [
    97             [
    97             [
    98                 /#(\w+)/gm,
    98                 /#(\w+)/gm,
    99                 function(matches) {
    99                 function(matches) {
   100                     return '<a href="http://twitter.com/search?q=%23' + matches[1] + '" target="_blank">'
   100                     return '<a href="http://twitter.com/search?q=%23' + matches[1] + '" target="_blank">';
   101                 },
   101                 },
   102                 '</a>'
   102                 '</a>'
   103             ]
   103             ]
   104         ];
   104         ];
   105         var _urls = IriSP._(_tweet.source.entities.urls).sortBy(function(_entity) {
   105         var _urls = IriSP._(_tweet.source.entities.urls).sortBy(function(_entity) {
   145             this.hideTimeout();
   145             this.hideTimeout();
   146         }
   146         }
   147     } else {
   147     } else {
   148         this.hide();
   148         this.hide();
   149     }
   149     }
   150 }
   150 };
   151 
   151 
   152 IriSP.Widgets.Tweet.prototype.hide = function() {
   152 IriSP.Widgets.Tweet.prototype.hide = function() {
   153     this.player.trigger("Annotation.maximize");
   153     this.player.trigger("Annotation.maximize");
   154     this.$.slideUp();
   154     this.$.slideUp();
   155     this.cancelTimeout();
   155     this.cancelTimeout();
   156 }
   156 };
   157 
   157 
   158 IriSP.Widgets.Tweet.prototype.cancelTimeout = function() {
   158 IriSP.Widgets.Tweet.prototype.cancelTimeout = function() {
   159     if (typeof this.hide_timer !== "undefined") {
   159     if (typeof this.hide_timer !== "undefined") {
   160         window.clearTimeout(this.hide_timer);
   160         window.clearTimeout(this.hide_timer);
   161         this.hide_timer = undefined;
   161         this.hide_timer = undefined;
   162     }  
   162     }  
   163 }
   163 };
   164 
   164 
   165 IriSP.Widgets.Tweet.prototype.hideTimeout = function() {
   165 IriSP.Widgets.Tweet.prototype.hideTimeout = function() {
   166     this.cancelTimeout();
   166     this.cancelTimeout();
   167     this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout);
   167     this.hide_timer = window.setTimeout(this.functionWrapper("hide"), this.hide_timeout);
   168 }
   168 };