From e6b533d85a40d56ee5a17d60e195479e79a6234c Mon Sep 17 00:00:00 2001 From: Kevin Hill Date: Sun, 17 Jan 2016 10:54:04 -0800 Subject: [PATCH] wrapped dashboard js in jvent function. passing google in as param. --- javascript/lava.js | 6 +++-- src/Javascript/ChartFactory.php | 3 +-- src/Javascript/DashboardFactory.php | 41 +++++++++++++++-------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/javascript/lava.js b/javascript/lava.js index 61a7251d..97cc0217 100644 --- a/javascript/lava.js +++ b/javascript/lava.js @@ -76,6 +76,8 @@ var lava = lava || {}; this.ready = function (callback) { if (typeof callback !== 'function') { throw new Error('[Lavacharts] ' + typeof callback + ' is not a valid callback.'); + } else { + var callback = function(){}; } lava.readyCallback = callback; @@ -201,7 +203,7 @@ var lava = lava || {}; }; /** - * Redraws all of the registed charts on screen. + * Redraws all of the registered charts on screen. * * * This method is attached to the window resize event with a 300ms debounce @@ -231,7 +233,7 @@ var lava = lava || {}; if (event.type === "load" || (/loaded|complete/.test(this.readyState))) { this.onload = this.onreadystatechange = null; - lava.events.emit('jsapi:ready'); + lava.events.emit('jsapi:ready', window.google); } }; diff --git a/src/Javascript/ChartFactory.php b/src/Javascript/ChartFactory.php index b20f1c8f..3861342b 100644 --- a/src/Javascript/ChartFactory.php +++ b/src/Javascript/ChartFactory.php @@ -143,7 +143,7 @@ private function buildFormatters() private function getTemplate() { return <<<'CHART' - lava.events.on('jsapi:ready', function() { + lava.events.on('jsapi:ready', function (google) { /** * If the object does not exist for a given chart type, initialize it. * This will prevent overriding keys when multiple charts of the same @@ -195,7 +195,6 @@ private function getTemplate() packages: [''], callback: function() { lava.charts.[""].render(); - //lava.readyCallback(); } }); }); diff --git a/src/Javascript/DashboardFactory.php b/src/Javascript/DashboardFactory.php index c15fc4bb..977617b5 100644 --- a/src/Javascript/DashboardFactory.php +++ b/src/Javascript/DashboardFactory.php @@ -149,34 +149,35 @@ private function mapWrapperArray($wrapperArray) private function getTemplate() { return <<<'DASH' - //Checking if dashboard div exists - if (! document.getElementById("")) { - throw new Error('[Lavacharts] No matching element was found with ID ""'); - } + lava.events.on('jsapi:ready', function (google) { + //Checking if dashboard div exists + if (! document.getElementById("")) { + throw new Error('[Lavacharts] No matching element was found with ID ""'); + } - lava.dashboards["