Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add custom formats with es5 - in v1.0.0 #850

Closed
sergop321 opened this issue Aug 9, 2016 · 4 comments
Closed

Unable to add custom formats with es5 - in v1.0.0 #850

sergop321 opened this issue Aug 9, 2016 · 4 comments

Comments

@sergop321
Copy link

I am trying to add a new formatter using es5

var Link = Quill.import('formats/link');
var ExtendedLink = function () {};
ExtendedLink.prototype = Object.create(Link.prototype);
ExtendedLink.prototype.constructor = ExtendedLink;

ExtendedLink.prototype.create = function (value) {
    var node = Link.prototype.create(value);
    node.className = 'test';

  return node;
};

ExtendedLink.blotName = 'linkt';
ExtendedLink.tagName = 'A';
ExtendedLink.SANITIZED_URL = 'about:blank';

Quill.register('formats/linkt', ExtendedLink);

That doesn't seems to work, and I couldn't find any documentation with an example.

@sergop321 sergop321 changed the title Unable to add custom formats in es5 Unable to add custom formats with es5 - in v1.0.0 Aug 9, 2016
@jhchen
Copy link
Member

jhchen commented Aug 11, 2016

Where are you getting this class/inheritance implementation for es5? Can you try Babel or Typescript's implementation?

@sergop321
Copy link
Author

sergop321 commented Aug 11, 2016

This is the exact problem, It is not possible to add precompiler to the project so it must be implemented completely in es5.

After several more hours I was able to make it work with the following

var Link = Quill.import('formats/link');
var ExtendedLink = function (node, value) {
    // Apply Link Constructor
    Link.call(this, node, value);
};

ExtendedLink.prototype = Object.create(Link.prototype);
// Copy static functions
$.extend(ExtendedLink, Object.create(Link));
ExtendedLink.sanitize = Link.sanitize; // sanitize not getting copied, so I am doing it manually

// Fixed constructor type 
ExtendedLink.prototype.constructor = ExtendedLink;

// Override parent create function
ExtendedLink.create = function (value) {
    var node = Link.create(value);
    node.className = 'test';

  return node;
};

// Update blotName
ExtendedLink.blotName = 'linkt';
Quill.register('formats/linkt', ExtendedLink, true);

Is there a more efficient way to implement the same functionality?
Is it possible to add some more documentation for es5 compatibility?

@jhchen
Copy link
Member

jhchen commented Aug 11, 2016

Quill should work with ES5 or ES6. The concern I wanted to explore was how you were implementing classes and inheritance. The snippet originally posted does not seem standard which is why I suggested Babel or Typescript's implementation. I was not suggesting use Typescript or Babel as a preprocessor, just their ES5 implementation for classes and inheritance. It looks like using jQuery's implementation did the trick, which is just as good.

@jhchen jhchen closed this as completed Aug 11, 2016
@sergop321
Copy link
Author

I tested both Babel and Typescript,
Typescript implementation, didn't work.
While Babel generate a harder to read code, but works great.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants