clientside / amplesdk

Ample SDK - JavaScript UI Framework
Other
170 stars 29 forks source link

Optionally expose getTextContent/setTextContent in Node class #180

Closed AmicaNoctis closed 11 years ago

AmicaNoctis commented 11 years ago

Includes previous pull request: https://github.com/clientside/amplesdk/pull/179

Summary

There is a textContent property, but it is useless. It always returns null and cannot react on modifications. In some cases it would be helpful to access it however, even if this access has to be performed via getter/setter methods. So it should be disabled by default, but possible to enable it easily at runtime, e. g. per ample.config()

A possible solution to this is enclosed in this pull request.

Changes

Improved fNode_getTextContent, added fNode_setTextContent. Added configuration option to expose these methods in the Node class (default: don't expose).

Example session

ample.documentElement.getTextContent(); TypeError: ample.documentElement.getTextContent is not a function

ample.config("enable-textcontent"); false

ample.config("enable-textcontent", true);

ample.documentElement.getTextContent(); "(Some string containing the concatenation of the values of all text nodes.)"

ample.config("enable-textcontent", false);

ample.documentElement.getTextContent(); TypeError: ample.documentElement.getTextContent is not a function

ilinsky commented 11 years ago

Amica, this feature implementation cannot be merged. Although the implemented getTextContent/setTextContent may sound practical, there is already Query.text function that does the same. var old_text = ample.query("#element").text(); ample.query("#element").text("new_text");