JQuery.st 6.4 KB

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