jQuery.st 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. Object subclass: #JQuery
  2. instanceVariableNames: 'jquery'
  3. category: 'JQuery'!
  4. !JQuery class methodsFor: 'instance creation'!
  5. fromString: aString
  6. | newJQuery |
  7. {'newJQuery = jQuery(String(aString))'}.
  8. ^self from: newJQuery
  9. !
  10. from: anObject
  11. ^self new
  12. initializeWithJQueryObject: anObject;
  13. yourself
  14. ! !
  15. !JQuery methodsFor: 'attributes'!
  16. removeAttribute: aString
  17. "Remove an attribute from each element in the set of matched elements."
  18. ^self call: 'removeAttribute' withArgument: aString
  19. !
  20. attr: aString
  21. "Get the value of an attribute for the first element in the set of matched elements."
  22. ^self call: 'attr' withArgument: aString
  23. !
  24. val
  25. "Get the current value of the first element in the set of matched elements."
  26. ^self call: 'val'
  27. !
  28. val: aString
  29. self call: 'val' withArgument: aString
  30. ! !
  31. !JQuery methodsFor: 'css'!
  32. cssAt: aString
  33. ^{'return self[''@jquery''].css(aString)'}
  34. !
  35. cssAt: aString put: anotherString
  36. {'self[''@jquery''].css(aString, anotherString)'}
  37. !
  38. addClass: aString
  39. "Adds the specified class(es) to each of the set of matched elements."
  40. self call: 'addClass' withArgument: aString
  41. !
  42. removeClass: aString
  43. "Remove a single class, multiple classes, or all classes from each element in the set of matched elements."
  44. self call: 'removeClass' withArgument: aString
  45. !
  46. toggleClass: aString
  47. "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."
  48. self call: 'toggleClass' withArgument: aString
  49. !
  50. height
  51. "Get the current computed height for the first element in the set of matched elements."
  52. ^self call: 'height'
  53. !
  54. height: anInteger
  55. self call: 'height' withArgument: anInteger
  56. !
  57. width: anInteger
  58. self call: 'width' withArgument: anInteger
  59. !
  60. width
  61. "Get the current computed width for the first element in the set of matched elements."
  62. ^self call: 'width'
  63. !
  64. innerHeight
  65. "Get the current computed height for the first element in the set of matched elements, including padding but not border."
  66. ^self call: 'innerHeight'
  67. !
  68. innerWidth
  69. "Get the current computed width for the first element in the set of matched elements, including padding but not border."
  70. ^self call: 'innerWidth'
  71. !
  72. outerHeight
  73. "Get the current computed height for the first element in the set of matched elements, including padding, border, and optionally margin."
  74. ^self call: 'outerHeight'
  75. !
  76. outerWidth
  77. "Get the current computed width for the first element in the set of matched elements, including padding and border."
  78. ^self call: 'outerWidth'
  79. !
  80. top
  81. "Get the current y coordinate of the first element in the set of matched elements, relative to the offset parent."
  82. ^(self call: 'position') basicAt: 'top'
  83. !
  84. left
  85. "Get the current x coordinate of the first element in the set of matched elements, relative to the offset parent."
  86. ^(self call: 'position') basicAt: 'left'
  87. !
  88. offsetLeft
  89. "Get the current coordinates of the first element in the set of matched elements, relative to the document."
  90. ^(self call: 'offset') basicAt: 'left'
  91. !
  92. offsetTop
  93. "Get the current coordinates of the first element in the set of matched elements, relative to the document."
  94. ^(self call: 'offset') basicAt: 'top'
  95. !
  96. scrollLeft
  97. "Get the current horizontal position of the scroll bar for the first element in the set of matched elements."
  98. ^self call: 'scrollLeft'
  99. !
  100. scrollTop
  101. "Get the current vertical position of the scroll bar for the first element in the set of matched elements."
  102. ^self call: 'scrollTop'
  103. !
  104. scrollLeft: anInteger
  105. self call: 'scrollLeft' withArgument: anInteger
  106. !
  107. scrollTop: anInteger
  108. self call: 'scrollTop' withArgument: anInteger
  109. ! !
  110. !JQuery methodsFor: 'events'!
  111. focus
  112. self call: 'focus'
  113. !
  114. show
  115. self call: 'show'
  116. !
  117. hide
  118. self call: 'hide'
  119. !
  120. remove
  121. self call: 'remove'
  122. !
  123. on: anEventString do: aBlock
  124. "Attach aBlock for anEventString on the element"
  125. {'self[''@jquery''].bind(anEventString, aBlock)'}
  126. !
  127. removeEvents: aString
  128. "Unbind all handlers attached to the event aString"
  129. self call: 'unbind' withArgument: aString
  130. ! !
  131. !JQuery methodsFor: 'DOM insertion'!
  132. append: anObject
  133. "Append anObject at the end of the element."
  134. anObject appendToJQuery: self
  135. !
  136. appendElement: anElement
  137. "Append anElement at the end of the element.
  138. Dont't call this method directly, use #append: instead"
  139. self call: 'append' withArgument: anElement
  140. !
  141. appendToJQuery: aJQuery
  142. aJQuery appendElement: jquery
  143. !
  144. contents: anObject
  145. self empty.
  146. self append: anObject
  147. !
  148. empty
  149. self call: 'empty'
  150. ! !
  151. !JQuery methodsFor: 'initialization'!
  152. initializeWithJQueryObject: anObject
  153. jquery := anObject
  154. ! !
  155. !JQuery methodsFor: 'private'!
  156. call: aString
  157. ^{'return self[''@jquery''][aString]()'}
  158. !
  159. call: aString withArgument: anObject
  160. ^{'return self[''@jquery''][aString](anObject)'}
  161. ! !
  162. !JQuery methodsFor: 'testing'!
  163. hasClass: aString
  164. "Determine whether any of the matched elements are assigned the given class."
  165. ^self call: 'hasClass' withArgument: aString
  166. ! !