Skip to content

Commit

Permalink
solved issue with EM6
Browse files Browse the repository at this point in the history
  • Loading branch information
grych committed Jan 31, 2017
1 parent da7c26b commit 90c9ed0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.3
Fixed:
* not working on iOS9 (#3): changed all ES6 constructs to plain JS

## 0.2.2
New callbacks and Session housekeeping (renamed to Store)

Expand Down
10 changes: 5 additions & 5 deletions priv/templates/drab/drab.core.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Drab.on_connect(function(resp, drab) {
// prevent reassigning messages
if (!drab.already_connected) {
drab.channel.on("onload", (message) => {
drab.channel.on("onload", function(message) {
// reply from onload is not expected
})

// exec is synchronous, returns the result
drab.channel.on("execjs", (message) => {
let query_output = [
drab.channel.on("execjs", function(message) {
var query_output = [
message.sender,
eval(message.js)
]
drab.channel.push("execjs", {ok: query_output})
})

// broadcast does not return a meesage
drab.channel.on("broadcastjs", (message) => {
drab.channel.on("broadcastjs", function(message) {
eval(message.js)
})

// console.log
drab.channel.on("console", (message) => {
drab.channel.on("console", function(message) {
console.log(message.log)
})
}
Expand Down
36 changes: 19 additions & 17 deletions priv/templates/drab/drab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,43 @@
this.path = location.pathname

// launch all on_load functions
for(let f of this.load) {
for(var f of this.load) {
f(this)
}

let socket = new this.Socket("<%= Drab.config.socket %>", {params: {drab_return: drab_return_token}})
var socket = new this.Socket("<%= Drab.config.socket %>", {params: {drab_return: drab_return_token}})
socket.connect()
this.channel = socket.channel(`drab:${this.path}`, {})

var drab = this
this.channel.join()
.receive("error", resp => {
.receive("error", function(resp) {
// TODO: communicate it to user
console.log("Unable to join the Drab Channel", resp)
})
.receive("ok", resp => {
.receive("ok", function(resp) {
// launch on_connect
for(let f of this.connected) {
f(resp, this)
for(var f of drab.connected) {
f(resp, drab)
}
this.already_connected = true
drab.already_connected = true
// event is sent after Drab finish processing the event
this.channel.on("event", (message) => {
drab.channel.on("event", function (message) {
// console.log("EVENT: ", message)
if(this.event_reply_table[message.finished]) {
this.event_reply_table[message.finished]()
delete this.event_reply_table[message.finished]
if(drab.event_reply_table[message.finished]) {
drab.event_reply_table[message.finished]()
delete drab.event_reply_table[message.finished]
}
// update the store
this.drab_store_token = message.drab_store_token
drab.drab_store_token = message.drab_store_token
})
})
// socket.onError(function(ev) {console.log("SOCKET ERROR", ev);});
// socket.onClose(function(ev) {console.log("SOCKET CLOSE", ev);});
socket.onClose((event) => {
socket.onClose(function(event) {
// on_disconnect
for(let f of this.disconnected) {
f(this)
for(var f of drab.disconnected) {
f(drab)
}
})
},
Expand All @@ -67,11 +69,11 @@
// payload: object - will be passed as the second argument to the Event Handler
// execute_after - callback to function executes after event finish
launch_event: function(event_name, event_handler, payload, execute_after) {
let reply_to = uuid()
var reply_to = uuid()
if(execute_after) {
Drab.event_reply_table[reply_to] = execute_after
}
let message = {
var message = {
event: event_name,
event_handler_function: event_handler,
payload: payload,
Expand Down
10 changes: 5 additions & 5 deletions priv/templates/drab/drab.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const MODAL_BUTTONS = ".drab-modal-button"

Drab.on_connect(function(resp, drab) {
function modal_button_clicked(message, button_clicked) {
let vals = {}
var vals = {}
$(`${MODAL} form :input`).map(function() {
let key = $(this).attr("name") || $(this).attr("id")
var key = $(this).attr("name") || $(this).attr("id")
vals[key] = $(this).val()
})
let query_output = [
var query_output = [
message.sender,
{
button_clicked: button_clicked,
Expand All @@ -22,7 +22,7 @@ Drab.on_connect(function(resp, drab) {
$(MODAL).modal('hide')
}

drab.channel.on("modal", (message) => {
drab.channel.on("modal", function(message) {
$modal = $(MODAL)
$(MODAL_FORM).on("submit", function() {
modal_button_clicked(message, "ok")
Expand All @@ -49,7 +49,7 @@ Drab.on_connect(function(resp, drab) {
}, 1000 * message.timeout)
}
// set focus on form
$modal.on("shown.bs.modal", () => {
$modal.on("shown.bs.modal", function() {
$(MODAL_FORM + " :input").first().focus()
})

Expand Down
8 changes: 4 additions & 4 deletions priv/templates/drab/drab.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ Drab.on_connect(function(resp, drab) {

// set up the controls with drab handlers
// first serve the shortcut controls by adding the longcut attrbutes
for (let ev of EVENTS) {
for (var ev of EVENTS) {
$(`[drab-${ev}]`).each(function() {
$(this).attr("drab-event", ev)
$(this).attr("drab-handler", $(this).attr(`drab-${ev}`))
})
}

let events_to_disable = EVENTS_TO_DISABLE
var events_to_disable = EVENTS_TO_DISABLE
$("[drab-event]").each(function() {
if($(this).attr("drab-handler")) {
let ev=$(this).attr("drab-event")
var ev=$(this).attr("drab-event")
$(this).off(ev).on(ev, function(event) {
let t = $(this)
var t = $(this)
// disable current control - will be re-enabled after finish
<%= if Drab.config.disable_controls_while_processing do %>
if ($.inArray(ev, events_to_disable) >= 0) {
Expand Down

0 comments on commit 90c9ed0

Please sign in to comment.