-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ChapelR/v2.6.1
v2.6.1
- Loading branch information
Showing
28 changed files
with
184 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,102 @@ | ||
// event macro set, by chapel; for sugarcube 2 | ||
// version 1.1.1 | ||
// version 2.0.0 | ||
|
||
// the <<trigger>> macro | ||
Macro.add('trigger', { | ||
handler : function () { | ||
|
||
// declare vars | ||
var evt, $el; | ||
|
||
// check for errors | ||
if (this.args.length > 2 || this.args.length === 0) { | ||
return this.error('incorrect number of arguments'); | ||
} | ||
if (typeof this.args[0] != 'string') { | ||
return this.error('first argument should be a string and a valid event type'); | ||
} | ||
|
||
// some setup | ||
evt = this.args[0]; | ||
$el = (this.args.length === 1 || | ||
(this.args[1] && typeof this.args[1] === 'string' && | ||
this.args[1].toLowerCase().trim() === 'document')) ? | ||
$(document) : $(this.args[1]); | ||
|
||
// fire the event | ||
$el.trigger(evt); | ||
|
||
} | ||
}); | ||
(function () { | ||
setup.eventMacroNamespace = 'macro-event'; | ||
|
||
// the <<event>> macro | ||
Macro.add('event', { | ||
tags : ['which'], | ||
handler : function () { | ||
|
||
var payload = this.payload; | ||
var evt, sel = '', code = '', i; | ||
|
||
if (this.args.length > 2 || this.args.length === 0) { | ||
return this.error('incorrect number of arguments'); | ||
} | ||
if (typeof this.args[0] != 'string') { | ||
return this.error('first argument should be a string and a valid event type'); | ||
} | ||
if (this.args.length === 2 && typeof this.args[1] == 'string') { | ||
sel = this.args[1]; | ||
// the <<trigger>> macro | ||
Macro.add('trigger', { | ||
handler : function () { | ||
|
||
// declare vars | ||
var evt, $el; | ||
|
||
// check for errors | ||
if (this.args.length > 2 || this.args.length === 0) { | ||
return this.error('incorrect number of arguments'); | ||
} | ||
if (typeof this.args[0] != 'string') { | ||
return this.error('first argument should be a string and a valid event type'); | ||
} | ||
|
||
// some setup | ||
evt = this.args[0]; | ||
$el = (this.args.length === 1 || | ||
(this.args[1] && typeof this.args[1] === 'string' && | ||
this.args[1].toLowerCase().trim() === 'document')) ? | ||
$(document) : $(this.args[1]); | ||
|
||
// fire the event | ||
$el.trigger(evt); | ||
|
||
} | ||
|
||
evt = this.args[0]; | ||
|
||
$(document).on(evt, sel, function (e) { | ||
code = payload[0].contents; | ||
if (payload.length > 1) { | ||
for (i = 1; i < payload.length; i++) { | ||
if (payload[i].args.includes(e.which)) { | ||
code = code + payload[i].contents; | ||
}); | ||
|
||
// the <<event>> macro: <<event type [selector] [once]>> | ||
Macro.add(['event', 'on', 'one'], { | ||
tags : ['which'], | ||
handler : function () { | ||
|
||
var payload = this.payload; | ||
var method = 'on'; | ||
var evt, sel = '', code = '', i; | ||
|
||
if (this.args.length > 3 || this.args.length === 0) { | ||
return this.error('incorrect number of arguments'); | ||
} | ||
if (typeof this.args[0] != 'string') { | ||
return this.error('first argument should be a string and a valid event type'); | ||
} | ||
if (this.args.length === 2 && typeof this.args[1] == 'string' && this.args[1] !== 'once') { | ||
sel = this.args[1]; | ||
} | ||
|
||
if (this.args.includes('once') || this.name === 'one') { | ||
method = 'one'; | ||
} | ||
|
||
evt = this.args[0]; | ||
|
||
$(document)[method](evt + '.' + setup.eventMacroNamespace, sel, function (e) { | ||
code = payload[0].contents; | ||
if (payload.length > 1) { | ||
for (i = 1; i < payload.length; i++) { | ||
if (payload[i].args.includes(e.which)) { | ||
code = code + payload[i].contents; | ||
} | ||
} | ||
} | ||
new Wikifier(null, code); | ||
}); | ||
|
||
} | ||
}); | ||
|
||
Macro.add('off', { | ||
handler : function () { | ||
|
||
// declare vars | ||
var evt, $el; | ||
|
||
// check for errors | ||
if (this.args.length > 2 || this.args.length === 0) { | ||
return this.error('incorrect number of arguments'); | ||
} | ||
if (typeof this.args[0] != 'string') { | ||
return this.error('first argument should be a string and a valid event type or namespace'); | ||
} | ||
new Wikifier(null, code); | ||
}); | ||
|
||
} | ||
}); | ||
|
||
// some setup | ||
evt = this.args[0]; | ||
$el = (this.args.length === 1 || | ||
(this.args[1] && typeof this.args[1] === 'string' && | ||
this.args[1].toLowerCase().trim() === 'document')) ? | ||
$(document) : $(this.args[1]); | ||
|
||
// fire the event | ||
$el.off(evt); | ||
|
||
} | ||
}); | ||
|
||
}()); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.