From ba8e21034ca71853ad646b0dd97cb6e709bffb49 Mon Sep 17 00:00:00 2001 From: ChapelR Date: Fri, 28 Jun 2019 19:11:16 -0400 Subject: [PATCH] update pronouns.js / docs closes #26 closes #25 --- docs/demo/index.html | 6 +++--- docs/pronoun-templates.md | 6 ++---- scripts/minified/pronouns.min.js | 2 +- scripts/pronouns.js | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/demo/index.html b/docs/demo/index.html index aa0e78e..7ce2126 100644 --- a/docs/demo/index.html +++ b/docs/demo/index.html @@ -191,7 +191,7 @@ // end fs.min.js /* twine-user-script #11: "fullscreen.min.js" */ // fullscreen.min.js, for SugarCube 2, by Chapel -;setup.fullscreen=function(e){e.requestFullScreen?e.requestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullScreen&&e.webkitRequestFullScreen()},Macro.add("fullscreen",{handler:function(){var e=$("body").css("background-color");$("html").css("background-color",e),setup.fullscreen(document.documentElement)}}),Macro.add("fullscreenlink",{handler:function(){var e,n,r=$(document.createElement("span")),c=$(document.createElement("a")),t="macro-"+this.name;if(1!==this.args.length)return this.error("incorrect number of arguments");n=this.args[0],c.wiki(n).attr("id","fullscreen-macro-link").ariaClick(function(){e=$("body").css("background-color"),$("html").css("background-color",e),setup.fullscreen(document.documentElement)}),r.append(c).addClass(t).appendTo(this.output)}}); +;!function(){"use strict";var n=document.body;function t(){return!!(document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement)}function u(e){t()||(e.requestFullScreen?e.requestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.msRequestFullscreen&&e.msRequestFullscreen())}function l(){t()&&(document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen&&document.msExitFullscreen())}function c(e){t()?l():u(n)}Macro.add("fullscreen",{handler:function(){c()}}),Macro.add("fullscreenlink",{handler:function(){var e,n=$(document.createElement("span")),t=$(document.createElement("a")),u="macro-"+this.name;if(1!==this.args.length)return this.error("incorrect number of arguments");e=this.args[0],t.wiki(e).attr("id","fullscreen-macro-link").ariaClick(function(){c()}),n.append(t).addClass(u).appendTo(this.output)}}),setup.fullscreen=function(e){void 0===e?c():e?u(n):l()},setup.isFullscreen=t}(); // end fullscreen.min.js /* twine-user-script #12: "message-macro.min.js" */ // message-macro.min.js, for SugarCube 2, by Chapel @@ -211,7 +211,7 @@ // end notify.min.js /* twine-user-script #16: "operations.min.js" */ // operations.min.js, for SugarCube 2, by Chapel -;setup.operations={tryGlobal:!0,nicknames:!0,fmRange:[0,100]},setup.dice={processDice:function(e,r){var t,i=[],o=0;if("string"==typeof e)i=e.split("d");else if("number"==typeof e&&r)i=[e,r];else{if(!(Array.isArray(e)&&2<=e.length))throw new TypeError("setup.dice.processDice(): could not process arguments...");e.length=2,i=e}for(t=0;tr[1])throw new TypeError("Number.prototype.fairmath called on a number that is out of the defined range (the number was "+this+").");if(null==e||"number"!=typeof e||100e[1])throw new TypeError("Number.prototype.fairmath called on a number that is out of the defined range (the number was "+this+").");if(null==r||"number"!=typeof r||100"],i.forEach(function(e){l.push(e),l.push("
")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e[0]===e[0].toUpperCase()?t.toUpperFirst():t}}(); +;!function(){"use strict";if(Template&&Template.add&&"function"==typeof Template.add){var m={name:"gender",showSetting:!0,label:"Gender",desc:"",storyVar:"%%gender",default:"female"},e="#setting-control-"+m.name,c={subjective:["she","he","they"],objective:["her","him","them"],possessive:["hers","his","theirs"],determiner:["her","his","their"],reflexive:["herself","himself","themself"],noun:["woman","man","person"]};m.showSetting&&(Setting.addToggle(m.name,{label:m.label,desc:m.desc&&"string"==typeof m.desc&&m.desc.trim()?m.desc.trim():void 0}),$(document).on(":dialogopen :dialogopened",function(){$("#ui-dialog-body").hasClass("settings")&&$(e).parent("div").empty().append($(document.createElement("button")).append("Configure...").ariaClick(function(){t()}))})),Template.add(["he","she","they","He","She","They"],function(){return n(this.name,a().subjective)}),Template.add(["him","her","them","Him","Her","Them"],function(){return n(this.name,a().objective)}),Template.add(["his","hers","theirs","His","Hers","Theirs"],function(){return n(this.name,a().possessive)}),Template.add(["his_","her_","their","His_","Her_","Their"],function(){return n(this.name,a().determiner)}),Template.add(["himself","herself","themself","Himself","Herself","Themself"],function(){return n(this.name,a().reflexive)}),Template.add(["man","woman","person","Man","Woman","Person"],function(){return n(this.name,a().noun)}),Macro.add("pronouns",{skipArgs:!0,handler:function(){t()}}),setup.gender={pronouns:a,dialog:t},window.gender=window.gender||setup.gender}else alert("Warning, this version of SugarCube does not include the Template API. Please upgrade to v2.29.0 or higher.");function r(){var e=$(document.createElement("div"));var t,a,n,r,i=Object.keys(c).map(function(e){var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a,n,r,i=State.variables,s=c[e][t];return i[m.storyVar]&&i[m.storyVar][e]&&(s=i[m.storyVar][e]),a=e.toUpperFirst()+": ",n="gender-"+e,r=s,$(document.createElement("label")).append(a).css("display","block").append($(document.createElement("input")).attr({type:"text",name:n}).css({float:"right","margin-left":"0.2em"}).val(r))}),s=(t="Presets: ",a="gender-preset",n=["She/Her","He/Him","They/Them"],r=$(document.createElement("select")).attr("name",a).css("float","right"),n.forEach(function(e,t){console.log(t),$(document.createElement("option")).attr("value",String(t)).append(e).appendTo(r)}),$(document.createElement("label")).css("display","block").append(t,r)).on("change",function(){var n=Number($(this).find("select").val());Number.isNaN(n)||i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];t.val(c[a][n])})}),o=s.find("select");State.variables[m.storyVar]?o.val(""):"male"===m.default?o.val("1"):"female"===m.default?o.val("0"):o.val("2");var l,d=$(document.createElement("button")).wiki("Confirm").addClass("gender-confirm").ariaClick({label:"Confirm pronoun selection."},function(){var n=State.variables;n[m.storyVar]={},i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];n[m.storyVar][a]=t.val().trim().toLowerCase()}),$("#ui-dialog-body").hasClass("reopen")&&UI.settings(),Dialog.close()}),u=(l=[s,"
"],i.forEach(function(e){l.push(e),l.push("
")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e.first()===e.first().toUpperCase()?t.toUpperFirst():t}}(); // end pronouns.min.js /* twine-user-script #19: "simple-inventory.min.js" */ // simple-inventory.min.js, for SugarCube 2, by Chapel diff --git a/docs/pronoun-templates.md b/docs/pronoun-templates.md index ab047e1..d380aa5 100644 --- a/docs/pronoun-templates.md +++ b/docs/pronoun-templates.md @@ -2,7 +2,7 @@ [Back to the main readme](./README.md). -This script leverages SugarCube 2's new [template markup](.) and [API](.) to create a complete, user configurable pronoun system. Users are free to list their own pronouns by filling out a form, or choose from one of three presets "He/Him", "She/Her", and "They/Them". You can use the provided macro or JavaScript function to give the user access to the pronoun configuration dialog, and you can optionally allow the user to re-configure their pronouns from the Settings dialog at their pleasure. +This script leverages SugarCube 2's new [template markup](http://www.motoslave.net/sugarcube/2/docs/#markup-template) and [API](http://www.motoslave.net/sugarcube/2/docs/#template-api) to create a complete, user configurable pronoun system. Users are free to list their own pronouns by filling out a form, or choose from one of three presets "He/Him", "She/Her", and "They/Them". You can use the provided macro or JavaScript function to give the user access to the pronoun configuration dialog, and you can optionally allow the user to re-configure their pronouns from the Settings dialog at their pleasure. **THE CODE:** [Minified](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/minified/pronouns.min.js). [Pretty](https://github.com/ChapelR/custom-macros-for-sugarcube-2/blob/master/scripts/pronouns.js). **DEMO:** [Available](http://macros.twinelab.net/demo?macro=pronouns). @@ -23,7 +23,7 @@ This macro opens the pronoun configuration dialog, a pop-up style form where the ### Included Templates -See the [documentation](.) for more on template markup. +See the [documentation](http://www.motoslave.net/sugarcube/2/docs/#markup-template) for more on template markup. #### Determiner warning: @@ -126,8 +126,6 @@ Here is the complete list of templates provided by this system. ?He went to the bank to find out what state ?his_ mortgage was in. For ?him, all that mattered was that the house remained ?his. ``` -etc... - ### JavaScript API The following functions are available on `window.gender` and on `setup.gender`. diff --git a/scripts/minified/pronouns.min.js b/scripts/minified/pronouns.min.js index de1faec..0449877 100644 --- a/scripts/minified/pronouns.min.js +++ b/scripts/minified/pronouns.min.js @@ -1,3 +1,3 @@ // pronouns.min.js, for SugarCube 2, by Chapel -;!function(){"use strict";if(Template&&Template.add&&"function"==typeof Template.add){var m={name:"gender",showSetting:!0,label:"Gender",desc:"",storyVar:"%%gender",default:"female"},e="#setting-control-"+m.name,c={subjective:["she","he","they"],objective:["her","him","them"],possessive:["hers","his","theirs"],determiner:["her","his","their"],reflexive:["herself","himself","themself"],noun:["woman","man","person"]};m.showSetting&&(Setting.addToggle(m.name,{label:m.label,desc:m.desc&&"string"==typeof m.desc&&m.desc.trim()?m.desc.trim():void 0}),$(document).on(":dialogopen :dialogopened",function(){$("#ui-dialog-body").hasClass("settings")&&$(e).parent("div").empty().append($(document.createElement("button")).append("Configure...").ariaClick(function(){t()}))})),Template.add(["he","she","they","He","She","They"],function(){return n(this.name,a().subjective)}),Template.add(["him","her","them","Him","Her","Them"],function(){return n(this.name,a().objective)}),Template.add(["his","hers","theirs","His","Hers","Theirs"],function(){return n(this.name,a().possessive)}),Template.add(["his_","her_","their","His_","Her_","Their"],function(){return n(this.name,a().determiner)}),Template.add(["himself","herself","themself","Himself","Herself","Themself"],function(){return n(this.name,a().reflexive)}),Template.add(["man","woman","person","Man","Woman","Person"],function(){return n(this.name,a().noun)}),Macro.add("pronouns",{skipArgs:!0,handler:function(){t()}}),setup.gender={pronouns:a,dialog:t},window.gender=window.gender||setup.gender}else alert("Warning, this version of SugarCube does not include the Template API. Please upgrade to v2.29.0 or higher.");function r(){var e=$(document.createElement("div"));var t,a,n,r,i=Object.keys(c).map(function(e){var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a,n,r,i=State.variables,s=c[e][t];return i[m.storyVar]&&i[m.storyVar][e]&&(s=i[m.storyVar][e]),a=e.toUpperFirst()+": ",n="gender-"+e,r=s,$(document.createElement("label")).append(a).css("display","block").append($(document.createElement("input")).attr({type:"text",name:n}).css({float:"right","margin-left":"0.2em"}).val(r))}),s=(t="Presets: ",a="gender-preset",n=["She/Her","He/Him","They/Them"],r=$(document.createElement("select")).attr("name",a).css("float","right"),n.forEach(function(e,t){console.log(t),$(document.createElement("option")).attr("value",String(t)).append(e).appendTo(r)}),$(document.createElement("label")).css("display","block").append(t,r)).on("change",function(){var n=Number($(this).find("select").val());Number.isNaN(n)||i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];t.val(c[a][n])})}),o=s.find("select");State.variables[m.storyVar]?o.val(""):"male"===m.default?o.val("1"):"female"===m.default?o.val("0"):o.val("2");var l,d=$(document.createElement("button")).wiki("Confirm").addClass("gender-confirm").ariaClick({label:"Confirm pronoun selection."},function(){var n=State.variables;n[m.storyVar]={},i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];n[m.storyVar][a]=t.val().trim().toLowerCase()}),$("#ui-dialog-body").hasClass("reopen")&&UI.settings(),Dialog.close()}),u=(l=[s,"
"],i.forEach(function(e){l.push(e),l.push("
")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e[0]===e[0].toUpperCase()?t.toUpperFirst():t}}(); +;!function(){"use strict";if(Template&&Template.add&&"function"==typeof Template.add){var m={name:"gender",showSetting:!0,label:"Gender",desc:"",storyVar:"%%gender",default:"female"},e="#setting-control-"+m.name,c={subjective:["she","he","they"],objective:["her","him","them"],possessive:["hers","his","theirs"],determiner:["her","his","their"],reflexive:["herself","himself","themself"],noun:["woman","man","person"]};m.showSetting&&(Setting.addToggle(m.name,{label:m.label,desc:m.desc&&"string"==typeof m.desc&&m.desc.trim()?m.desc.trim():void 0}),$(document).on(":dialogopen :dialogopened",function(){$("#ui-dialog-body").hasClass("settings")&&$(e).parent("div").empty().append($(document.createElement("button")).append("Configure...").ariaClick(function(){t()}))})),Template.add(["he","she","they","He","She","They"],function(){return n(this.name,a().subjective)}),Template.add(["him","her","them","Him","Her","Them"],function(){return n(this.name,a().objective)}),Template.add(["his","hers","theirs","His","Hers","Theirs"],function(){return n(this.name,a().possessive)}),Template.add(["his_","her_","their","His_","Her_","Their"],function(){return n(this.name,a().determiner)}),Template.add(["himself","herself","themself","Himself","Herself","Themself"],function(){return n(this.name,a().reflexive)}),Template.add(["man","woman","person","Man","Woman","Person"],function(){return n(this.name,a().noun)}),Macro.add("pronouns",{skipArgs:!0,handler:function(){t()}}),setup.gender={pronouns:a,dialog:t},window.gender=window.gender||setup.gender}else alert("Warning, this version of SugarCube does not include the Template API. Please upgrade to v2.29.0 or higher.");function r(){var e=$(document.createElement("div"));var t,a,n,r,i=Object.keys(c).map(function(e){var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a,n,r,i=State.variables,s=c[e][t];return i[m.storyVar]&&i[m.storyVar][e]&&(s=i[m.storyVar][e]),a=e.toUpperFirst()+": ",n="gender-"+e,r=s,$(document.createElement("label")).append(a).css("display","block").append($(document.createElement("input")).attr({type:"text",name:n}).css({float:"right","margin-left":"0.2em"}).val(r))}),s=(t="Presets: ",a="gender-preset",n=["She/Her","He/Him","They/Them"],r=$(document.createElement("select")).attr("name",a).css("float","right"),n.forEach(function(e,t){console.log(t),$(document.createElement("option")).attr("value",String(t)).append(e).appendTo(r)}),$(document.createElement("label")).css("display","block").append(t,r)).on("change",function(){var n=Number($(this).find("select").val());Number.isNaN(n)||i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];t.val(c[a][n])})}),o=s.find("select");State.variables[m.storyVar]?o.val(""):"male"===m.default?o.val("1"):"female"===m.default?o.val("0"):o.val("2");var l,d=$(document.createElement("button")).wiki("Confirm").addClass("gender-confirm").ariaClick({label:"Confirm pronoun selection."},function(){var n=State.variables;n[m.storyVar]={},i.forEach(function(e){var t=e.find("input"),a=t.attr("name").split("-")[1];n[m.storyVar][a]=t.val().trim().toLowerCase()}),$("#ui-dialog-body").hasClass("reopen")&&UI.settings(),Dialog.close()}),u=(l=[s,"
"],i.forEach(function(e){l.push(e),l.push("
")}),l.push(d),l);return e.append(u)}function t(){var e,t,a,n;e="Customize Gender",t=r(),n=!(a="custom-gender"),Dialog.isOpen()&&$("#ui-dialog-body").hasClass("settings")&&(n=!0),Dialog.close(),Dialog.setup(e,n?a+" reopen":a),Dialog.append(t),Dialog.open()}function a(){if(State.variables[m.storyVar]&&State.variables[m.storyVar].subjective)return State.variables[m.storyVar];var t=2;"male"===m.default?t=1:"female"===m.default&&(t=0);var a={};return Object.keys(c).forEach(function(e){a[e]=c[e][t]}),a}function n(e,t){return e.first()===e.first().toUpperCase()?t.toUpperFirst():t}}(); // end pronouns.min.js \ No newline at end of file diff --git a/scripts/pronouns.js b/scripts/pronouns.js index 6528d50..46f8e8a 100644 --- a/scripts/pronouns.js +++ b/scripts/pronouns.js @@ -210,7 +210,7 @@ function isUpper (name, string) { // is name is uppercase, return uppercased string - if (name[0] === name[0].toUpperCase()) { + if (name.first() === name.first().toUpperCase()) { return string.toUpperFirst(); } return string;