-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ YouTubeShell = acorn.shells.YouTubeShell = | |
] | ||
|
||
|
||
|
||
class YouTubeShell.Model extends VideoLinkShell.Model | ||
|
||
|
||
|
@@ -57,6 +56,19 @@ class YouTubeShell.Model extends VideoLinkShell.Model | |
|
||
pattern.exec(link)[3] | ||
|
||
parseTime: (time) => | ||
validTimePatterns = [ | ||
/(\d+)/ | ||
/(\d+)m(\d+)s/ | ||
] | ||
|
||
# the second one is more general, work backwards | ||
if validTimePatterns[1].test time | ||
return 60 * parseInt(validTimePatterns[1].exec(time)[1]) + parseInt(validTimePatterns[1].exec(time)[2]) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
else if validTimePatterns[0].test time | ||
return parseInt(validTimePatterns[0].exec(time)[0]) | ||
else | ||
return undefined | ||
|
||
embedLink: (options) => | ||
# see https://developers.google.com/youtube/player_parameters for options | ||
|
@@ -102,6 +114,27 @@ class YouTubeShell.RemixView extends VideoLinkShell.RemixView | |
@model.timeTotal data.data.duration | ||
|
||
@model._updateAttributesWithDefaults() | ||
start = acorn.util.fetchParameters this.model.link(), ["t", "start"] | ||
This comment has been minimized.
Sorry, something went wrong. |
||
# take the first possible valid parameter | ||
|
||
start = @model.timeStart() | ||
unless _.isNumber start | ||
start = acorn.util.fetchParameters this.model.link(), ["t", "start"] | ||
start = @model.parseTime _.values(start)[0] | ||
unless _.isNumber start | ||
start = 0 | ||
|
||
end = @model.timeEnd() | ||
unless _.isNumber end | ||
end = acorn.util.fetchParameters this.model.link(), ["end"] | ||
end = @model.parseTime _.values(end)[0] | ||
unless _.isNumber end | ||
end = @model.timeTotal() | ||
This comment has been minimized.
Sorry, something went wrong.
jbenet
Member
|
||
|
||
@model.timeStart(start) | ||
@model.timeEnd(end) | ||
|
||
@_setTimeInputMin() | ||
@_setTimeInputMax() | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,7 +274,26 @@ util.parseUrl = (url) -> | |
|
||
result | ||
|
||
# function takes a URL and an array of parameters | ||
# returns JSON object with matching parameters and values, if any | ||
# otherwise, returns empty object | ||
# http://stackoverflow.com/a/8649003 | ||
util.fetchParameters = (url, params) -> | ||
url = $.trim url | ||
url = "http://#{url}" unless /^([a-z0-9]+:)?\/\//i.test url | ||
anchor = document.createElement 'a' | ||
anchor.href = url | ||
|
||
search = anchor.search.substring(1) | ||
search = '{"' + search.replace(/&/g, '","').replace(/\=/g, '":"') + '"}' | ||
This comment has been minimized.
Sorry, something went wrong.
jbenet
Member
|
||
|
||
parameters = if search is "" then {} else JSON.parse search, (key, value) -> | ||
if key is "" then value else decodeURIComponent value | ||
This comment has been minimized.
Sorry, something went wrong.
jbenet
Member
|
||
|
||
|
||
console.log(parameters) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
_.pick parameters, params | ||
|
||
|
||
# track mouse location at all times | ||
util.mouseLocationTracker = (-> | ||
|
1 comment
on commit 73f7ff2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, solid approach! :) a few stylistic/logic things above
might want to do something like:
it's clearer.