-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Outsource add item/reference/screenshot button.
- Loading branch information
Showing
5 changed files
with
90 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/assets/javascripts/thyme/components/add_item_button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class AddItemButton extends Component { | ||
|
||
add() { | ||
const video = thymeAttributes.video; | ||
|
||
// Event listener for addItem button | ||
this.element.addEventListener('click', function() { | ||
video.pause(); | ||
// round time down to three decimal digits | ||
const time = video.currentTime; | ||
const intTime = Math.floor(time); | ||
const roundTime = intTime + Math.floor((time - intTime) * 1000) / 1000; | ||
video.currentTime = roundTime; | ||
$.ajax(Routes.add_item_path(thymeAttributes.mediumId), { | ||
type: 'GET', | ||
dataType: 'script', | ||
data: { | ||
time: video.currentTime | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app/assets/javascripts/thyme/components/add_reference_button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class AddReferenceButton extends Component { | ||
|
||
add() { | ||
const video = thymeAttributes.video; | ||
|
||
// Event listener for addItem button | ||
this.element.addEventListener('click', function() { | ||
video.pause(); | ||
// round time down to three decimal digits | ||
const time = video.currentTime; | ||
const intTime = Math.floor(time); | ||
const roundTime = intTime + Math.floor((time - intTime) * 1000) / 1000; | ||
video.currentTime = roundTime; | ||
$.ajax(Routes.add_reference_path(thymeAttributes.mediumId), { | ||
type: 'GET', | ||
dataType: 'script', | ||
data: { | ||
time: video.currentTime | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
app/assets/javascripts/thyme/components/add_screenshot_button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class AddScreenshotButton extends Component { | ||
|
||
constructor(element, canvasId) { | ||
super(element); | ||
this.canvas = document.getElementById(canvasId); | ||
} | ||
|
||
add() { | ||
const video = thymeAttributes.video; | ||
const canvas = this.canvas; | ||
|
||
// Event listener for add screenshot button | ||
this.element.addEventListener('click', function() { | ||
video.pause(); | ||
// extract video screenshot from canvas | ||
const context = canvas.getContext('2d'); | ||
context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
const base64image = canvas.toDataURL('image/png'); | ||
// Get our file | ||
const file = thymeUtility.dataURLtoBlob(base64image); | ||
// Create new form data | ||
const fd = new FormData; | ||
// Append our Canvas image file to the form data | ||
fd.append('image', file); | ||
// And send it | ||
$.ajax(Routes.add_screenshot_path(thymeAttributes.mediumId), { | ||
type: 'POST', | ||
data: fd, | ||
processData: false, | ||
contentType: false | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters