History

js: use new hooks API (match f60826c3)

Avi Halachmi (:avih) committed 8 years ago

Commit ec625261 parent 84aa9e72 files · +50 −10Browse files

Showing the changes to player/javascript (1 of 2 files). Show all

Unified · Split

player/javascript/defaults.js+8−10
@@ -123,22 +123,19 @@ function dispatch_message(ev) { · 122 unmodified lines
123}123}
124 124
125// ----- hooks -----125// ----- hooks -----
126var next_hid = 1,126var hooks = []; // array of callbacks, id is index+1
127 hooks = new_cache(); // items of id: fn
128 127
129function hook_run(id, cont) {128function run_hook(ev) {
130 var cb = hooks[id];129 var cb = ev.id > 0 && hooks[ev.id - 1];
131 if (cb)130 if (cb)
132 cb();131 cb();
133 mp.commandv("hook-ack", cont);132 mp._hook_continue(ev.hook_id);
134}133}
135 134
136mp.add_hook = function add_hook(name, pri, fn) {135mp.add_hook = function add_hook(name, pri, fn) {
137 if (next_hid == 1) // doesn't really matter if we do it once or always136 hooks.push(fn);
138 mp.register_script_message("hook_run", hook_run);137 // 50 (scripting docs default priority) maps to 0 (default in C API docs)
139 var id = next_hid++;138 return mp._hook_add(name, pri - 50, hooks.length);
140 hooks[id] = fn;
141 return mp.commandv("hook-add", name, id, pri);
142}139}
143 140
144/**********************************************************************141/**********************************************************************
@@ -559,6 +556,7 @@ mp.keep_running = true; · 414 unmodified lines
559g.exit = function() { mp.keep_running = false }; // user-facing too556g.exit = function() { mp.keep_running = false }; // user-facing too
560mp.register_event("shutdown", g.exit);557mp.register_event("shutdown", g.exit);
561mp.register_event("property-change", notify_observer);558mp.register_event("property-change", notify_observer);
559mp.register_event("hook", run_hook);
562mp.register_event("client-message", dispatch_message);560mp.register_event("client-message", dispatch_message);
563mp.register_script_message("key-binding", dispatch_key_binding);561mp.register_script_message("key-binding", dispatch_key_binding);
564 562

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t