JQuery.st 6.4 KB

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