web/tagging/tagtool.js
author clebeaupin
Fri, 16 Apr 2010 11:35:35 +0200
changeset 62 ca07ccdd09d3
parent 2 65157edaee3e
permissions -rw-r--r--
Update data dump
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     1
var tagTool = {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     2
    
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     3
    // Segments: {in (ms), out (ms), tag, user}
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     4
    segments: Array(),
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     5
    currentTags: Array(),
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     6
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     7
    tagContainer: "",
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     8
    player: false,
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
     9
    showTagInPage: true,
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    10
    showTagInPlayer: true,
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    11
    stopOnSegment: false,
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    12
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    13
    playSegment: function(seg, pause) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    14
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    15
        if (pause == "on")
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    16
            this.stopOnSegment = this.segments[seg].sout;
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    17
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    18
        this.player.seek(this.segments[seg].sin / 1000);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    19
    },
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    20
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    21
    displayTags: function() {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    22
                
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    23
        if (this.showTagInPage) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    24
            taglist=$('<ul></ul>');
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    25
            for (tag in this.currentTags)
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    26
                $('<li>' + this.currentTags[tag] + '</li>').appendTo(taglist);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    27
            $(this.tagContainer).html(taglist);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    28
        }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    29
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    30
        if (this.showTagInPlayer) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    31
            if (this.currentTags.length == 0)
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    32
                this.player.getPlugin('content').fadeOut();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    33
            else {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    34
                line = '<p>' + this.currentTags.join('<br>') + '</p>';
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    35
                this.player.getPlugin('content').animate({height: 15*(this.currentTags.length + 1) + 'px'});
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    36
                this.player.getPlugin('content').setHtml(line).fadeIn();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    37
            }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    38
        }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    39
    },
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    40
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    41
    addTag: function(tag) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    42
        this.currentTags.push(tag);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    43
        this.displayTags();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    44
    },
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    45
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    46
    removeTag: function(tag) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    47
        this.currentTags.splice(this.currentTags.indexOf(tag), 1);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    48
        this.displayTags();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    49
    },
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    50
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    51
    rebuildCurrentTags: function(position) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    52
        this.currentTags = new Array();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    53
        for (seg in this.segments) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    54
            if (this.segments[seg].sin < position && this.segments[seg].sout > position) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    55
                this.currentTags.push(this.segments[seg].tag);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    56
            }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    57
        }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    58
        this.displayTags();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    59
    },
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    60
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    61
    setupHandlers: function(player) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    62
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    63
        cuepoints = new Array();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    64
        for (seg in this.segments) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    65
            cuepoint = {time: this.segments[seg].sin, tag: this.segments[seg].tag};
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    66
            cuepoints.push(cuepoint);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    67
            cuepoint = {time: this.segments[seg].sout, tag: this.segments[seg].tag, out: 'true'};
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    68
            cuepoints.push(cuepoint);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    69
        }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    70
        player.onCuepoint(cuepoints, function(clip, cuepoint) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    71
            if (cuepoint.out) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    72
                tagTool.removeTag(cuepoint.tag);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    73
                if (tagTool.stopOnSegment == cuepoint.time) {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    74
                    this.pause();
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    75
                    tagTool.stopOnSegment = false;
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    76
                }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    77
            } else {
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    78
                tagTool.addTag(cuepoint.tag);
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    79
            }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    80
        });
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    81
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    82
    }
65157edaee3e Tagging proof of concept
Boris de Laage <bdelaage@universcine.com>
parents:
diff changeset
    83
}