Skip to content

Commit

Permalink
Merge pull request #45 from SimplyEdit/feature/fix-styles
Browse files Browse the repository at this point in the history
Feature/fix styles
  • Loading branch information
ylebre authored Oct 17, 2024
2 parents 462b4e6 + 7d7b70c commit e0c5192
Show file tree
Hide file tree
Showing 18 changed files with 5,149 additions and 4 deletions.
46 changes: 46 additions & 0 deletions www/hope/hope.annotation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
hope.register( 'hope.annotation', function() {

function hopeAnnotation(range, tag) {
this.range = hope.range.create(range);
this.tag = tag;
Object.freeze(this);
}

hopeAnnotation.prototype.delete = function( range ) {
return new hopeAnnotation( this.range.delete( range ), this.tag );
};

hopeAnnotation.prototype.copy = function( range ) {
return new hopeAnnotation( this.range.copy( range ), this.tag );
};

hopeAnnotation.prototype.compare = function( annotation ) {
return this.range.compare( annotation.range );
};

hopeAnnotation.prototype.has = function( tag ) {
//FIXME: should be able to specify attributes and attribute values as well
return this.stripTag() == hope.annotation.stripTag(tag);
};

hopeAnnotation.prototype.toString = function() {
return this.range + ':' + this.tag;
};

hopeAnnotation.prototype.stripTag = function() {
return hope.annotation.stripTag(this.tag);
};

hopeAnnotation.prototype.isBlock = function() {
return (hope.render.html.rules.nestingSets.block.indexOf(hope.annotation.stripTag(this.tag)) != -1 ); // FIXME: this should not know about hope.render.html;
};

this.create = function( range, tag ) {
return new hopeAnnotation( range, tag );
};

this.stripTag = function(tag) {
return tag.split(' ')[0];
};
});

35 changes: 35 additions & 0 deletions www/hope/hope.editor.events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
hope.register('hope.editor.events', function() {

if ( typeof hope.global.addEventListener != 'undefined' ) {
this.listen = function( el, event, callback, capture ) {
return el.addEventListener( event, callback, capture );
};
} else if ( typeof hope.global.attachEvent != 'undefined' ) {
this.listen = function( el, event, callback, capture ) {
return el.attachEvent( 'on' + event, function() {
var evt = hope.global.event;
var self = evt.srcElement;
if ( !self ) {
self = hope.global;
}
return callback.call( self, evt );
} );
};
} else {
throw new hope.Exception( 'Browser is not supported', 'hope.editor.events.1' );
}

this.cancel = function( evt ) {
if ( typeof evt.stopPropagation != 'undefined' ) {
evt.stopPropagation();
}
if ( typeof evt.preventDefault != 'undefined' ) {
evt.preventDefault();
}
if ( typeof evt.cancelBubble != 'undefined' ) {
evt.cancelBubble = true;
}
return false;
};

} );
Loading

0 comments on commit e0c5192

Please sign in to comment.