Permalink
Browse files

Merge pull request #88 from duckduckgo/zaahir/temp-calltype-self-fix

Force Duckpan to manually call Spice callback after templates are compiled
  • Loading branch information...
jagtalon committed Jul 7, 2014
2 parents 0d76e04 + 1f834d5 commit 44c1aac7acdaa76258c712c0f08293defd485347
Showing with 21 additions and 5 deletions.
  1. +5 −4 lib/App/DuckPAN/Web.pm
  2. +16 −1 share/duckpan.js
View
@@ -269,7 +269,8 @@ sub request {
} elsif ($_->filename =~ /^.+handlebars$/){
my $template_name = $_->filename;
$template_name =~ s/\.handlebars//;
- $calls_template{$spice_name}{$template_name} = $_;
+ $calls_template{$spice_name}{$template_name}{"content"} = $_;
+ $calls_template{$spice_name}{$template_name}{"is_ct_self"} = $result->call_type eq 'self';
}
}
push (@calls_nrj, $result->call_path);
@@ -346,12 +347,12 @@ sub request {
: '';
if (%calls_template) {
-
foreach my $spice_name ( keys %calls_template ){
$calls_script .= join("",map {
my $template_name = $_;
- my $template_content = $calls_template{$spice_name}{$template_name}->slurp;
- "<script class='duckduckhack_spice_template' spice-name='$spice_name' template-name='$template_name' type='text/plain'>$template_content</script>"
+ my $is_ct_self = $calls_template{$spice_name}{$template_name}{"is_ct_self"};
+ my $template_content = $calls_template{$spice_name}{$template_name}{"content"}->slurp;
+ "<script class='duckduckhack_spice_template' spice-name='$spice_name' template-name='$template_name' is-ct-self='$is_ct_self' type='text/plain'>$template_content</script>"
} keys $calls_template{$spice_name});
}
View
@@ -5,7 +5,8 @@ $(document).ready(function() {
DDG.duckpan = true;
// array of spice template <script>
- var hb_templates = $("script.duckduckhack_spice_template");
+ var hb_templates = $("script.duckduckhack_spice_template"),
+ toCall = [];
// Check for any spice templates
// grab their contents and name
@@ -18,6 +19,9 @@ $(document).ready(function() {
content = $script.html();
spiceName = $script.attr("spice-name");
templateName = $script.attr("template-name");
+ if ($script.attr("is-ct-self") === "1"){
+ toCall.push(spiceName);
+ }
if (!Spice.hasOwnProperty(spiceName)) {
Spice[spiceName] = {};
@@ -30,6 +34,17 @@ $(document).ready(function() {
console.log("Finished compiling templates")
console.log("Now Spice obj: ", Spice);
+
+ // Need to wait a little for page JS to finish
+ // modifying the DOM
+ setTimeout(function(){
+ $.each(toCall, function(i, name){
+ var cbName = "ddg_spice_" + name;
+ console.log("Executing: " + cbName);
+ window[cbName]();
+ });
+ }, 100);
+
return;
}
});

0 comments on commit 44c1aac

Please sign in to comment.