diff --git a/coffee/src/shells/videolink.shell.coffee b/coffee/src/shells/videolink.shell.coffee index b00799e..796bf8d 100644 --- a/coffee/src/shells/videolink.shell.coffee +++ b/coffee/src/shells/videolink.shell.coffee @@ -291,6 +291,12 @@ class VideoLinkShell.RemixView extends LinkShell.RemixView _setTimeInputMax: => @timeRangeView.setMax @model.timeTotal() + _setClipRange: => + @timeRangeView.values { + start: @model.timeStart() + end: @model.timeEnd() + } + onChangeTimes: (changed) => changes = {} diff --git a/coffee/src/shells/youtube.shell.coffee b/coffee/src/shells/youtube.shell.coffee index 488f242..ffad243 100644 --- a/coffee/src/shells/youtube.shell.coffee +++ b/coffee/src/shells/youtube.shell.coffee @@ -21,7 +21,6 @@ YouTubeShell = acorn.shells.YouTubeShell = ] - class YouTubeShell.Model extends VideoLinkShell.Model @@ -57,6 +56,20 @@ 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 + match = validTimePatterns[1].exec time + if match + return 60 * parseInt(match[1]) + parseInt(match[2]) + match = validTimePatterns[0].exec time + if validTimePatterns[0].test time + return parseInt(match[1]) + return undefined embedLink: (options) => # see https://developers.google.com/youtube/player_parameters for options @@ -95,16 +108,46 @@ class YouTubeShell.RemixView extends VideoLinkShell.RemixView super @metaData().sync success: @onMetaDataSync + _timeLinkParam: (keys) => + unless _.isArray keys + keys = [keys] + param = acorn.util.fetchParameters this.model.link(), keys + return @model.parseTime _.values(param)[0] + + # Default start/end can only be set once player metadata + # is avaiilable and initialized. Otherwise, default values + # will override the start/end times. + initializeDefaultClip: => + firstNumber = (args) -> + _.find args, _.isNumber + + start = firstNumber [ + @model.timeStart() + @_timeLinkParam ["t", "start"] + 0 + ] + + end = firstNumber [ + @model.timeEnd() + @_timeLinkParam ["end"] + @model.timeTotal() + ] + + end = if end >= start then end else @model.timeTotal() + # Clip range must be set before progress bar is initialized + @model.timeStart(start) + @model.timeEnd(end) + @_setClipRange() onMetaDataSync: (data) => @model._fetchedDefaults ?= {} @model._fetchedDefaults = title: data.data.title + @model._updateAttributesWithDefaults() @model.timeTotal data.data.duration - @model._updateAttributesWithDefaults() + @initializeDefaultClip() @_setTimeInputMax() - metaData: => if @model.metaDataUrl() and not @_metaData @_metaData = new athena.lib.util.RemoteResource diff --git a/coffee/src/util/util.coffee b/coffee/src/util/util.coffee index 86c8980..939340d 100644 --- a/coffee/src/util/util.coffee +++ b/coffee/src/util/util.coffee @@ -274,7 +274,24 @@ 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, '":"') + '"}' + + parameters = JSON.parse search, (key, value) -> + if key is "" then value else decodeURIComponent value + + _.pick parameters, params + # track mouse location at all times util.mouseLocationTracker = (-> diff --git a/coffee/src/views/index.coffee b/coffee/src/views/index.coffee index 5145292..9c2647e 100644 --- a/coffee/src/views/index.coffee +++ b/coffee/src/views/index.coffee @@ -21,7 +21,6 @@ `import "shell_editor_view"` `import "shell_options_view"` `import "shell_selector_view"` -`import "slider_handle_view"` `import "sliding_bar_view"` `import "sliding_object_view"` `import "sources_view"`