Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ var extend = require('extend');
*/
module.exports = function (options, prompt) {
return function (scribe) {
var imagePromptCommand = new scribe.api.Command('insertImage');
var imagePromptCommand = new scribe.api.Command('insertHTML');
imagePromptCommand.nodeName = 'IMG';

if (typeof options == 'function') {
prompt = options;
};
}

imagePromptCommand.execute = function () {
link = prompt ? prompt() : window.prompt('Enter image url');
var link = prompt ? prompt() : window.prompt('Enter image url');
if (!link) return false;
if (typeof link === 'object') {
// If some extra properties were passed from prompt
options = extend(options, link);
} else if (typeof link === 'string') {
options.url = link
};
options.url = link;
}

if (!/^https?\:\/\//.test(options.url)) {
options.url = location.protocol + '//' + options.url;
};
}

var url = options.url;
var html = addAttributes('<img src=' + url + '>', options.attributes);

scribe.api.SimpleCommand.prototype.execute.call(this, html);
}
};

scribe.commands.imagePrompt = imagePromptCommand;
};
Expand All @@ -51,4 +51,4 @@ function addAttributes (html, attrs) {
}

return host.innerHTML;
}
}