Skip to content

Commit

Permalink
added rangy for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Callens committed May 8, 2015
1 parent f93ae9e commit d058320
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins/pencilblue/templates/admin/elements/wysiwyg.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wysiwyg layout="layout"></wysiwyg>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rangy/1.2.3/rangy-core.js"></script>
<script type="text/javascript" src="^to_markdown_src^"></script>
<script type="text/javascript" src="^markdown_src^"></script>
21 changes: 19 additions & 2 deletions public/js/angular/directives/wysiwyg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
angular.module('wysiwygElement', [])
.directive('wysiwyg', function($sce) {
.directive('wysiwyg', function($sce, $document) {
return {
restrict: 'AE',
replace: true,
Expand All @@ -19,8 +19,14 @@
scope.wysiwyg.currentView = view;
};

scope.formatAction = function(action, arguments) {
console.log(action);

$document[0].execCommand(action, false, arguments);
}

scope.$watch('wysiwyg.layout', function(newVal, oldVal) {
if(scope.wysiwyg.currentView === 'markdown') {
if(scope.wysiwyg.currentView !== 'layout') {
return;
}

Expand All @@ -30,10 +36,21 @@
});

scope.$watch('wysiwyg.markdown', function(newVal, oldVal) {
if(scope.wysiwyg.currentView !== 'markdown') {
return;
}

if(newVal !== oldVal) {
scope.wysiwyg.layout = markdown.toHTML(newVal);
}
});

var editableDiv = angular.element(element).find('[contenteditable]');
var range = rangy.createRange();
editableDiv.on('mouseup', function(event) {
range.selectNodeContents(editableDiv[0]);
console.log(rangy.getSelection());
});
}
};
})
Expand Down

0 comments on commit d058320

Please sign in to comment.