GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.97k stars 399 forks source link

Changes in element DOM doesn't preserve #508

Open salehliam opened 6 years ago

salehliam commented 6 years ago

Hi,

I'm trying to create a tool that can increase or decrease font size of an element. The problem is that changes I make to DOM doesn't preserve. The elment goes back to its previous state after clicking the green button.

Here is the code of the plugin

`class fontSizeUp extends ContentTools.Tools.Bold

ContentTools.ToolShelf.stow(@,'fontSizeUp')

@label = 'fontSizeUp'
@icon = 'fontSizeUp'
@tagName = 'fontSizeUp'

@apply: (element, selection, callback) ->

  element.storeState()

  fontSize = element._domElement.style.fontSize

  unless fontSize? and fontSize

    element._domElement.style.fontSize = '14';

  element._domElement.style.fontSize = parseInt(element._domElement.style.fontSize) +  5

  element.updateInnerHtml();    

  element.restoreState()

ContentTools.DEFAULT_TOOLS[0].push('fontSizeUp')`

Is this the right way I am trying to change font size attribute of the element or is there a better way?

Thank you for your help. contenttools

Zhjoker commented 6 years ago

I am a newbie, I want to ask how to save the state after the user changes.