Skip to content

Commit

Permalink
attempted fix of rangy issues with firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Callens committed Aug 14, 2015
1 parent 98bdb48 commit 2401443
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions public/js/angular/directives/wysiwyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@
return scope.availableElements[0];
};

scope.formatAction = function(action, arguments) {
scope.formatAction = function(action, args) {
if(scope.wysiwyg.currentView !== 'editable') {
return;
}

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

scope.isFormatActive = function(type) {
return $document[0].queryCommandState(type)
return $document[0].queryCommandState(type);
};

scope.clearStyles = function() {
Expand All @@ -95,7 +95,7 @@
}

scope.layoutLink.text = scope.getSelection();
scope.saveSelection();
scope.saveSelection(true);
angular.element(element).find('[insert-link-modal]').modal('show');
};

Expand All @@ -112,6 +112,7 @@
};

scope.insertReadMore = function() {
scope.saveSelection(true);
scope.restoreSelection();
scope.formatAction('inserthtml', '<hr class="read_more_break"></hr>');
};
Expand All @@ -126,7 +127,7 @@

scope.showInsertMediaModal = function() {
angular.element(element).find('[contenteditable]').focus();
scope.saveSelection();
scope.saveSelection(true);
angular.element(element).find('[insert-media-modal]').modal('show');
};

Expand Down Expand Up @@ -154,14 +155,15 @@
return mediaFormat;
};

scope.saveSelection = function() {
if(!angular.element(element).find('[contenteditable]').is(':focus')) {
scope.saveSelection = function(force) {
if(!angular.element(element).find('[contenteditable]').is(':focus') && !force) {
return;
}

if(scope.editableSelection) {
rangy.removeMarkers(scope.editableSelection);
}

scope.editableSelection = rangy.saveSelection();
};

Expand Down Expand Up @@ -306,7 +308,7 @@
var mediaTags = ['^' + angular.element(this).attr('media-tag') + '^'];
var subTags = angular.element(this).find('[media-tag]');
for(var j = 0; j < subTags.length; j++) {
mediaTags.push('^' + $(subTags[j]).attr('media-tag') + '^')
mediaTags.push('^' + $(subTags[j]).attr('media-tag') + '^');
}

angular.element(this).replaceWith(mediaTags.concat(''));
Expand All @@ -316,7 +318,7 @@
scope.convertReadMore();
}
});
}
};

scope.$watch('wysiwyg.layout', function(newVal, oldVal) {
if(scope.wysiwyg.currentView !== 'editable') {
Expand All @@ -332,7 +334,7 @@
scope.wysiwyg.markdown = toMarkdown(scope.layout);
}

scope.saveSelection();
//scope.saveSelection();
});

scope.$watch('layout', function(newVal, oldVal) {
Expand Down Expand Up @@ -402,6 +404,6 @@
ngModel.$setViewValue(html);
}
}
}
};
});
}());

0 comments on commit 2401443

Please sign in to comment.