lib/atome/extensions/helper.rb in atome-0.4.5.4 vs lib/atome/extensions/helper.rb in atome-0.4.7.0
- old
+ new
@@ -1,29 +1,14 @@
+
+
def grab(val)
Atome.grab(val)
end
-def read_ruby(file)
- `
-fetch('medias/rubies/'+#{file})
- .then(response => response.text())
- .then(text => Opal.eval(text))
-`
-end
-
-def read_text(file)
- `
-fetch('medias/rubies/'+#{file})
- .then(response => response.text())
- .then(text => console.log(text))
-`
-end
-
-
def read(file, action=:text)
- send("read_#{action}", file)
+ Internal.send("read_#{action}", file)
end
def wait(seconds)
seconds = seconds.to_f
`setTimeout(function(){ #{yield} }, #{seconds * 1000})`
@@ -47,23 +32,10 @@
}
end
-
-`
-const atome = {
- jsSchedule: function (years, months, days, hours, minutes, seconds, proc) {
- const now = new Date();
- const formatedDate = new Date(years, months - 1, days, hours, minutes, seconds);
- const diffTime = Math.abs(formatedDate - now);
- setTimeout(function () {
- Opal.Object.$schedule_callback(proc);
- }, diffTime);
- }}
-`
-
def schedule(date, &proc)
date = date.to_s
delimiters = [",", " ", ":", "-"]
formated_date = date.split(Regexp.union(delimiters))
missing_datas = Time.now
@@ -118,6 +90,23 @@
end
def schedule_callback(proc)
instance_exec(&proc) if proc.is_a?(Proc)
+end
+
+def play_video(params, &proc)
+ params[:atome].html_object.play
+ # TODO : change timeupdate for when possible requestVideoFrameCallback (opal-browser/opal/browser/event.rb line 36)
+ video_callback = params[:atome].bloc # this is the video callback not the play callback
+ play_callback = params[:proc] # this is the video callback not the play callback
+ params[:atome].html_object.on(:timeupdate) do |e|
+ # e.prevent # Prevent the default action (eg. form submission)
+ # You can also use `e.stop` to stop propagating the event to other handlers.
+ instance_exec(params[:atome].html_object.currentTime, &video_callback) if video_callback.is_a?(Proc)
+ instance_exec(params[:atome].html_object.currentTime, &play_callback) if play_callback.is_a?(Proc)
+ end
+end
+
+def pause_video(params, &proc)
+ params[:atome].html_object.pause
end
\ No newline at end of file