1
0

Canvas-Snippet.deploy.js 5.5 KB

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