diff --git a/application/forms/Dashboard/AddUrlForm.php b/application/forms/Dashboard/AddUrlForm.php index 42a205a27..bd7bd2e19 100644 --- a/application/forms/Dashboard/AddUrlForm.php +++ b/application/forms/Dashboard/AddUrlForm.php @@ -56,7 +56,8 @@ class AddUrlForm extends Form array( 'label' => 'Dashboard', 'required' => true, - 'style' => 'display:inline-block', + 'style' => 'display:inline-block;', + 'multiOptions' => $dashboard->getPaneKeyTitleArray() ) ); @@ -64,8 +65,9 @@ class AddUrlForm extends Form $newDashboardBtn = new Zend_Form_Element_Submit( 'create_new_pane', array( - 'label' => '+', + 'label' => 'Create A New Pane', 'required' => false, + 'class' => 'btn btn-default', 'style' => 'display:inline-block' ) ); @@ -83,7 +85,7 @@ class AddUrlForm extends Form * Add a textfield for creating a new pane to this form * */ - private function addNewPaneTextField() + private function addNewPaneTextField($showExistingButton = true) { $txtCreatePane = new Zend_Form_Element_Text( 'pane', @@ -106,18 +108,22 @@ class AddUrlForm extends Form $cancelDashboardBtn = new Zend_Form_Element_Submit( 'use_existing_dashboard', array( - 'label' => '{{REMOVE_ICON}}', - 'required' => false, - 'style' => 'display:inline-block' + 'class' => 'btn', + 'escape' => false, + 'label' => 'Use An Existing Dashboard', + 'required' => false ) ); + $cancelDashboardBtn->removeDecorator('DtDdWrapper'); $txtCreatePane->removeDecorator('DtDdWrapper'); $txtCreatePane->removeDecorator('htmlTag'); $this->addElement($txtCreatePane); - $this->addElement($cancelDashboardBtn); + if ($showExistingButton) { + $this->addElement($cancelDashboardBtn); + } $this->addElement($markAsNewPane); } @@ -146,7 +152,7 @@ class AddUrlForm extends Form !$this->getRequest()->getPost('use_existing_dashboard', '0')) // and the user didn't click the 'use // existing' button ) { - $this->addNewPaneTextField(); + $this->addNewPaneTextField(!empty($elems)); } else { $this->addPaneSelectionBox($dashboard); } @@ -159,7 +165,7 @@ class AddUrlForm extends Form 'required' => true, ) ); - $this->setSubmitLabel("{{CREATE_ICON}} Add To Dashboard"); + $this->setSubmitLabel("Add To Dashboard"); } } diff --git a/application/views/scripts/dashboard/addurl.phtml b/application/views/scripts/dashboard/addurl.phtml index 047cbdf0d..35c505139 100644 --- a/application/views/scripts/dashboard/addurl.phtml +++ b/application/views/scripts/dashboard/addurl.phtml @@ -1,3 +1,5 @@ -

Add Dashboard URL

+

Hosts Status

