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

Added removeOverride() in rendition.themes to remove a css property in rendition.themes._overrides #971

Merged
merged 1 commit into from
Nov 7, 2019

Conversation

strattonpress
Copy link

@strattonpress strattonpress commented Aug 16, 2019

There are some instances that I want to remove and override a css property I have added using rendition.themes.override() and I can't seem to find a default method in epubjs to do this, so I added one. Maybe this will help some people too.

Usage:
rendition.themes.removeOverride(cssProperty)

@strattonpress
Copy link
Author

strattonpress commented Aug 16, 2019

Or, we can do this instead:

override(name, value, priority) {
    var contents = this.rendition.getContents();

    if(value) {
        this._overrides[name] = {
            value: value,
            priority: priority === true
        };
        contents.forEach((content) => {
            content.css(name, this._overrides[name].value, this._overrides[name].priority);
        });
    } else {
        delete this._overrides[name];
        contents.forEach((content) => {
            content.css(name);
        });
    }
}

Usage:
rendition.themes.override(cssProperty)

Which do you think is better?

@fchasen
Copy link
Contributor

fchasen commented Sep 6, 2019

Humm, I think I prefer explicitly removing the override.

Could you also add a removeOveride method to contents.js?

@strattonpress
Copy link
Author

strattonpress commented Sep 6, 2019

Hi @fchasen !

Yes, I have already added a removeOverride method. The second one was just a suggestion.

Here it is: 0acc423#diff-50c330c10da2c73d5d984ba2555b8e6e

In that method, I just removed the css property from _overrides then called the css() method from contents.js but without a css value (eg css(property)). Then in the css() method in contents.js, I did this:

if (value) {
    content.style.setProperty(property, value, priority ? "important" : "");
} else {
    content.style.removeProperty(property);
}

@fchasen fchasen merged commit a6bbf71 into futurepress:master Nov 7, 2019
@fchasen
Copy link
Contributor

fchasen commented Nov 7, 2019

Sorry for the delay!

@strattonpress
Copy link
Author

strattonpress commented Nov 7, 2019 via email

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

Successfully merging this pull request may close these issues.

2 participants