Open yura121 opened 10 years ago
That's a nice idea, but for technical reasons, it's not currently possible to display an attached image inline. Let's keep this ticket open just in case that changes in the future.
On 11/08/2013 06:00 AM, Yura Gerassimenko wrote:
It would be great to create a link/button beside an attachment image to quickly insert image into text.
— Reply to this email directly or view it on GitHub https://github.com/boonebgorges/buddypress-docs/issues/369.
Has deployed attached image so:
function bpdInsertImage(imgSrc) {
if (jQuery('textarea#doc_content').is(':visible')) {
var xImg = '<img src="' + imgSrc + '" />';
jQuery('textarea#doc_content').insertAtCaret(xImg);
} else {
var ed = tinyMCE.getInstanceById('doc_content');
var newNode = ed.getDoc().createElement('img');
newNode.src = imgSrc;
ed.execCommand('mceInsertContent', false, newNode.outerHTML);
}
}
jQuery.fn.insertAtCaret = function(myValue) {
return this.each(function() {
var me = this;
if (document.selection) { // IE
me.focus();
sel = document.selection.createRange();
sel.text = myValue;
me.focus();
} else if (me.selectionStart || me.selectionStart == '0') { // Real browsers
var startPos = me.selectionStart, endPos = me.selectionEnd, scrollTop = me.scrollTop;
me.value = me.value.substring(0, startPos) + myValue + me.value.substring(endPos, me.value.length);
me.focus();
me.selectionStart = startPos + myValue.length;
me.selectionEnd = startPos + myValue.length;
me.scrollTop = scrollTop;
} else {
me.value += myValue;
me.focus();
}
});
};
templatetags.php
if (in_array($attachment_ext, array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'))) {
$attachment_insert_html = sprintf(
'<span class="sep">|</span><a href="javascript:;" onclick="bpdInsertImage(\'%s\');" class="doc-attachment-insert">%s</a>',
$attachment_url,
__( 'Insert', 'bp-docs' )
);
}
It would be great to create a link/button beside an attachment image to quickly insert image into text.