-form->render($this); ?> \ No newline at end of file +
+form->render($this); ?> +
\ No newline at end of file diff --git a/application/views/scripts/dashboard/index.phtml b/application/views/scripts/dashboard/index.phtml index 6b1e5c9bb..0d6fd9ef0 100644 --- a/application/views/scripts/dashboard/index.phtml +++ b/application/views/scripts/dashboard/index.phtml @@ -1,3 +1,5 @@ tabs->render($this); ?> -dashboard->render($this); ?> \ No newline at end of file +
+dashboard->render($this); ?> +
\ No newline at end of file diff --git a/library/Icinga/Chart/Palette.php b/library/Icinga/Chart/Palette.php index 7523da8d6..1dd5f9906 100644 --- a/library/Icinga/Chart/Palette.php +++ b/library/Icinga/Chart/Palette.php @@ -59,10 +59,10 @@ class Palette * @var array */ public $colorSets = array( - self::OK => array('#00FF00','#00C90D', '#008209', '#238C47', '#00BB3F', '#37DD6F'), - self::PROBLEM => array('#FF0000','#FF1300', '#FF4E40', '#A60C00', '#FF4500', '#A62D00'), - self::WARNING => array('#FFFF00', 'B4B400' , '#A6A600', '#F5FF73', '#FFB300', '#BFA730'), - self::NEUTRAL => array('#232323', '#009999', '#1D7373', '#ACACFF', '#8F9ABF', '#356AA6') + self::OK => array('#00FF00'), + self::PROBLEM => array('#FF0000'), + self::WARNING => array('#FFFF00'), + self::NEUTRAL => array('#f3f3f3') ); /** @@ -79,8 +79,10 @@ class Palette } $color = current($this->colorSets[$type]); + echo $type; if ($color === false) { reset($this->colorSets[$type]); + $color = current($this->colorSets[$type]); } next($this->colorSets[$type]); diff --git a/library/Icinga/Chart/PieChart.php b/library/Icinga/Chart/PieChart.php index 98581c7b8..fbd2645da 100644 --- a/library/Icinga/Chart/PieChart.php +++ b/library/Icinga/Chart/PieChart.php @@ -112,6 +112,9 @@ class PieChart extends Chart if ($total === 100) { return; } + if ($total == 0) { + return; + } foreach ($pie['data'] as &$slice) { $slice = $slice/$total * 100; } @@ -181,7 +184,7 @@ class PieChart extends Chart private function getColorForPieSlice(array $pie, $dataIdx) { if (isset($pie['colors']) && is_array($pie['colors']) && isset($pie['colors'][$dataIdx])) { - return $pie['colors']['dataIdx']; + return $pie['colors'][$dataIdx]; } $type = Palette::NEUTRAL; if (isset($pie['palette']) && is_array($pie['palette']) && isset($pie['palette'][$dataIdx])) { @@ -203,6 +206,7 @@ class PieChart extends Chart foreach ($this->pies as $pie) { $labelPos = 0; $lastRadius = 0; + foreach ($pie['data'] as $idx => $dataset) { $slice = new PieSlice($radius, $dataset, $lastRadius); $slice->setX($x) @@ -244,13 +248,21 @@ class PieChart extends Chart $offset = isset($this->pies[$i+1]) ? $radius - $shrinkStep : 0; $labelPos = 0; $lastRadius = 0; - foreach ($pie['data'] as $idx => $dataset) { + foreach ($pie['data'] as $idx => $dataset) { + $color = $this->getColorForPieSlice($pie, $idx); + if ($dataset === 100) { + $dataset = 99.9; + } + if ($dataset == 0) { + $labelPos++; + continue; + } $slice = new PieSlice($radius, $dataset, $lastRadius); $slice->setY(50) ->setX($x) ->setStrokeColor('#000') ->setStrokeWidth(1) - ->setFill($this->getColorForPieSlice($pie, $idx)) + ->setFill($color) ->setLabelGroup($labelBox); if (!$this->noCaption && isset($pie['labels'])) { diff --git a/library/Icinga/Chart/Primitive/PieSlice.php b/library/Icinga/Chart/Primitive/PieSlice.php index e8f1e93a5..37b92d138 100644 --- a/library/Icinga/Chart/Primitive/PieSlice.php +++ b/library/Icinga/Chart/Primitive/PieSlice.php @@ -178,13 +178,13 @@ class PieSlice extends Animatable implements Drawable $midX += ($addOffset + $r/1.8) * ($midRadius > M_PI ? -1 : 1); $path->append(array($midX, $midY))->toAbsolute(); - $midX += intval($r/2 * sin(M_PI/7)) * ($midRadius > M_PI ? -1 : 1); + $midX += intval($r/2 * sin(M_PI/9)) * ($midRadius > M_PI ? -1 : 1); $midY -= intval($r/2 * cos(M_PI/7)) * ($midRadius < M_PI*1.5 && $midRadius > M_PI/2 ? -1 : 1); if ($ctx->ytoRelative($midY) > 100) { $midY = $ctx->yToAbsolute(100); } elseif ($ctx->ytoRelative($midY) < 0) { - $midY = $ctx->yToAbsolute(0); + $midY = $ctx->yToAbsolute($ctx->ytoRelative(100+$midY)); } $path->append(array($midX , $midY)); diff --git a/library/Icinga/Chart/Unit/LinearUnit.php b/library/Icinga/Chart/Unit/LinearUnit.php index 1c3973a12..eb69ea5b6 100644 --- a/library/Icinga/Chart/Unit/LinearUnit.php +++ b/library/Icinga/Chart/Unit/LinearUnit.php @@ -74,13 +74,13 @@ class LinearUnit implements AxisUnit * * @var int */ - private $currentTick = 0; + protected $currentTick = 0; /** * The currently displayed value * @var int */ - private $currentValue = 0; + protected $currentValue = 0; /** * Create and initialize this AxisUnit diff --git a/library/Icinga/Filter/Query/Tree.php b/library/Icinga/Filter/Query/Tree.php index 5c1690fff..fcfa87fa7 100644 --- a/library/Icinga/Filter/Query/Tree.php +++ b/library/Icinga/Filter/Query/Tree.php @@ -250,6 +250,7 @@ class Tree */ public static function normalizeTree($node) { + if ($node->type === Node::TYPE_OPERATOR) { return $node; } diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index d5f71e908..613e82b4e 100755 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -201,6 +201,9 @@ class ActionController extends Zend_Controller_Action if ($this->_request->isXmlHttpRequest()) { $target = ($this->getParam('render') === 'detail') ? 'inline' : 'body'; + if ($target !== 'inline') { + $target = ($this->getParam('view') === 'compact') ? 'inline' : 'body'; + } $this->_helper->layout()->setLayout($target); } } diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index a3e118253..2ed1aaea6 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -612,7 +612,9 @@ class Form extends Zend_Form $el->removeDecorator('Label'); $el->removeDecorator('DtDdWrapper'); $el->addDecorator(new BootstrapForm()); - $el->setAttrib('class', $el->getAttrib('class') . ' form-control input-sm'); + if ($el->getId() === 'btn_submit' || stripos($el->getAttrib('class'), 'btn') === false) { + $el->setAttrib('class', $el->getAttrib('class') . ' form-control input-sm'); + } } return $this; diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php index c71b3d5e8..719089b18 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Component.php @@ -29,9 +29,13 @@ namespace Icinga\Web\Widget\Dashboard; use Icinga\Util\Dimension; +use Icinga\Web\Form; use Icinga\Web\Url; use Icinga\Web\Widget\Widget; +use Zend_View_Abstract; use Zend_Config; +use Zend_Form_Element_Submit; +use Zend_Form_Element_Button; /** * A dashboard pane component @@ -81,18 +85,16 @@ class Component implements Widget */ private $template =<<<'EOD' -
-
- {TITLE} - -
-
- +
+

{TITLE}

