12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- Smalltalk createPackage: 'Platform-DOM'!
- Object subclass: #PlatformDom
- instanceVariableNames: ''
- package: 'Platform-DOM'!
- !PlatformDom class methodsFor: 'node creation'!
- newDocumentFragment
- <inlineJS: 'return document.createDocumentFragment()'>
- !
- newElement: aString
- <inlineJS: 'return document.createElement(aString)'>
- !
- newTextNode: aString
- <inlineJS: 'return document.createTextNode(aString)'>
- ! !
- !PlatformDom class methodsFor: 'testing'!
- isDomNode: anObject
- <inlineJS: '
- return anObject.nodeType > 0 &&
- Object.prototype.toString.call(anObject) !!== "[object Object]"
- '>
- !
- isFeasible
- <inlineJS: '
- if (typeof document === "undefined") return false;
- try {
- var d = document.createElement("div"),
- f = document.createDocumentFragment(),
- t = document.createTextNode("Hello, Amber!!");
- f.appendChild(t);
- d.insertBefore(f, null);
- return d.innerHTML === "Hello, Amber!!";
- } catch (e) {
- return false;
- }
- '>
- ! !
- !CharacterArray methodsFor: '*Platform-DOM'!
- asDomNode
- ^ PlatformDom newTextNode: self asString
- ! !
- !Collection methodsFor: '*Platform-DOM'!
- asDomNode
- | fragment |
- fragment := PlatformDom newDocumentFragment.
- self do: [ :each | fragment appendChild: each asDomNode ].
- ^ fragment
- ! !
- !JSObjectProxy methodsFor: '*Platform-DOM'!
- asDomNode
- (PlatformDom isDomNode: jsObject)
- ifTrue: [ ^ jsObject ]
- ifFalse: [ ^ super asDomNode ]
- ! !
|