Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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
Jag Talon committed Jul 7, 2014
2 parents 0d76e04 + 1f834d5 commit 44c1aac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/App/DuckPAN/Web.pm
Expand Up @@ -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);
Expand Down Expand Up @@ -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});
}
Expand Down
17 changes: 16 additions & 1 deletion share/duckpan.js
Expand Up @@ -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
Expand All @@ -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] = {};
Expand All @@ -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.