integration/js/tangle.js
changeset 28 a0a048ff33a1
parent 25 ab966883a458
child 63 55b26d1c32ef
--- a/integration/js/tangle.js	Tue May 21 17:41:57 2013 +0200
+++ b/integration/js/tangle.js	Wed May 22 17:09:59 2013 +0200
@@ -6,16 +6,15 @@
         tangleHasMoved;
     
     $('.chapter-widget-info').on('mousedown', '.time-tangle', function(evt){
-   // $(".time-tangle").mousedown(function(evt) {
-
         activeTangle = $(this);
         activeTangle.addClass("active");
         tangleStartVal = +activeTangle.attr("data-milliseconds");
         tangleStartX = evt.pageX;
         tangleHasMoved = false;
-        $(this).siblings(".time-tangle").addClass("deactivate");
+        $(this).parents('td').siblings('td').find(".time-tangle").addClass("deactivate");
         return false;
     });
+
     $(document)
         .mousemove(function(evt) {
             if (activeTangle) {
@@ -27,23 +26,77 @@
         })
         .mouseup(function() {
             if (activeTangle) {
-                activeTangle.text(activeTangle.text().replace(/\.\d+$/,''));
                 $(".time-tangle").removeClass("active deactivate");
                 activeTangle = undefined;
             }
         });
+
+    function updateRenderChapter(chapterData){
+        var segment = $('.chapter-segments li#'+chapterData.id),
+            wChapterSegmentWrap = $('.chapter-segments').width(),
+            wSegmentNew = Math.floor(chapterData.getDuration() * wChapterSegmentWrap / myMedia.duration),
+            row = $('#row-list-chapter-'+chapterData.id),
+            form = ($('#form-chapter-edit-'+chapterData.id).length) ? $('#form-chapter-edit-'+chapterData.id) : false;
+
+        segment.width(wSegmentNew);
+
+        row.find('.begin').text(chapterData.begin);
+        row.find('.duration').text(chapterData.getDuration());
+        row.find('.end').text(chapterData.end);
+
+        if(form){
+            form.find('.begin').text(chapterData.begin);
+            form.find('.begin').attr('data-milliseconds',chapterData.begin);
+            form.find('.duration').text(chapterData.getDuration());
+            form.find('.end').text(chapterData.end);
+            form.find('.end').attr('data-milliseconds',chapterData.end);
+        }
+    }
+
+    function updateChapterDuration(val, chapterBefore, chapterAfter){
+        if (val<chapterAfter.end && val>chapterBefore.begin) {
+            chapterAfter.setBegin(val);
+            chapterBefore.setEnd(val);
+
+            updateRenderChapter(chapterAfter);
+            updateRenderChapter(chapterBefore);
+        }
+    }
+
+    $('.chapter-widget-info').on('valuechange', '.tangle-start', function(evt, val){
+        var indexChapter = _.indexOf(chapters, currentChapter);
+        if(indexChapter == 0 || chapters.length<=1) return;
         
+        var chapterBefore = chapters[indexChapter-1],
+            chapterAfter = currentChapter;
+
+        updateChapterDuration(val, chapterBefore, chapterAfter);
+    });
+
+    $('.chapter-widget-info').on('valuechange', '.tangle-end', function(evt, val){
+        var indexChapter = _.indexOf(chapters, currentChapter);
+        if(indexChapter == chapters.length-1 || chapters.length<=1) return;
+        
+        var chapterAfter = chapters[indexChapter+1],
+            chapterBefore = currentChapter;
+        
+        updateChapterDuration(val, chapterBefore, chapterAfter);
+    });
+    /*
     $(".tangle-start")
         .mouseup(function(evt) {
+
             if (!tangleHasMoved && currentMedia && currentSegment) {
                 currentMedia.setCurrentTime(currentSegment.begin);
             }
         })
         .on("valuechange", function(evt, val) {
+
             if (currentMedia && currentSegment) {
                 currentSegment.setBegin(val);
             }
         });
+
     $(".tangle-end")
         .mouseup(function(evt) {
             if (!tangleHasMoved && currentMedia && currentSegment) {
@@ -59,4 +112,5 @@
         if (currentMedia && currentSegment) {
             currentSegment.setDuration(val);
         }
-    });
\ No newline at end of file
+       
+    }); */
\ No newline at end of file