Canvas-Snippet.deploy.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. smalltalk.addPackage('Canvas-Snippet', {});
  2. smalltalk.addClass('HtmlSnippet', smalltalk.Object, ['snippets'], 'Canvas-Snippet');
  3. smalltalk.addMethod(
  4. "_addSnippet_",
  5. smalltalk.method({
  6. selector: "addSnippet:",
  7. fn: function (anAssociation){
  8. var self=this;
  9. return smalltalk.withContext(function($ctx1) {
  10. var $2,$1;
  11. $2=self["@snippets"];
  12. if(($receiver = $2) == nil || $receiver == undefined){
  13. self["@snippets"]=smalltalk.HashedCollection._fromPairs_([]);
  14. $1=self["@snippets"];
  15. } else {
  16. $1=$2;
  17. };
  18. _st($1)._add_(anAssociation);
  19. return self}, function($ctx1) {$ctx1.fill(self,"addSnippet:",{anAssociation:anAssociation}, smalltalk.HtmlSnippet)})}
  20. }),
  21. smalltalk.HtmlSnippet);
  22. smalltalk.addMethod(
  23. "_addSnippets_",
  24. smalltalk.method({
  25. selector: "addSnippets:",
  26. fn: function (aCollection){
  27. var self=this;
  28. return smalltalk.withContext(function($ctx1) {
  29. _st(aCollection)._associationsDo_((function(each){
  30. return smalltalk.withContext(function($ctx2) {
  31. return _st(self)._addSnippet_(each);
  32. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  33. return self}, function($ctx1) {$ctx1.fill(self,"addSnippets:",{aCollection:aCollection}, smalltalk.HtmlSnippet)})}
  34. }),
  35. smalltalk.HtmlSnippet);
  36. smalltalk.addMethod(
  37. "_at_",
  38. smalltalk.method({
  39. selector: "at:",
  40. fn: function (aString){
  41. var self=this;
  42. return smalltalk.withContext(function($ctx1) {
  43. var $1;
  44. $1=_st(self["@snippets"])._at_(aString);
  45. return $1;
  46. }, function($ctx1) {$ctx1.fill(self,"at:",{aString:aString}, smalltalk.HtmlSnippet)})}
  47. }),
  48. smalltalk.HtmlSnippet);
  49. smalltalk.addMethod(
  50. "_at_ifAbsent_",
  51. smalltalk.method({
  52. selector: "at:ifAbsent:",
  53. fn: function (aString,aBlock){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. var $1;
  57. $1=_st(self["@snippets"])._at_ifAbsent_(aString,aBlock);
  58. return $1;
  59. }, function($ctx1) {$ctx1.fill(self,"at:ifAbsent:",{aString:aString,aBlock:aBlock}, smalltalk.HtmlSnippet)})}
  60. }),
  61. smalltalk.HtmlSnippet);
  62. smalltalk.HtmlSnippet.klass.iVarNames = ['current'];
  63. smalltalk.addMethod(
  64. "_current",
  65. smalltalk.method({
  66. selector: "current",
  67. fn: function (){
  68. var self=this;
  69. return smalltalk.withContext(function($ctx1) {
  70. var $2,$3,$4,$1;
  71. $2=self["@current"];
  72. if(($receiver = $2) == nil || $receiver == undefined){
  73. $3=_st(self)._new();
  74. _st($3)._addSnippets_(_st(self)._digFromJQuery_(_st(document)._asJQuery()));
  75. $4=_st($3)._yourself();
  76. self["@current"]=$4;
  77. $1=self["@current"];
  78. } else {
  79. $1=$2;
  80. };
  81. return $1;
  82. }, function($ctx1) {$ctx1.fill(self,"current",{}, smalltalk.HtmlSnippet.klass)})}
  83. }),
  84. smalltalk.HtmlSnippet.klass);
  85. smalltalk.addMethod(
  86. "_digFromJQuery_",
  87. smalltalk.method({
  88. selector: "digFromJQuery:",
  89. fn: function (aJQuery){
  90. var self=this;
  91. var result;
  92. return smalltalk.withContext(function($ctx1) {
  93. var $1,$2,$3;
  94. result=smalltalk.HashedCollection._fromPairs_([]);
  95. _st(_st(_st("[data-snippet]")._asJQuery())._toArray())._do_((function(each){
  96. var jq,name;
  97. return smalltalk.withContext(function($ctx2) {
  98. jq=_st(each)._asJQuery();
  99. jq;
  100. name=_st(jq)._attr_("data-snippet");
  101. name;
  102. $1=_st(name).__eq("*");
  103. if(! smalltalk.assert($1)){
  104. $2=_st(_st("^\x5c*")._asRegexp())._test_(name);
  105. if(smalltalk.assert($2)){
  106. name=_st(name)._allButFirst();
  107. name;
  108. _st(jq)._attr_put_("data-snippet","*");
  109. } else {
  110. _st(jq)._removeAttr_("data-snippet");
  111. };
  112. return _st(result)._at_put_(name,_st(_st(jq)._detach())._get_((0)));
  113. };
  114. }, function($ctx2) {$ctx2.fillBlock({each:each,jq:jq,name:name},$ctx1)})}));
  115. $3=result;
  116. return $3;
  117. }, function($ctx1) {$ctx1.fill(self,"digFromJQuery:",{aJQuery:aJQuery,result:result}, smalltalk.HtmlSnippet.klass)})}
  118. }),
  119. smalltalk.HtmlSnippet.klass);
  120. smalltalk.addMethod(
  121. "_asSnippet",
  122. smalltalk.method({
  123. selector: "asSnippet",
  124. fn: function (){
  125. var self=this;
  126. return smalltalk.withContext(function($ctx1) {
  127. var $1;
  128. $1=_st(_st((smalltalk.HtmlSnippet || HtmlSnippet))._current())._at_(_st(self)._asString());
  129. return $1;
  130. }, function($ctx1) {$ctx1.fill(self,"asSnippet",{}, smalltalk.CharacterArray)})}
  131. }),
  132. smalltalk.CharacterArray);
  133. smalltalk.addMethod(
  134. "_doesNotUnderstand_",
  135. smalltalk.method({
  136. selector: "doesNotUnderstand:",
  137. fn: function (aMessage){
  138. var self=this;
  139. var snippet;
  140. return smalltalk.withContext(function($ctx1) {
  141. var $1,$2,$3,$4;
  142. var $early={};
  143. try {
  144. $1=_st(_st(aMessage)._arguments())._isEmpty();
  145. if(! smalltalk.assert($1)){
  146. $2=smalltalk.Object.fn.prototype._doesNotUnderstand_.apply(_st(self), [aMessage]);
  147. return $2;
  148. };
  149. snippet=_st(_st((smalltalk.HtmlSnippet || HtmlSnippet))._current())._at_ifAbsent_(_st(aMessage)._selector(),(function(){
  150. return smalltalk.withContext(function($ctx2) {
  151. $3=smalltalk.Object.fn.prototype._doesNotUnderstand_.apply(_st(self), [aMessage]);
  152. throw $early=[$3];
  153. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  154. $4=_st(self)._snip_(snippet);
  155. return $4;
  156. }
  157. catch(e) {if(e===$early)return e[0]; throw e}
  158. }, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage,snippet:snippet}, smalltalk.HTMLCanvas)})}
  159. }),
  160. smalltalk.HTMLCanvas);
  161. smalltalk.addMethod(
  162. "_snip_",
  163. smalltalk.method({
  164. selector: "snip:",
  165. fn: function (anElement){
  166. var self=this;
  167. var clone,caret;
  168. return smalltalk.withContext(function($ctx1) { var $1,$2;
  169. clone=_st(_st(anElement)._asJQuery())._clone();
  170. _st(self)._with_(_st((smalltalk.TagBrush || TagBrush))._fromJQuery_canvas_(clone,self));
  171. caret=_st(clone)._find_("[data-snippet=\x22*\x22]");
  172. $1=_st(_st(caret)._toArray())._isEmpty();
  173. if(smalltalk.assert($1)){
  174. caret=clone;
  175. caret;
  176. };
  177. $2=_st((smalltalk.TagBrush || TagBrush))._fromJQuery_canvas_(_st(caret)._removeAttr_("data-snippet"),self);
  178. return $2;
  179. }, function($ctx1) {$ctx1.fill(self,"snip:",{anElement:anElement,clone:clone,caret:caret}, smalltalk.HTMLCanvas)})}
  180. }),
  181. smalltalk.HTMLCanvas);