[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
api[www,FileAPI] code
NativeObject
subclass: #FileAPIObject
category: #FileAPI!
FileAPIObject comment: '
Provides an API for representing file objects in web applications, as well as programmatically selecting them and accessing their data.
http://www.w3.org/TR/FileAPI/
@2013 Alejandro Reimondo [email protected]
'!
#( #FileList #LineEndings
#Blob
#FileReaderSync #URL
) do: [:each| FileAPIObject subclass: each ].
Blob subclass: #File category: #FileAPI!
DOM subclass: #FileReader category: #FileAPI!
! BrowserWindow methodsFor: 'FileAPI-converting' !
asLineEndings
" Return the receiver adapted to LineEndings interface. "
^LineEndings @ self handle! !
FileList buildGetters: #( #length )!
FileList buildFunctions: #( #( #item: #( #index ) ) )!
LineEndings buildFunctions: #(
#( #toNativeLineEndings: #( #string ) )
)!
Blob buildGetters: #( #size #type )!
Blob buildFunctions: #(
#( #slice:end:contentType: #( #start #end #contentType ) )
#( #slice:end: #( #start #end ) )
#( #slice: #( #start ) )
#slice #close
)!
File buildGetters: #( #name #lastModifiedDate )!
FileReader buildAccessors: #(
#onloadstart #onprogress #onload #onabort #onerror #onloadend
)!
FileReader buildGetters: #( #readyState #result #error )!
FileReader buildFunctions: #(
#( #readAsArrayBuffer: #( #blob ) )
#( #readAsText:encoding: #( #blob #encoding ) )
#( #readAsDataURL: #( #blob ) )
#abort
)!
! FileReader class methodsFor: #constants !
empty
" Return the constant value EMPTY "
^0! !
! FileReader class methodsFor: #constants !
loading
" Return the constant value LOADING "
^1! !
! FileReader class methodsFor: #constants !
done
" Return the constant value DONE "
^2! !
FileReaderSync buildFunctions: #(
#( #readAsArrayBuffer: #( #blob ) )
#( #readAsText:encoding: #( #blob #encoding ) )
#( #readAsDataURL: #( #blob ) )
)!
URL buildFunctions: #(
#( #createObjectURL:options: #( #blob #options ) )
#( #revokeObjectURL: #( #url ) )
)!
! Blob methodsFor: #initialize !
initializeHandle
" Initialize the handle of the receiver. "
handle := {' new Blob() '}.! !
! Blob class methodsFor: 'instance creation' !
new: blobParts
" Return an instance of the receiver.
See http://www.w3.org/TR/FileAPI/#blob
"
| aHandle |
aHandle := {' new Blob(blobParts) '}.
^self @ aHandle! !
! Blob class methodsFor: 'instance creation' !
new: blobParts options: aBlobPropertyBag
" Return an instance of the receiver.
See http://www.w3.org/TR/FileAPI/#blob
"
| aHandle |
aHandle := {' new Blob(blobParts,aBlobPropertyBag) '}.
^self @ aHandle! !
! Blob class methodsFor: 'instance creation' !
utf8: aString
" Return an instance of the receiver. "
^self new: aString options: (#type -> 'text/plain;charset=UTF-8') json! !
! FileReader methodsFor: #initialize !
initializeHandle
" Initialize the handle of the receiver. "
handle := {' new FileReader() '}.! !
! FileReader class methodsFor: #events !
selectorForHTML5Event: anEvent
" Private - Return the on... selector to use to register binding to anEvent. "
^#on , (anEvent upTo: $:) asLowercase! !
! FileReader class methodsFor: #events !
html5Events
" Private - Return the html5 events managed by instances of the receiver. "
^#(
#progress: #load
#abort #error
#loadstart #loadend
) , super html5Events! !