Skip to content

Commit

Permalink
added DOM Element functionality for edit's selector parameter
Browse files Browse the repository at this point in the history
+ edit now accepts a DOM Element for the "selector" attribute (as well
as being able to pass a selector like before
+ you may now omit the "inputType" parameter and specify "parent" in its
place

Did this for one reason: to add point-and-click editing functionality.
By attaching a "click" event listener to the document and calling:
scribly.edit(e.target, [parent]);
as its callback you can allow your users to edit inline elements on the
fly with a single click.
  • Loading branch information
Kinman Covey committed Mar 2, 2015
1 parent 86ece40 commit 95e2d56
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/scribly.js
Expand Up @@ -10,10 +10,19 @@ var scribly = {
edit: function(selector, inputType, parent) {
var elements, parentElement, editSId, elementSId, elementSIdName, elementInput; //SId is short for Scribly ID

inputType = inputType || 'text';
parentElement = parent || document;
if(arguments[1].tagName) {
parentElement = arguments[1];
inputType = 'text';
}
else {
parentElement = parent || document;
inputType = inputType || 'text';
}

elements = parentElement.querySelectorAll(selector);
if(arguments[0].tagName && arguments[0].parentNode === parentElement)
elements = [arguments[0]];
else
elements = parentElement.querySelectorAll(selector);

var i = 0;
for(i=0; i<elements.length; i++) {
Expand Down

0 comments on commit 95e2d56

Please sign in to comment.