Comments (4)
Sounds like you have an interesting project! That isn't really something textAngular was designed to support natively as all our dom manipulation is done through document.execCommand which doesn't support what you want to do.
So you'd have to do some custom code but this should get you going:
action: function(){
var element = $compile("<eg-todo>")(this.$parent);
//figure out how to insert it here using something like Rangy to get the current cursor position/selection, then inserting your compiled html
this.$parent.displayElements.text[0].focus(); // refocus on the WYSIWYG editor after loosing it to the button
this.$parent.updateSelectedStyles(); // you can omit this if you aren't implementing activeState or the active class
this.$parent.updateTaBindtext(); // updates the model
}
I'd say you'd also need to change line 442 of textAngular from element.html(val);
to element.html($compile(val)(scope.$parent));
and then inject $compile
into the taBind directive.
No guarantees it will work, if it does we could consider making the ability to insert directives dynamically a feature in the future, which sounds cooler the more I think about it. But I have no idea what the implications are of allowing this on security and performance and I have a feeling these could be a tricky.
from textangular.
If we living in directive world i think we must to support it.
I solved this problem using next way:
Checkbox button:
checkbox: {
display: "<button type='button' ng-click='action()' ><i class='fa fa-check-square-o'></i></button>",
action: function () {
function insertNodeAtCursor(node) {
var sel, range, html;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
sel.getRangeAt(0).insertNode(node);
}
} else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
html = (node.nodeType == 3) ? node.data : node.outerHTML;
range.pasteHTML(html);
}
}
function placeCaretAtEnd(el) {
el.focus();
if (typeof window.getSelection != "undefined"
&& typeof document.createRange != "undefined") {
var range = document.createRange();
range.setStartAfter( el );
range.setEndAfter( el );
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.body.createTextRange != "undefined") {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.collapse(false);
textRange.select();
}
}
var element = $compile('<input type="checkbox" eg-todo />')(this.$parent);
this.$parent.displayElements.text[0].focus();
insertNodeAtCursor(element[0]);
placeCaretAtEnd(element[0])
return this.$parent.wrapSelection("insertHTML", " ");
}
},
$compile before insert
nizsheanez@f588a0b
and add change
event listener
nizsheanez@7e26d35
and example of eg-todo
directive:
angular.module('eg.goal').directive('egTodo', function () {
return {
restrict: 'A',
scope: false,
link: function ($scope, element, attrs) {
element.change(function() {
element.attr('checked', element.is(':checked') ? 'checked' : false);
});
}
};
});
i try to use it on page with 14 editors, and 200 checkboxes per editor.
Don't see problems with memory or cpu
from textangular.
first problem:
console.log($compile('<span>1</span>sdfasdfasdf')(scope.$parent));
loose raw text, it's not dom
from textangular.
Cool, great that it's working for you and thanks for sharing your code. I'm not able to look into this properly till Feb next year due to Family commitments. I agree that it's a good idea to allow the use of directives in the wysiwyg, I just have some concerns about essentially allowing dynamic injecting of directives into your code. It opens up a nice big hole in your app if we use your approach as is. From what I can see any angular directives put into the raw HTML view will be activated and run using the WYSIWYG view which normally you can't do afaik.
from textangular.
Related Issues (20)
- Dropdown Button in Toolbar angular.
- Firefox toolbar selection issue when typing a new word HOT 1
- Toolbar bold stops working if font-weight is larger than normal (Firefox)
- Triple click error on chrome
- textAngular removes all styling when HTML is copied
- Applying Header format not working when html content copied from email HOT 1
- will remove center class while copy html from email
- while pasting external content cursor is jumping to initial position.
- Android mobile autocomplete error
- Is there any option for font-size?
- Backspace key not working
- Upgraded textangular version as1.5.16 is giving vulnerable version of angular-sanitize
- How do you configure 2 different toolbars in the same project?
- Save changes in HTML-mode HOT 1
- Security vulnerability HOT 1
- TextAngular not rendering button tag HOT 1
- Capture Ng-click event from button inside the texteditor in text-angular HOT 2
- Clicking on the validation bold/italics/underline when no text present in text box. validation is getting triggered HOT 1
- Not able to change Tooltip Text for any control of Rich-Text-Area-TextAngular
- All html tags scape from control
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textangular.