Skip to content

Commit

Permalink
Merge pull request #43 from ChapelR/v2.7.0
Browse files Browse the repository at this point in the history
v2.7.0
  • Loading branch information
ChapelR committed Nov 24, 2020
2 parents 5d64d15 + 07db5cc commit 49126e1
Show file tree
Hide file tree
Showing 34 changed files with 254 additions and 90 deletions.
7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [The Popover Macro](popover.md)
- [The UI Macro](ui-macro.md)
- [The Fading Macro Set](fading-macros.md)
- [The Disable Macro](disable-macro.md)
- [The CSS Macro](css-macro.md)
- [The Notify Macro](notify-macro.md)
- [The Meter Macro Set](meter-macros.md)
Expand Down Expand Up @@ -110,6 +111,12 @@ This code is dedicated to the public domain. You **don't** need to provide cred
> [!TIP]
> If you have any questions or concerns about this, refer to the [license](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/LICENSE) or reach out to me.
#### This macro set features contributions from these awesome folks:

- [Thomas M. Edwards](https://github.com/tmedwards)
- [Matilde Park](https://github.com/matildepark)
- [Zachary Chandler](https://github.com/Zachac)

### Donations

> [!NOTE]
Expand Down
16 changes: 8 additions & 8 deletions docs/articles.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ This function takes a string and finds the correct indefinite article, then appe

**Examples**:
```
setup.articles.find('UFO'); // 'a UFO'
setup.articles.find('animal'); // 'an animal'
setup.articles.find('1'); // 'a 1'
setup.articles.find('86'); // 'an 86'
setup.articles.find('honorable man'); // 'an honorable man'
setup.articles.find('heir to the king'); // 'an heir to the king'
setup.articles.find('horrible day'); // 'a horrible day'
setup.articles.find('painting'); // 'a painting'
setup.articles.output('UFO'); // 'a UFO'
setup.articles.output('animal'); // 'an animal'
setup.articles.output('1'); // 'a 1'
setup.articles.output('86'); // 'an 86'
setup.articles.output('honorable man'); // 'an honorable man'
setup.articles.output('heir to the king'); // 'an heir to the king'
setup.articles.output('horrible day'); // 'a horrible day'
setup.articles.output('painting'); // 'a painting'
```

#### Function: `setup.articles.override()`
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[Back to the main page](./README.md).

### November 24, 2020 (v2.7.0)

- **[New]** Added the `<<disable>>` macro.
- **[Update]** Updated the meter macro set. Now has a `this.settings.id` property.

### August 2, 2020 (v2.6.1)

- **[Update]** Updated the event macro set.
Expand Down
159 changes: 103 additions & 56 deletions docs/demo/index.html

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions docs/disable-macro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## The Disable Macro

[Back to the main readme](./README.md).

The `<<disable>>` macro allows the user to disable (and re-enable) various interactive elements.

**THE CODE:** [Minified](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/minified/disable.min.js). [Pretty](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/disable.js).
**DEMO:** [Available](http://macros.twinelab.net/demo?macro=disable).
**GUIDE:** Not available.

### Macro: `<<disable>>`

**Syntax**:`<<disable [expression]>>...<</disable>>`

The first interactive element (such as a button or text input) between the macro tags will be disabled. If an expression is passed to the macro, it will be evaluated. If the evaluated expression yields a truthy result, the interactive element will be disabled. If the expression is falsy, the element will not be disabled.

**Usage**:

```
This button should be disabled:
<<disable>><<button "Submit">><</button>><</disable>>
This textbox should also be disabled:
<<disable 1 === 1>><<textbox "$name" "">><</disable>>
This listbox, too:
<<disable true>><<listbox '$whee'>><<optionsfrom ["1", "2", "3"]>><</listbox>><</disable>>
This button should ''not'' be disabled:
<<disable false>><<button "Submit">><</button>><</disable>>
This textbox should ''not'' be disabled:
<<disable 1 === 0>><<textbox "$name" "">><</disable>>
```

## Other usage notes:

Disabled elements are also given the class `disabled`.
1 change: 1 addition & 0 deletions docs/download/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'The Done Macro' : 'done',
'The Event Macro Set' : 'events',
'The Fading Macro Set' : 'fading-macro-set',
'The Disable Macro' : 'disable',
'The First Macro' : 'first-macro',
'File System Macros' : 'fs',
'The Message Macro' : 'message-macro',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "custom-macros-for-sugarcube-2",
"version": "2.6.0",
"version": "2.7.0",
"description": "Collection of custom macros and systems for Twine/SugarCube2.",
"main": "build.js",
"directories": {
Expand Down
61 changes: 61 additions & 0 deletions scripts/disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
(function () {
// disable.js, by chapel, for sugarcube 2
// v1.0.0

'use strict';

var cls = 'disabled';
var interactive = ['button', 'fieldset', 'input', 'menuitem', 'optgroup', 'option', 'select', 'textarea'];

function getEl (self) {
// get the first interactive element
var $el = $(self).find(interactive.join(',')).first();
if (!$el[0]) {
$el = $(self).children().eq(0);
if (!$el[0]) {
return $(self);
}
}
return $el;
}

function changeCls ($el) {
if ($el.ariaIsDisabled()) {
$el.addClass(cls);
} else {
$el.removeClass(cls);
}
}

function disable ($el, bool) {
if (!($el instanceof $)) {
$el = $($el);
}
$el.ariaDisabled((bool === undefined) ? true : !!bool);
changeCls($el);
return $el;
}

// no need for JS API as there us a built-in jQuery extension

Macro.add('disable', {
tags : null,
handler : function () {
var bool, $wrapper = $(document.createElement('span'))
.addClass('macro-' + this.name)
.wiki(this.payload[0].contents);

try {
bool = this.args.raw.trim() ? !!Scripting.evalJavaScript(this.args.full) : undefined;
} catch (err) {
return this.error("bad evaluation: " + err.message);
}

disable(getEl($wrapper), bool);

// output
$(this.output).append($wrapper);
}
});

}());
1 change: 1 addition & 0 deletions scripts/meters.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
console.error('Meter "' + name + '" already exists.');
return;
}
Object.assign(opts, { id : name });
var meter = new Meter(opts, value);
Meter._list.set(name, meter);
return meter;
Expand Down
2 changes: 1 addition & 1 deletion scripts/minified/articles.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/minified/continue.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/minified/css-macro.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/minified/cycles.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/minified/dialog-api-macro-set.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/minified/disable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/minified/done.min.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// done.min.js, for SugarCube 2, by Chapel
// v1.0.1, 2020-08-02, 1d6b869ee7a4b36293aaf4003bfe47ffdfbdeba8
// v1.0.1, 2020-11-24, 9f958db927f80b0101af14e286ea0ad142026739
;!function(){var a=1;Macro.add("done",{skipArgs:!0,tags:null,handler:function(){var n=this.payload[0].contents.trim();""!==n&&(postdisplay[":chapel-done-macro-"+a]=function(a){delete postdisplay[a],$.wiki(n)},a++)}})}();
// end done.min.js
Loading

0 comments on commit 49126e1

Please sign in to comment.