|
107 | 107 | sub pp { Data::Dumper->new([@_])->Useqq(1)->Terse(1)->Pair('=>') |
108 | 108 | ->Sortkeys(1)->Quotekeys(0)->Indent(0)->Purity(1)->Dump } |
109 | 109 |
|
110 | | -$jq->('#perlinfo')->text("perl $^V"); |
111 | | - |
112 | 110 | sub sample_init { |
113 | 111 | my $samp = shift; |
114 | 112 | my $samptxt = $samp->children(".samptxt"); |
|
154 | 152 | } |
155 | 153 | $addsamp->click(sub { newsamp('')->click }); |
156 | 154 |
|
157 | | -our $re_debug=0; |
| 155 | +our $re_debug=0; #TODO Later: this is actually a parameter to update() |
158 | 156 | my $ta_debugout = $jq->('#debugout'); |
159 | 157 | my $re_debug_hide = $jq->('#re_debug_hide'); |
160 | 158 | $jq->('#re_debug')->click(sub { |
|
188 | 186 | $codecopy->hide; |
189 | 187 | $sampcodebtn->text('Show Example Perl Code'); |
190 | 188 | } |
191 | | - else { |
192 | | - $samplecode_ta->show; |
193 | | - $codecopy->show; |
194 | | - $sampcodebtn->text('Hide Example Perl Code'); |
195 | | - update(); |
196 | | - } |
| 189 | + else { sampcode_show() } |
197 | 190 | }); |
| 191 | +sub sampcode_show { |
| 192 | + $samplecode_ta->show; |
| 193 | + $codecopy->show; |
| 194 | + $sampcodebtn->text('Hide Example Perl Code'); |
| 195 | + update(); |
| 196 | +} |
198 | 197 | $codecopy->click(sub { |
199 | 198 | $samplecode_ta->[0]->select; |
200 | 199 | js(q{ document.execCommand("copy"); }); |
|
209 | 208 | $precode_ta->hide; |
210 | 209 | $precodebtn->text("Add Preamble Code"); |
211 | 210 | } |
212 | | - else { |
213 | | - $precode_ta->show; |
214 | | - $precodebtn->text("Disable Preamble Code"); |
215 | | - } |
| 211 | + else { precode_show() } |
216 | 212 | update(); |
217 | 213 | }); |
| 214 | +sub precode_show { |
| 215 | + $precode_ta->text(shift) if @_; |
| 216 | + $precode_ta->show; |
| 217 | + $precodebtn->text("Disable Preamble Code"); |
| 218 | +} |
218 | 219 | $precode_ta->hide; |
219 | 220 | $precode_ta->change(\&update); |
220 | 221 | $precode_ta->keyup( \&update); |
221 | 222 |
|
222 | 223 | my $thisurl_ta = $jq->("#thisurl"); |
| 224 | +$jq->('#urlcopy')->click(sub { |
| 225 | + $thisurl_ta->[0]->select; |
| 226 | + js(q{ document.execCommand("copy"); }); |
| 227 | +}); |
| 228 | + |
| 229 | +$jq->('#perlinfo')->text("perl $^V"); |
| 230 | + |
223 | 231 | my $ta_regex = $jq->("#regex"); |
224 | 232 | my $ta_flags = $jq->("#flags"); |
225 | | -my $warnmsgs = $jq->("#warnmsgs"); |
226 | 233 | $ta_regex->change(\&update); |
227 | 234 | $ta_regex->keyup( \&update); |
228 | 235 | $ta_flags->change(\&update); |
229 | 236 | $ta_flags->keyup( \&update); |
230 | | -update(); |
| 237 | + |
| 238 | +js('$(window)')->on('hashchange',\&hashchange); |
231 | 239 |
|
232 | 240 | $ta_regex->on('input', sub { |
233 | 241 | $ta_regex->height($ta_regex->[0]->{scrollHeight}); |
234 | 242 | }); |
235 | 243 |
|
| 244 | +hashchange(); |
| 245 | +update(); |
| 246 | + |
236 | 247 | sub run_code { |
237 | 248 | my ($code,$inp) = @_; |
238 | 249 | my @warns; |
|
264 | 275 | ." Here, a workaround is used so it acts as a true empty pattern.\n" unless length $regex; |
265 | 276 | $warn .= "\\n is recommended over literal newlines\n" if $regex=~/\n/ && $flags!~/x/; |
266 | 277 | $warn .= "\\t is recommended over literal tabs\n" if $regex=~/\t/ && $flags!~/x/; |
| 278 | + state $warnmsgs = $jq->("#warnmsgs"); |
267 | 279 | $warnmsgs->text($warn); |
268 | 280 |
|
269 | 281 | # apply regex to the samples and do highlighting |
|
372 | 384 | $thisurl_ta->text( $baseurl . $hash ); |
373 | 385 | } |
374 | 386 |
|
375 | | -$jq->('#urlcopy')->click(sub { |
376 | | - $thisurl_ta->[0]->select; |
377 | | - js(q{ document.execCommand("copy"); }); |
378 | | -}); |
379 | | - |
380 | 387 | sub hashchange { |
381 | 388 | my $hash = js('window.location')->{hash}; |
382 | 389 | return unless $hash=~/^#.*\bregex=/; |
|
390 | 397 | $ta_regex->text($res{regex}); |
391 | 398 | $ta_regex->height($ta_regex->[0]->{scrollHeight}); |
392 | 399 | $ta_flags->text($res{flags}); |
393 | | - if ($res{showsampcode}) { |
394 | | - $samplecode_ta->show; |
395 | | - $codecopy->show; |
396 | | - $sampcodebtn->text('Hide Example Perl Code'); |
397 | | - } |
398 | | - if (exists $res{pre}) { |
399 | | - $precode_ta->text($res{pre}); |
400 | | - $precode_ta->show; |
401 | | - $precodebtn->text("Disable Preamble Code"); |
402 | | - } |
| 400 | + sampcode_show() if $res{showsampcode}; |
| 401 | + precode_show($res{pre}) if exists $res{pre}; |
403 | 402 | if (exists $res{samp1}) { |
404 | 403 | $jq->(".sample")->remove(); |
405 | 404 | for (my $i=1;exists $res{"samp$i"};$i++) { |
|
410 | 409 | } |
411 | 410 | else { js('window.location')->{hash}='' } |
412 | 411 | } |
413 | | -hashchange(); |
414 | | -js('$(window)')->on('hashchange',\&hashchange); |
415 | 412 |
|
416 | 413 | </script> |
417 | 414 |
|
|
0 commit comments