JQuery.st 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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%20variable%20names%3A%0A-%20settings%20%20A%20set%20of%20key/value%20pairs%20that%20configure%20the%20Ajax%20request.%20All%20settings%20are%20optional.%0A%0AFull%20list%20of%20settings%20options%20at%20http%3A//api.jquery.com/jQuery.ajax/%0A!
  181. !Ajax methodsFor: 'accessing'!
  182. at: aKey
  183. ^settings at: aKey ifAbsent: [nil]
  184. !
  185. at: aKey put: aValue
  186. settings at: aKey put: aValue
  187. !
  188. url
  189. ^self at: 'url'
  190. !
  191. url: aString
  192. self at: 'url' put: aString
  193. ! !
  194. !Ajax methodsFor: 'actions'!
  195. send
  196. {'jQuery.ajax(self[''@settings''])'}
  197. ! !
  198. !Ajax methodsFor: 'initialization'!
  199. initialize
  200. super initialize.
  201. settings := Dictionary new
  202. ! !
  203. !Ajax class methodsFor: 'instance creation'!
  204. url: aString
  205. ^self new
  206. url: aString;
  207. yourself
  208. ! !
  209. appendToJQuery: aJQuery
  210. | canvas |
  211. canvas := HTMLCanvas new.
  212. self value: canvas.
  213. aJQuery append: canvas
  214. !
  215. asJQuery
  216. ^JQuery fromString: self
  217. !
  218. appendToJQuery: aJQuery
  219. {'aJQuery._appendElement_(String(self))'}
  220. !
  221. appendToJQuery: aJQuery
  222. aJQuery appendElement: root element
  223. !