Implemented text field functionality
Character text fields now work. Slightly modified versions will be needed for Spells, features, etc.
This commit is contained in:
@@ -32,9 +32,9 @@ iron:controller@1.0.0
|
||||
iron:core@1.0.0
|
||||
iron:dynamic-template@1.0.0
|
||||
iron:layout@1.0.0
|
||||
iron:location@1.0.0
|
||||
iron:location@1.0.1
|
||||
iron:middleware-stack@1.0.0
|
||||
iron:router@1.0.0
|
||||
iron:router@1.0.1
|
||||
iron:url@1.0.0
|
||||
jquery@1.0.1
|
||||
json@1.0.1
|
||||
|
||||
@@ -126,6 +126,10 @@ Character = function(owner){
|
||||
canDeathSave: true
|
||||
};
|
||||
|
||||
for(var i = 0, l = string.length; i < l; i++){
|
||||
this.strings[strings[i]] = "";
|
||||
};
|
||||
|
||||
this.weaponProficiencies = [];
|
||||
this.toolProficiencies = [];
|
||||
this.languages = [];
|
||||
|
||||
36
rpg-docs/Model/Utility/evaluateString.js
Normal file
36
rpg-docs/Model/Utility/evaluateString.js
Normal file
@@ -0,0 +1,36 @@
|
||||
evaluate = function(character, string){
|
||||
string = string.replace(/\b[a-z]+\b/g, function(sub){
|
||||
//skill mods
|
||||
if(character.skills[sub]){
|
||||
return +character.skillMod(character.skills[sub]);
|
||||
}
|
||||
//attributes
|
||||
if(character.attributes[sub]){
|
||||
return +character.attributeValue(character.attributes[sub]);
|
||||
}
|
||||
return sub;
|
||||
});
|
||||
try{
|
||||
result = math.eval(string);
|
||||
return result
|
||||
} catch(e){
|
||||
console.log(e)
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
evaluateString = function(character, string){
|
||||
//define brackets as curly brackets around anything that isn't a curly bracket
|
||||
var brackets = /\{[^\{\}]*\}/g;
|
||||
var result = string.replace(brackets, function(exp){
|
||||
var exp = exp.replace(/(\{|\})/g, "") //remove brackets
|
||||
var span = jQuery('<span/>', {
|
||||
title: exp,
|
||||
text: evaluate(character, exp),
|
||||
class: "calculatedValue"
|
||||
});
|
||||
return span.prop('outerHTML');
|
||||
});
|
||||
//this is going to return HTML, ensure it is santized!
|
||||
return result;
|
||||
}
|
||||
34
rpg-docs/Model/Utility/math.js
Normal file
34
rpg-docs/Model/Utility/math.js
Normal file
File diff suppressed because one or more lines are too long
@@ -3,9 +3,6 @@
|
||||
{{> characterName}}
|
||||
</div>
|
||||
<div class="flexContainer">
|
||||
<div id="abilityScores" class="flexItem">
|
||||
{{> bigAbilities}}
|
||||
</div>
|
||||
<div class="flexItem">
|
||||
<div>
|
||||
Proficiency Bonus {{proficiencyBonus}}
|
||||
@@ -14,11 +11,8 @@
|
||||
{{> skills}}
|
||||
</div>
|
||||
</div>
|
||||
<div id="stats" class="flexItem">
|
||||
{{> characterStats}}
|
||||
</div>
|
||||
<div>
|
||||
{{> features}}
|
||||
<div class="flexItem floatBox">
|
||||
{{> textField character=this field="description"}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
11
rpg-docs/client/views/character/textField/textField.css
Normal file
11
rpg-docs/client/views/character/textField/textField.css
Normal file
@@ -0,0 +1,11 @@
|
||||
#textOutput.notEditing{
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#textInput {
|
||||
width:100%;
|
||||
height:100%;
|
||||
box-sizing: border-box; /* For IE and modern versions of Chrome */
|
||||
-moz-box-sizing: border-box; /* For Firefox */
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
9
rpg-docs/client/views/character/textField/textField.html
Normal file
9
rpg-docs/client/views/character/textField/textField.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<template name="textField">
|
||||
{{#if editing}}
|
||||
<div id="textInput" class={{outputClass}} contenteditable=true>{{input}}</div>
|
||||
{{else}}
|
||||
<div id="textOutput" class={{outputClass}}>
|
||||
{{output}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
42
rpg-docs/client/views/character/textField/textField.js
Normal file
42
rpg-docs/client/views/character/textField/textField.js
Normal file
@@ -0,0 +1,42 @@
|
||||
Template.textField.created = function(){
|
||||
Template.instance().editing = new ReactiveVar(false);
|
||||
document.execCommand('defaultParagraphSeparator', false, 'div');
|
||||
}
|
||||
|
||||
Template.textField.helpers({
|
||||
editing: function(){
|
||||
return Template.instance().editing.get();
|
||||
},
|
||||
input: function(){
|
||||
var text = this.character.strings[this.field];
|
||||
return Spacebars.SafeString(text);
|
||||
},
|
||||
output: function(){
|
||||
var html = evaluateString(this.character, this.character.strings[this.field]);
|
||||
return Spacebars.SafeString(html);
|
||||
},
|
||||
outputClass: function(){
|
||||
if(Template.instance().editing.get()){
|
||||
return "editing";
|
||||
} else{
|
||||
return "notEditing"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Template.textField.events({
|
||||
"blur #textInput": function(){
|
||||
Template.instance().editing.set(false);
|
||||
var text = $("#textInput").html();
|
||||
//TODO sanitise the html
|
||||
var setter = {};
|
||||
setter["strings."+this.field] = text;
|
||||
Characters.update(this.character._id, {$set: setter});
|
||||
},
|
||||
"click #textOutput": function(){
|
||||
Template.instance().editing.set(true);
|
||||
Tracker.afterFlush(function(){
|
||||
$("#textInput").focus();
|
||||
});
|
||||
}
|
||||
})
|
||||
20
rpg-docs/nohup.out
Normal file
20
rpg-docs/nohup.out
Normal file
@@ -0,0 +1,20 @@
|
||||
[[[[[ ~/workspace/rpg-docs ]]]]]
|
||||
|
||||
=> Started proxy.
|
||||
=> Started MongoDB.
|
||||
[34mI20141109-18:31:54.578(0)? [39m** You've set up some data subscriptions with Meteor.publish(), but
|
||||
[34mI20141109-18:31:54.660(0)? [39m** you still have autopublish turned on. Because autopublish is still
|
||||
[34mI20141109-18:31:54.660(0)? [39m** on, your Meteor.publish() calls won't have much effect. All data
|
||||
[34mI20141109-18:31:54.660(0)? [39m** will still be sent to all clients.
|
||||
[34mI20141109-18:31:54.660(0)? [39m**
|
||||
[34mI20141109-18:31:54.661(0)? [39m** Turn off autopublish by removing the autopublish package:
|
||||
[34mI20141109-18:31:54.661(0)? [39m**
|
||||
[34mI20141109-18:31:54.661(0)? [39m** $ meteor remove autopublish
|
||||
[34mI20141109-18:31:54.661(0)? [39m**
|
||||
[34mI20141109-18:31:54.661(0)? [39m** .. and make sure you have Meteor.publish() and Meteor.subscribe() calls
|
||||
[34mI20141109-18:31:54.661(0)? [39m** for each collection that you want clients to see.
|
||||
[34mI20141109-18:31:54.662(0)? [39m
|
||||
=> Started your app.
|
||||
|
||||
=> App running at: http://localhost:3000/
|
||||
=> Client modified -- refreshing
|
||||
Reference in New Issue
Block a user