+ {REMOVE_BTN} +
+
+ +
EOD; @@ -194,11 +196,27 @@ EOD; /** * @see Widget::render() */ - public function render(\Zend_View_Abstract $view) + public function render(Zend_View_Abstract $view) { $url = clone($this->url); $url->addParams(array('view' => 'compact')); + $html = str_replace('{URL}', $url->getAbsoluteUrl(), $this->template); + $html = str_replace('{FULL_URL}', $url->getUrlWithout('view')->getAbsoluteUrl(), $html); + $html = str_replace('{REMOVE_BTN}', $this->getRemoveForm($view), $html); + $html = str_replace('{DIMENSION}', $this->getBoxSizeAsCSS(), $html); + $html = str_replace('{TITLE}', htmlentities($this->getTitle()), $html); + return $html; + } + + /** + * Render the form for removing a dashboard elemetn + * + * @param Zend_View_Abstract $view The view to use for rendering + * @return string The html representation of the form + */ + public function getRemoveForm(Zend_View_Abstract $view) + { $removeUrl = Url::fromPath( '/dashboard/removecomponent', array( @@ -206,12 +224,18 @@ EOD; 'component' => $this->getTitle() ) ); - - $html = str_replace('{URL}', $url->getAbsoluteUrl(), $this->template); - $html = str_replace('{REMOVE_URL}', $removeUrl, $html); - $html = str_replace('{DIMENSION}', $this->getBoxSizeAsCSS(), $html); - $html = str_replace('{TITLE}', htmlentities($this->getTitle()), $html); - return $html; + $form = new Form(); + $form->setMethod('POST'); + $form->setAction($removeUrl); + $form->addElement(new Zend_Form_Element_Button( + 'remove_pane_btn', + array( + 'class'=> 'btn btn-danger pull-right', + 'type' => 'submit', + 'label' => 'Remove' + ) + )); + return $form->render($view); } /** diff --git a/modules/monitoring/application/controllers/ChartController.php b/modules/monitoring/application/controllers/ChartController.php index ff6c67cd3..7a5b3d97b 100644 --- a/modules/monitoring/application/controllers/ChartController.php +++ b/modules/monitoring/application/controllers/ChartController.php @@ -33,8 +33,11 @@ use Icinga\Web\Form; use Icinga\Web\Controller\ActionController; use Icinga\Chart\SVGRenderer; use Icinga\Chart\GridChart; +use Icinga\Module\Monitoring\DataView\Groupsummary as GroupsummaryView; use Icinga\Module\Monitoring\Backend; +use Icinga\Chart\Palette; use Icinga\Chart\Axis; +use Icinga\Chart\PieChart; /** * Class Monitoring_CommandController @@ -65,7 +68,7 @@ class Monitoring_ChartController extends ActionController */ public function init() { - $this->backend = Backend::getInstance($this->_getParam('backend')); + } public function testAction() { @@ -100,7 +103,7 @@ class Monitoring_ChartController extends ActionController $this->chart->drawBars( array( 'label' => 'Some other line', - 'color' => 'black', + 'color' => 'green', 'data' => $data3, 'showPoints' => true ) @@ -111,11 +114,72 @@ class Monitoring_ChartController extends ActionController 'label' => 'Nr of outtakes', 'color' => 'yellow', 'width' => '5', - 'data' => $data2 ) ); $this->view->svg = $this->chart; } + + public function hostgroupAction() + { + $query = GroupsummaryView::fromRequest( + $this->_request, + array( + 'hostgroup_name', + 'cnt_hosts_up', + 'cnt_hosts_unreachable', + 'cnt_hosts_unreachable_unhandled', + 'cnt_hosts_down', + 'cnt_hosts_down_unhandled', + 'cnt_hosts_pending', + 'cnt_services_ok', + 'cnt_services_unknown', + 'cnt_services_unknown_unhandled', + 'cnt_services_critical', + 'cnt_services_critical_unhandled', + 'cnt_services_warning', + 'cnt_services_warning_unhandled', + 'cnt_services_pending' + ) + )->getQuery()->fetchRow(); + + $this->view->chart = new PieChart(); + $this->view->chart->drawPie( + array( + 'data' => array( + (int) $query->cnt_hosts_up, + (int) $query->cnt_hosts_down, + (int) $query->cnt_hosts_unreachable, + (int) $query->cnt_hosts_pending + ), + 'colors' => array('00ff00', 'ff0000', 'ffff00', 'fefefe'), + 'labels'=> array( + (int) $query->cnt_hosts_up . ' Up Hosts', + (int) $query->cnt_hosts_down . ' Down Hosts', + (int) $query->cnt_hosts_unreachable . ' Unreachable Hosts', + (int) $query->cnt_hosts_pending . ' Pending Hosts' + ) + ), + array( + 'data' => array( + (int) $query->cnt_services_ok, + (int) $query->cnt_services_warning, + (int) $query->cnt_services_critical, + (int) $query->cnt_services_unknown, + (int) $query->cnt_services_pending + ), + 'colors' => array('00ff00', 'ffff00','ff0000', 'efef00', 'fefefe'), + 'labels'=> array( + $query->cnt_services_ok . ' Up Services', + $query->cnt_services_warning . ' Warning Services', + $query->cnt_services_critical . ' Down Services', + $query->cnt_services_unknown . ' Unreachable Services', + $query->cnt_services_pending . ' Pending Services' + ) + ) + + ); + + } } \ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/chart/hostgroup.phtml b/modules/monitoring/application/views/scripts/chart/hostgroup.phtml new file mode 100644 index 000000000..5799b9d19 --- /dev/null +++ b/modules/monitoring/application/views/scripts/chart/hostgroup.phtml @@ -0,0 +1,6 @@ + +
+ render(); + ?> +
\ No newline at end of file diff --git a/modules/monitoring/application/views/scripts/list/hosts-compact.phtml b/modules/monitoring/application/views/scripts/list/hosts-compact.phtml index 409a19022..731516ce6 100644 --- a/modules/monitoring/application/views/scripts/list/hosts-compact.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts-compact.phtml @@ -1,94 +1,87 @@ getHelper('MonitoringState'); ?> +
+ + + + + + util()->getHostStateName($host->host_state)); ?> + href('monitoring/show/host', array('host' => $host->host_name)); ?> + activeRowHref === $hostLink) ? 'class="active"' : ''; ?> > + + + + + + + + + + -paginationControl($hosts, null, null, array('preserve' => $this->preserve)) ?> -
+ + + host_handled && $host->host_state > 0): ?> + + + + + + host_acknowledged && !$host->host_in_downtime): ?> + + + + + + host_is_flapping): ?> + + + + + + host_notifications_enabled): ?> + + + + + + host_in_downtime): ?> + + + + + + host_active_checks_enabled): ?> + host_passive_checks_enabled): ?> + + + + + + + + + + + host_last_comment !== null): ?> + + + + + + + host_name ?> + + +
+ escape(substr(strip_tags($host->host_output), 0, 10000)); ?> +
+
- - - - - - - - - - - - - - - - - -
StatusHostOutput
-
- host_icon_image) : ?> - - -
-
-
- host_handled && $host->host_state > 0): ?> - - {{UNHANDLED_ICON}} - - - host_acknowledged && !$host->host_in_downtime): ?> - - {{ACKNOWLEDGED_ICON}} - - - host_is_flapping): ?> - - {{FLAPPING_ICON}} - - - host_notifications_enabled): ?> - - {{NOTIFICATIONS_DISABLED_ICON}} - - - host_in_downtime): ?> - - {{IN_DOWNTIME_ICON}} - - -
-
- - - host_last_comment !== null): ?> - - {{COMMENT_ICON}} - - - - host_name; ?> -
- host_address; ?> -
- host_action_url != ''): ?> - Action - - host_notes_url != ''): ?> - Notes - -
- escape(substr(strip_tags($host->host_output), 0, 500)); ?> -
+ + +
diff --git a/modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php b/modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php index de3e77d9a..90451dbac 100644 --- a/modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php +++ b/modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php @@ -107,6 +107,9 @@ class UrlViewFilter public function normalizeTreeNode($node, Tree $subTree = null) { $subTree = $subTree ? $subTree : new Tree(); + if (!$node) { + return $subTree; + } if ($node->type === Node::TYPE_OPERATOR) { $this->insertNormalizedOperatorNode($node, $subTree); } else { diff --git a/public/css/icinga/main.less b/public/css/icinga/main.less index a00dfd73a..449960c85 100644 --- a/public/css/icinga/main.less +++ b/public/css/icinga/main.less @@ -457,5 +457,12 @@ select.input-sm { } .panel-body { +} +.dashboard-component { + border: 1px solid @lightgrey; + float:left; + width:45%; + padding:1%; + margin:1%; } \ No newline at end of file diff --git a/public/js/icinga/components/container.js b/public/js/icinga/components/container.js index f38c70a28..cd5a0f337 100644 --- a/public/js/icinga/components/container.js +++ b/public/js/icinga/components/container.js @@ -401,6 +401,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe mainDom.addClass('col-xs-pull-12 col-sm-pull-12 col-md-pull-12 col-lg-7'); detailDom.addClass('col-xs-push-12 col-sm-push-12 col-md-push-12 col-lg-5'); + $(window).trigger('layoutchange'); }; /** @@ -426,6 +427,7 @@ define(['jquery', 'logging', 'icinga/componentLoader', 'URIjs/URI', 'URIjs/URITe mainDom.addClass('col-sm-12'); detailDom.addClass('hidden-sm'); detailDom.removeAttr('data-icinga-href'); + $(window).trigger('layoutchange'); }; /** * Injects the icinga object into the Container class diff --git a/public/js/icinga/components/dashboard.js b/public/js/icinga/components/dashboard.js new file mode 100644 index 000000000..cb08e6af4 --- /dev/null +++ b/public/js/icinga/components/dashboard.js @@ -0,0 +1,70 @@ +/*global Icinga:false, document: false, define:false require:false base_url:false console:false */ +// {{{ICINGA_LICENSE_HEADER}}} +/** + * This file is part of Icinga 2 Web. + * + * Icinga 2 Web - Head for multiple monitoring backends. + * Copyright (C) 2013 Icinga Development Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * @copyright 2013 Icinga Development Team + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + */ +// {{{ICINGA_LICENSE_HEADER}}} + +/** + * Dashboard container, uses freetile for layout + * + */ +define(['jquery', 'logging', 'URIjs/URI', 'icinga/componentLoader'], function($, log, URI, components) { + 'use strict'; + return function(parent) { + this.dom = $(parent); + var dashboardContainer = this.dom.parent('div'); + dashboardContainer.freetile(); + this.container = this.dom.children('.container'); + this.dashboardUrl = this.dom.attr('data-icinga-url'); + var reloadTimeout = null; + + /** + * Refresh the container content and layout + */ + this.refresh = function() { + $.ajax({ + url: this.dashboardUrl + }).done((function(response) { + this.container.html(response); + dashboardContainer.freetile('layout'); + $(window).on('layoutchange', function() { + dashboardContainer.freetile('layout'); + }); + this.triggerRefresh(); + components.load(); + }).bind(this)).fail((function(response, reason) { + this.container.html(response); + }).bind(this)); + }; + + this.triggerRefresh = function() { + if (reloadTimeout) { + clearTimeout(reloadTimeout); + } + setTimeout(this.refresh.bind(this), 10000); + }; + this.refresh(); + }; +}); \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index 79cf52d29..39ee1a814 100755 --- a/public/js/main.js +++ b/public/js/main.js @@ -4,6 +4,7 @@ requirejs.config({ 'paths': { 'jquery': 'vendor/jquery-1.8.3', 'jquery_scrollto': 'vendor/jquery.scrollto', + 'freetile': 'vendor/freetile', 'bootstrap': 'vendor/bootstrap/bootstrap.min', 'logging': 'icinga/util/logging', 'URIjs': 'vendor/uri', @@ -13,9 +14,13 @@ requirejs.config({ 'datetimepicker': { 'exports': 'datetimepicker' }, + 'jquery_scrollto': { exports: 'jquery_scrollto' }, + 'freetile': { + exports: 'freetile' + }, 'jquery' : { exports: 'jquery' } @@ -26,7 +31,7 @@ define(['jquery'], function ($, history) { window.$ = $; window.jQuery = $; - requirejs(['bootstrap','jquery_scrollto'], function() { + requirejs(['bootstrap','vendor/imagesLoaded','jquery_scrollto', 'freetile'], function() { requirejs(['datetimepicker']); }); requirejs(['icinga/icinga'], function (Icinga) { diff --git a/public/js/vendor/freetile.js b/public/js/vendor/freetile.js new file mode 100644 index 000000000..afab92349 --- /dev/null +++ b/public/js/vendor/freetile.js @@ -0,0 +1,5 @@ +/*! + * Freetile.js v0.3.1 + * A dynamic layout plugin for jQuery. + */ +(function(b){b.fn.freetile=function(c){if(typeof a[c]==="function"){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.Freetile")}}return this};var a={init:function(e){var d=this,f=a.setupOptions(d,e),g=a.newContent(f.contentToAppend);if(!f.tiled){a.setupContainerBindings(d,f)}if(f.tiled&&g){d.append(g);g.filter(f.selector||"*").filter(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}else{d.children(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}return d},append:function(e){var d=this,f=a.setupOptions(d,e),g=a.newContent(f.contentToAppend);if(f.tiled&&g){d.append(g);g.filter(f.loadCheckSelector).imagesLoaded(function(){a.positionAll(d,f)})}return d},layout:function(d){var c=this,e=a.setupOptions(c,d);a.positionAll(c,e);return c},destroy:function(){var c=this,d=c.data("FreetileData");a.resetElementsStyle(c,d);b(window).off("resize",this.windowResizeCallback);c.off(d.customEvents,this.customEventsCallback);return true},setupOptions:function(d,e){var c=d.data("FreetileData");var f=b.extend(true,{},this.defaults,c,this.reset,e);d.data("FreetileData",f);f.tiled=(c!==undefined);f._animate=f.animate&&f.tiled&&b.isEmptyObject(f.contentToAppend);this.reset.callback=f.persistentCallback&&f.callback?f.callback:function(){};return f},windowResizeCallback:function(c,d,e){clearTimeout(c.data("FreetileTimeout"));c.data("FreetileTimeout",setTimeout(function(){var h=b(window),g=h.width(),f=h.height();if(g!=d||f!=e){d=g,e=f;c.freetile("layout")}},400))},customEventsCallback:function(c){clearTimeout(c.data("FreetileTimeout"));c.data("FreetileTimeout",setTimeout(function(){c.freetile("layout")},400))},setupContainerBindings:function(c,f){if(f.containerResize){var e=b(window),d=e.width(),g=e.height();e.resize(b.proxy(this.windowResizeCallback,c,c,d,g))}if(f.customEvents){c.bind(f.customEvents,b.proxy(this.customEventsCallback,c,c))}return c},newContent:function(c){if((typeof c==="object"&&!b.isEmptyObject(c))||(typeof c==="string"&&b(c).length)){return b(c)}return false},calculatePositions:function(c,d,e){d.each(function(o){var p=b(this),n=0;e.ElementWidth=p.outerWidth(true);e.ElementHeight=p.outerHeight(true);e.ElementTop=0;e.ElementIndex=o;e.IndexStart=0;e.IndexEnd=0;e.BestScore=0;e.TestedTop=0;e.TestedLeft=0;e.TestedTop=e.currentPos[0].top;for(n=1;ne.BestScore){e.IndexStart=o;e.IndexEnd=n;e.ElementTop=e.TestedTop;e.BestScore=l}}var h=p.position(),q={left:e.currentPos[e.IndexStart].left+e.xPadding,top:e.ElementTop+e.yPadding};if(h.top!=q.top||h.left!=q.left){var k={el:p,f:"css",d:0};if(e._animate&&!p.hasClass("noanim")){var f=p.offset(),m={left:q.left+(f.left-h.left),top:q.top+(f.top-h.top)};if((f.top+e.ElementHeight>e.viewportY&&f.tope.viewportY&&m.top0){h.width=g.containerWidthStep*(parseInt(c.width()/g.containerWidthStep,10))}c.css(h);var e=b.map(g.currentPos,function(l,k){return l.top});h={height:Math.max.apply(Math,e)};if(g._animate&&g.containerAnimate){c.stop().animate(h,b.extend(true,{},g.animationOptions))}else{c.css(h)}if(g.iteration<=0){g.callback(g)}c.data("FreetilePos",g.currentPos);j.addClass("tiled");return c},resetElementsStyle:function(c,d){var e;if(b.isEmptyObject(d.contentToAppend)){e=d.selector?c.children(d.selector):c.children()}else{e=d.selector?d.contentToAppend.filter(d.selector):d.contentToAppend}e.each(function(){b(this).attr("style","")})},defaults:{selector:"*",animate:false,elementDelay:0,containerResize:true,containerAnimate:false,customEvents:"",persistentCallback:false,forceWidth:false,containerWidthStep:1,loadCheckSelector:":not(.ignore-load-check)",scoreFunction:function(c){return -(c.TestedTop)}},reset:{animationOptions:{complete:function(){}},callback:function(){},contentToAppend:{}}}})(jQuery); diff --git a/public/js/vendor/imagesLoaded.js b/public/js/vendor/imagesLoaded.js new file mode 100644 index 000000000..abf9a7123 --- /dev/null +++ b/public/js/vendor/imagesLoaded.js @@ -0,0 +1,816 @@ +/*! + * imagesLoaded PACKAGED v3.0.4 + * JavaScript is all like "You images are done yet or what?" + * MIT License + */ + +/*! + * EventEmitter v4.2.4 - git.io/ee + * Oliver Caldwell + * MIT license + * @preserve + */ + +(function () { + 'use strict'; + + /** + * Class for managing events. + * Can be extended to provide event functionality in other classes. + * + * @class EventEmitter Manages event registering and emitting. + */ + function EventEmitter() {} + + // Shortcuts to improve speed and size + + // Easy access to the prototype + var proto = EventEmitter.prototype; + + /** + * Finds the index of the listener for the event in it's storage array. + * + * @param {Function[]} listeners Array of listeners to search through. + * @param {Function} listener Method to look for. + * @return {Number} Index of the specified listener, -1 if not found + * @api private + */ + function indexOfListener(listeners, listener) { + var i = listeners.length; + while (i--) { + if (listeners[i].listener === listener) { + return i; + } + } + + return -1; + } + + /** + * Alias a method while keeping the context correct, to allow for overwriting of target method. + * + * @param {String} name The name of the target method. + * @return {Function} The aliased method + * @api private + */ + function alias(name) { + return function aliasClosure() { + return this[name].apply(this, arguments); + }; + } + + /** + * Returns the listener array for the specified event. + * Will initialise the event object and listener arrays if required. + * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them. + * Each property in the object response is an array of listener functions. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Function[]|Object} All listener functions for the event. + */ + proto.getListeners = function getListeners(evt) { + var events = this._getEvents(); + var response; + var key; + + // Return a concatenated array of all matching events if + // the selector is a regular expression. + if (typeof evt === 'object') { + response = {}; + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + response[key] = events[key]; + } + } + } + else { + response = events[evt] || (events[evt] = []); + } + + return response; + }; + + /** + * Takes a list of listener objects and flattens it into a list of listener functions. + * + * @param {Object[]} listeners Raw listener objects. + * @return {Function[]} Just the listener functions. + */ + proto.flattenListeners = function flattenListeners(listeners) { + var flatListeners = []; + var i; + + for (i = 0; i < listeners.length; i += 1) { + flatListeners.push(listeners[i].listener); + } + + return flatListeners; + }; + + /** + * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful. + * + * @param {String|RegExp} evt Name of the event to return the listeners from. + * @return {Object} All listener functions for an event in an object. + */ + proto.getListenersAsObject = function getListenersAsObject(evt) { + var listeners = this.getListeners(evt); + var response; + + if (listeners instanceof Array) { + response = {}; + response[evt] = listeners; + } + + return response || listeners; + }; + + /** + * Adds a listener function to the specified event. + * The listener will not be added if it is a duplicate. + * If the listener returns true then it will be removed after it is called. + * If you pass a regular expression as the event name then the listener will be added to all events that match it. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListener = function addListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var listenerIsWrapped = typeof listener === 'object'; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) { + listeners[key].push(listenerIsWrapped ? listener : { + listener: listener, + once: false + }); + } + } + + return this; + }; + + /** + * Alias of addListener + */ + proto.on = alias('addListener'); + + /** + * Semi-alias of addListener. It will add a listener that will be + * automatically removed after it's first execution. + * + * @param {String|RegExp} evt Name of the event to attach the listener to. + * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addOnceListener = function addOnceListener(evt, listener) { + return this.addListener(evt, { + listener: listener, + once: true + }); + }; + + /** + * Alias of addOnceListener. + */ + proto.once = alias('addOnceListener'); + + /** + * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad. + * You need to tell it what event names should be matched by a regex. + * + * @param {String} evt Name of the event to create. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvent = function defineEvent(evt) { + this.getListeners(evt); + return this; + }; + + /** + * Uses defineEvent to define multiple events. + * + * @param {String[]} evts An array of event names to define. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.defineEvents = function defineEvents(evts) { + for (var i = 0; i < evts.length; i += 1) { + this.defineEvent(evts[i]); + } + return this; + }; + + /** + * Removes a listener function from the specified event. + * When passed a regular expression as the event name, it will remove the listener from all events that match it. + * + * @param {String|RegExp} evt Name of the event to remove the listener from. + * @param {Function} listener Method to remove from the event. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListener = function removeListener(evt, listener) { + var listeners = this.getListenersAsObject(evt); + var index; + var key; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + index = indexOfListener(listeners[key], listener); + + if (index !== -1) { + listeners[key].splice(index, 1); + } + } + } + + return this; + }; + + /** + * Alias of removeListener + */ + proto.off = alias('removeListener'); + + /** + * Adds listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. + * You can also pass it a regular expression to add the array of listeners to all events that match it. + * Yeah, this function does quite a bit. That's probably a bad thing. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.addListeners = function addListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(false, evt, listeners); + }; + + /** + * Removes listeners in bulk using the manipulateListeners method. + * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be removed. + * You can also pass it a regular expression to remove the listeners from all events that match it. + * + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeListeners = function removeListeners(evt, listeners) { + // Pass through to manipulateListeners + return this.manipulateListeners(true, evt, listeners); + }; + + /** + * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level. + * The first argument will determine if the listeners are removed (true) or added (false). + * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. + * You can also pass it an event name and an array of listeners to be added/removed. + * You can also pass it a regular expression to manipulate the listeners of all events that match it. + * + * @param {Boolean} remove True if you want to remove listeners, false if you want to add. + * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once. + * @param {Function[]} [listeners] An optional array of listener functions to add/remove. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) { + var i; + var value; + var single = remove ? this.removeListener : this.addListener; + var multiple = remove ? this.removeListeners : this.addListeners; + + // If evt is an object then pass each of it's properties to this method + if (typeof evt === 'object' && !(evt instanceof RegExp)) { + for (i in evt) { + if (evt.hasOwnProperty(i) && (value = evt[i])) { + // Pass the single listener straight through to the singular method + if (typeof value === 'function') { + single.call(this, i, value); + } + else { + // Otherwise pass back to the multiple function + multiple.call(this, i, value); + } + } + } + } + else { + // So evt must be a string + // And listeners must be an array of listeners + // Loop over it and pass each one to the multiple method + i = listeners.length; + while (i--) { + single.call(this, evt, listeners[i]); + } + } + + return this; + }; + + /** + * Removes all listeners from a specified event. + * If you do not specify an event then all listeners will be removed. + * That means every event will be emptied. + * You can also pass a regex to remove all events that match it. + * + * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.removeEvent = function removeEvent(evt) { + var type = typeof evt; + var events = this._getEvents(); + var key; + + // Remove different things depending on the state of evt + if (type === 'string') { + // Remove all listeners for the specified event + delete events[evt]; + } + else if (type === 'object') { + // Remove all events matching the regex. + for (key in events) { + if (events.hasOwnProperty(key) && evt.test(key)) { + delete events[key]; + } + } + } + else { + // Remove all listeners in all events + delete this._events; + } + + return this; + }; + + /** + * Alias of removeEvent. + * + * Added to mirror the node API. + */ + proto.removeAllListeners = alias('removeEvent'); + + /** + * Emits an event of your choice. + * When emitted, every listener attached to that event will be executed. + * If you pass the optional argument array then those arguments will be passed to every listener upon execution. + * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately. + * So they will not arrive within the array on the other side, they will be separate. + * You can also pass a regular expression to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {Array} [args] Optional array of arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emitEvent = function emitEvent(evt, args) { + var listeners = this.getListenersAsObject(evt); + var listener; + var i; + var key; + var response; + + for (key in listeners) { + if (listeners.hasOwnProperty(key)) { + i = listeners[key].length; + + while (i--) { + // If the listener returns true then it shall be removed from the event + // The function is executed either with a basic call or an apply if there is an args array + listener = listeners[key][i]; + + if (listener.once === true) { + this.removeListener(evt, listener.listener); + } + + response = listener.listener.apply(this, args || []); + + if (response === this._getOnceReturnValue()) { + this.removeListener(evt, listener.listener); + } + } + } + } + + return this; + }; + + /** + * Alias of emitEvent + */ + proto.trigger = alias('emitEvent'); + + /** + * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on. + * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it. + * + * @param {String|RegExp} evt Name of the event to emit and execute listeners for. + * @param {...*} Optional additional arguments to be passed to each listener. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.emit = function emit(evt) { + var args = Array.prototype.slice.call(arguments, 1); + return this.emitEvent(evt, args); + }; + + /** + * Sets the current value to check against when executing listeners. If a + * listeners return value matches the one set here then it will be removed + * after execution. This value defaults to true. + * + * @param {*} value The new value to check for when executing listeners. + * @return {Object} Current instance of EventEmitter for chaining. + */ + proto.setOnceReturnValue = function setOnceReturnValue(value) { + this._onceReturnValue = value; + return this; + }; + + /** + * Fetches the current value to check against when executing listeners. If + * the listeners return value matches this one then it should be removed + * automatically. It will return true by default. + * + * @return {*|Boolean} The current value to check for or the default, true. + * @api private + */ + proto._getOnceReturnValue = function _getOnceReturnValue() { + if (this.hasOwnProperty('_onceReturnValue')) { + return this._onceReturnValue; + } + else { + return true; + } + }; + + /** + * Fetches the events object and creates one if required. + * + * @return {Object} The events storage object. + * @api private + */ + proto._getEvents = function _getEvents() { + return this._events || (this._events = {}); + }; + + // Expose the class either via AMD, CommonJS or the global object + + this.EventEmitter = EventEmitter; + +}.call(this)); + +/*! + * eventie v1.0.3 + * event binding helper + * eventie.bind( elem, 'click', myFn ) + * eventie.unbind( elem, 'click', myFn ) + */ + +/*jshint browser: true, undef: true, unused: true */ +/*global define: false */ + +( function( window ) { + + 'use strict'; + + var docElem = document.documentElement; + + var bind = function() {}; + + if ( docElem.addEventListener ) { + bind = function( obj, type, fn ) { + obj.addEventListener( type, fn, false ); + }; + } else if ( docElem.attachEvent ) { + bind = function( obj, type, fn ) { + obj[ type + fn ] = fn.handleEvent ? + function() { + var event = window.event; + // add event.target + event.target = event.target || event.srcElement; + fn.handleEvent.call( fn, event ); + } : + function() { + var event = window.event; + // add event.target + event.target = event.target || event.srcElement; + fn.call( obj, event ); + }; + obj.attachEvent( "on" + type, obj[ type + fn ] ); + }; + } + + var unbind = function() {}; + + if ( docElem.removeEventListener ) { + unbind = function( obj, type, fn ) { + obj.removeEventListener( type, fn, false ); + }; + } else if ( docElem.detachEvent ) { + unbind = function( obj, type, fn ) { + obj.detachEvent( "on" + type, obj[ type + fn ] ); + try { + delete obj[ type + fn ]; + } catch ( err ) { + // can't delete window object properties + obj[ type + fn ] = undefined; + } + }; + } + + var eventie = { + bind: bind, + unbind: unbind + }; + +// transport + + // browser global + window.eventie = eventie; + +})( this ); + +/*! + * imagesLoaded v3.0.4 + * JavaScript is all like "You images are done yet or what?" + * MIT License + */ + +( function( window ) { + + 'use strict'; + + var $ = window.jQuery; + var console = window.console; + var hasConsole = typeof console !== 'undefined'; + +// -------------------------- helpers -------------------------- // + +// extend objects + function extend( a, b ) { + for ( var prop in b ) { + a[ prop ] = b[ prop ]; + } + return a; + } + + var objToString = Object.prototype.toString; + function isArray( obj ) { + return objToString.call( obj ) === '[object Array]'; + } + +// turn element or nodeList into an array + function makeArray( obj ) { + var ary = []; + if ( isArray( obj ) ) { + // use object if already an array + ary = obj; + } else if ( typeof obj.length === 'number' ) { + // convert nodeList to array + for ( var i=0, len = obj.length; i < len; i++ ) { + ary.push( obj[i] ); + } + } else { + // array of single index + ary.push( obj ); + } + return ary; + } + +// -------------------------- -------------------------- // + + function defineImagesLoaded( EventEmitter, eventie ) { + + /** + * @param {Array, Element, NodeList, String} elem + * @param {Object or Function} options - if function, use as callback + * @param {Function} onAlways - callback function + */ + function ImagesLoaded( elem, options, onAlways ) { + // coerce ImagesLoaded() without new, to be new ImagesLoaded() + if ( !( this instanceof ImagesLoaded ) ) { + return new ImagesLoaded( elem, options ); + } + // use elem as selector string + if ( typeof elem === 'string' ) { + elem = document.querySelectorAll( elem ); + } + + this.elements = makeArray( elem ); + this.options = extend( {}, this.options ); + + if ( typeof options === 'function' ) { + onAlways = options; + } else { + extend( this.options, options ); + } + + if ( onAlways ) { + this.on( 'always', onAlways ); + } + + this.getImages(); + + if ( $ ) { + // add jQuery Deferred object + this.jqDeferred = new $.Deferred(); + } + + // HACK check async to allow time to bind listeners + var _this = this; + setTimeout( function() { + _this.check(); + }); + } + + ImagesLoaded.prototype = new EventEmitter(); + + ImagesLoaded.prototype.options = {}; + + ImagesLoaded.prototype.getImages = function() { + this.images = []; + + // filter & find items if we have an item selector + for ( var i=0, len = this.elements.length; i < len; i++ ) { + var elem = this.elements[i]; + // filter siblings + if ( elem.nodeName === 'IMG' ) { + this.addImage( elem ); + } + // find children + var childElems = elem.querySelectorAll('img'); + // concat childElems to filterFound array + for ( var j=0, jLen = childElems.length; j < jLen; j++ ) { + var img = childElems[j]; + this.addImage( img ); + } + } + }; + + /** + * @param {Image} img + */ + ImagesLoaded.prototype.addImage = function( img ) { + var loadingImage = new LoadingImage( img ); + this.images.push( loadingImage ); + }; + + ImagesLoaded.prototype.check = function() { + var _this = this; + var checkedCount = 0; + var length = this.images.length; + this.hasAnyBroken = false; + // complete if no images + if ( !length ) { + this.complete(); + return; + } + + function onConfirm( image, message ) { + if ( _this.options.debug && hasConsole ) { + console.log( 'confirm', image, message ); + } + + _this.progress( image ); + checkedCount++; + if ( checkedCount === length ) { + _this.complete(); + } + return true; // bind once + } + + for ( var i=0; i < length; i++ ) { + var loadingImage = this.images[i]; + loadingImage.on( 'confirm', onConfirm ); + loadingImage.check(); + } + }; + + ImagesLoaded.prototype.progress = function( image ) { + this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded; + // HACK - Chrome triggers event before object properties have changed. #83 + var _this = this; + setTimeout( function() { + _this.emit( 'progress', _this, image ); + if ( _this.jqDeferred ) { + _this.jqDeferred.notify( _this, image ); + } + }); + }; + + ImagesLoaded.prototype.complete = function() { + var eventName = this.hasAnyBroken ? 'fail' : 'done'; + this.isComplete = true; + var _this = this; + // HACK - another setTimeout so that confirm happens after progress + setTimeout( function() { + _this.emit( eventName, _this ); + _this.emit( 'always', _this ); + if ( _this.jqDeferred ) { + var jqMethod = _this.hasAnyBroken ? 'reject' : 'resolve'; + _this.jqDeferred[ jqMethod ]( _this ); + } + }); + }; + + // -------------------------- jquery -------------------------- // + + if ( $ ) { + $.fn.imagesLoaded = function( options, callback ) { + var instance = new ImagesLoaded( this, options, callback ); + return instance.jqDeferred.promise( $(this) ); + }; + } + + + // -------------------------- -------------------------- // + + var cache = {}; + + function LoadingImage( img ) { + this.img = img; + } + + LoadingImage.prototype = new EventEmitter(); + + LoadingImage.prototype.check = function() { + // first check cached any previous images that have same src + var cached = cache[ this.img.src ]; + if ( cached ) { + this.useCached( cached ); + return; + } + // add this to cache + cache[ this.img.src ] = this; + + // If complete is true and browser supports natural sizes, + // try to check for image status manually. + if ( this.img.complete && this.img.naturalWidth !== undefined ) { + // report based on naturalWidth + this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' ); + return; + } + + // If none of the checks above matched, simulate loading on detached element. + var proxyImage = this.proxyImage = new Image(); + eventie.bind( proxyImage, 'load', this ); + eventie.bind( proxyImage, 'error', this ); + proxyImage.src = this.img.src; + }; + + LoadingImage.prototype.useCached = function( cached ) { + if ( cached.isConfirmed ) { + this.confirm( cached.isLoaded, 'cached was confirmed' ); + } else { + var _this = this; + cached.on( 'confirm', function( image ) { + _this.confirm( image.isLoaded, 'cache emitted confirmed' ); + return true; // bind once + }); + } + }; + + LoadingImage.prototype.confirm = function( isLoaded, message ) { + this.isConfirmed = true; + this.isLoaded = isLoaded; + this.emit( 'confirm', this, message ); + }; + + // trigger specified handler for event type + LoadingImage.prototype.handleEvent = function( event ) { + var method = 'on' + event.type; + if ( this[ method ] ) { + this[ method ]( event ); + } + }; + + LoadingImage.prototype.onload = function() { + this.confirm( true, 'onload' ); + this.unbindProxyEvents(); + }; + + LoadingImage.prototype.onerror = function() { + this.confirm( false, 'onerror' ); + this.unbindProxyEvents(); + }; + + LoadingImage.prototype.unbindProxyEvents = function() { + eventie.unbind( this.proxyImage, 'load', this ); + eventie.unbind( this.proxyImage, 'error', this ); + }; + + // ----- ----- // + + return ImagesLoaded; + } + +// -------------------------- transport -------------------------- // + + + // browser global + window.imagesLoaded = defineImagesLoaded( + window.EventEmitter, + window.eventie + ); + +})( window ); \ No newline at end of file