JQuery.st 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. Object subclass: #JQuery
  2. instanceVariableNames: 'jquery'
  3. category: 'JQuery'!
  4. !JQuery methodsFor: 'DOM insertion'!
  5. append: anObject
  6. "Append anObject at the end of the element."
  7. anObject appendToJQuery: self
  8. !
  9. appendElement: anElement
  10. "Append anElement at the end of the element.
  11. Dont't call this method directly, use #append: instead"
  12. self call: 'append' withArgument: anElement
  13. !
  14. appendToJQuery: aJQuery
  15. aJQuery appendElement: jquery
  16. !
  17. contents: anObject
  18. self empty.
  19. self append: anObject
  20. !
  21. empty
  22. ^self call: 'empty'
  23. ! !
  24. !JQuery methodsFor: 'accessing'!
  25. jquery
  26. ^jquery
  27. ! !
  28. !JQuery methodsFor: 'attributes'!
  29. removeAttribute: aString
  30. "Remove an attribute from each element in the set of matched elements."
  31. ^self call: 'removeAttribute' withArgument: aString
  32. !
  33. attr: aString
  34. "Get the value of an attribute for the first element in the set of matched elements."
  35. ^self call: 'attr' withArgument: aString
  36. !
  37. val
  38. "Get the current value of the first element in the set of matched elements."
  39. ^self call: 'val'
  40. !
  41. val: aString
  42. self call: 'val' withArgument: aString
  43. ! !
  44. !JQuery methodsFor: 'css'!
  45. cssAt: aString
  46. <return self['@jquery'].css(aString)>
  47. !
  48. cssAt: aString put: anotherString
  49. <self['@jquery'].css(aString, anotherString)>
  50. !
  51. addClass: aString
  52. "Adds the specified class(es) to each of the set of matched elements."
  53. self call: 'addClass' withArgument: aString
  54. !
  55. removeClass: aString
  56. "Remove a single class, multiple classes, or all classes from each element in the set of matched elements."
  57. self call: 'removeClass' withArgument: aString
  58. !
  59. toggleClass: aString
  60. "Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument."
  61. self call: 'toggleClass' withArgument: aString
  62. !
  63. height
  64. "Get the current computed height for the first element in the set of matched elements."
  65. ^self call: 'height'
  66. !
  67. height: anInteger
  68. self call: 'height' withArgument: anInteger
  69. !
  70. width: anInteger
  71. self call: 'width' withArgument: anInteger
  72. !
  73. width
  74. "Get the current computed width for the first element in the set of matched elements."
  75. ^self call: 'width'
  76. !
  77. innerHeight
  78. "Get the current computed height for the first element in the set of matched elements, including padding but not border."
  79. ^self call: 'innerHeight'
  80. !
  81. innerWidth
  82. "Get the current computed width for the first element in the set of matched elements, including padding but not border."
  83. ^self call: 'innerWidth'
  84. !
  85. outerHeight
  86. "Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin."
  87. ^self call: 'outerHeight'
  88. !
  89. outerWidth
  90. "Get the current computed width for the first element in the set of matched elements, including padding and border."
  91. ^self call: 'outerWidth'
  92. !
  93. top
  94. "Get the current y coordinate of the first element in the set of matched elements, relative to the offset parent."
  95. ^(self call: 'position') basicAt: 'top'
  96. !
  97. left
  98. "Get the current x coordinate of the first element in the set of matched elements, relative to the offset parent."
  99. ^(self call: 'position') basicAt: 'left'
  100. !
  101. offsetLeft
  102. "Get the current coordinates of the first element in the set of matched elements, relative to the document."
  103. ^(self call: 'offset') basicAt: 'left'
  104. !
  105. offsetTop
  106. "Get the current coordinates of the first element in the set of matched elements, relative to the document."
  107. ^(self call: 'offset') basicAt: 'top'
  108. !
  109. scrollLeft
  110. "Get the current horizontal position of the scroll bar for the first element in the set of matched elements."
  111. ^self call: 'scrollLeft'
  112. !
  113. scrollTop
  114. "Get the current vertical position of the scroll bar for the first element in the set of matched elements."
  115. ^self call: 'scrollTop'
  116. !
  117. scrollLeft: anInteger
  118. self call: 'scrollLeft' withArgument: anInteger
  119. !
  120. scrollTop: anInteger
  121. self call: 'scrollTop' withArgument: anInteger
  122. ! !
  123. !JQuery methodsFor: 'events'!
  124. focus
  125. self call: 'focus'
  126. !
  127. show
  128. self call: 'show'
  129. !
  130. hide
  131. self call: 'hide'
  132. !
  133. remove
  134. self call: 'remove'
  135. !
  136. on: anEventString do: aBlock
  137. "Attach aBlock for anEventString on the element"
  138. <self['@jquery'].bind(anEventString, function(e){aBlock(e, self)})>
  139. !
  140. removeEvents: aString
  141. "Unbind all handlers attached to the event aString"
  142. self call: 'unbind' withArgument: aString
  143. ! !
  144. !JQuery methodsFor: 'initialization'!
  145. initializeWithJQueryObject: anObject
  146. jquery := anObject
  147. ! !
  148. !JQuery methodsFor: 'private'!
  149. call: aString
  150. <return self['@jquery'][aString]()>
  151. !
  152. call: aString withArgument: anObject
  153. <return self['@jquery'][aString](anObject)>
  154. ! !
  155. !JQuery methodsFor: 'testing'!
  156. hasClass: aString
  157. "Determine whether any of the matched elements are assigned the given class."
  158. ^self call: 'hasClass' withArgument: aString
  159. ! !
  160. !JQuery class methodsFor: 'instance creation'!
  161. fromString: aString
  162. | newJQuery |
  163. <newJQuery = jQuery(String(aString))>.
  164. ^self from: newJQuery
  165. !
  166. from: anObject
  167. ^self new
  168. initializeWithJQueryObject: anObject;
  169. yourself
  170. !
  171. window
  172. <return self._from_(jQuery(window))>
  173. !
  174. body
  175. <return self._from_(jQuery('body'))>
  176. !
  177. document
  178. <return self._from_(jQuery(document))>
  179. !
  180. fromElement: anElement
  181. | newJQuery |
  182. <newJQuery = jQuery(anElement)>.
  183. ^self from: newJQuery
  184. !
  185. documentReady: aBlock
  186. <jQuery(document).ready(aBlock)>
  187. ! !
  188. Object subclass: #Ajax
  189. instanceVariableNames: 'settings'
  190. category: 'JQuery'!
  191. !Ajax commentStamp!
  192. instance variable names:
  193. - settings A set of key/value pairs that configure the Ajax request. All settings are optional.
  194. Full list of settings options at http://api.jquery.com/jQuery.ajax/!
  195. !Ajax methodsFor: 'accessing'!
  196. at: aKey
  197. ^settings at: aKey ifAbsent: [nil]
  198. !
  199. at: aKey put: aValue
  200. settings at: aKey put: aValue
  201. !
  202. url
  203. ^self at: 'url'
  204. !
  205. url: aString
  206. self at: 'url' put: aString
  207. ! !
  208. !Ajax methodsFor: 'actions'!
  209. send
  210. <jQuery.ajax(self['@settings'])>
  211. ! !
  212. !Ajax methodsFor: 'initialization'!
  213. initialize
  214. super initialize.
  215. settings := Dictionary new
  216. ! !
  217. !Ajax class methodsFor: 'instance creation'!
  218. url: aString
  219. ^self new
  220. url: aString;
  221. yourself
  222. ! !
  223. !BlockClosure methodsFor: '*JQuery'!
  224. appendToJQuery: aJQuery
  225. self value: (HTMLCanvas onJQuery: aJQuery)
  226. ! !
  227. !String methodsFor: '*JQuery'!
  228. asJQuery
  229. ^JQuery fromString: self
  230. !
  231. appendToJQuery: aJQuery
  232. <aJQuery._appendElement_(String(self))>
  233. ! !
  234. !HTMLCanvas methodsFor: '*JQuery'!
  235. appendToJQuery: aJQuery
  236. aJQuery appendElement: root element
  237. ! !