{"size": 3276, "ext": "js", "max_stars_repo_path": "admin/components/sw-navigation.js", "max_stars_repo_name": "BrfSkagagard/beta", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "admin/components/sw-navigation.js", "max_issues_repo_name": "BrfSkagagard/beta", "max_issues_repo_issues_event_min_datetime": "2017-02-08T09:48:40.000Z", "max_issues_repo_issues_event_max_datetime": "2017-02-08T09:48:40.000Z", "max_forks_repo_path": "admin/components/sw-navigation.js", "max_forks_repo_name": "BrfSkagagard/beta", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 39.0, "max_line_length": 134, "alphanum_fraction": 0.5061050061}
/* global tinymce */
(function (staticWeb) {
    "use strict";
    var Navigation = function (element) {
        if (!(this instanceof Navigation)) {
            return new Navigation(element);
        }

        return this.init(element);
    }
    Navigation.prototype = {
        createInterface: function () {
            var self = this;

            self._element.addEventListener('drop', function (event) {
                event.preventDefault();

                var name = false;
                var url = false;
                var obj = event.dataTransfer.getData("text");
                try {
                    var navNode = JSON.parse(obj);
                    if (navNode) {
                        name = navNode.name;
                        url = navNode.path;
                        staticWeb.storage.get(navNode.path + 'metadata.json', function (file, callStatus) {
                            if (callStatus.isOK) {
                                var metadata = JSON.parse(file.data);
                                name = staticWeb.decodeToText(metadata.name);
                            }
                            self.addNavigationItemDialog(url, name);
                        });
                        return;
                    }
                } catch (ex) { }

                //name = event.dataTransfer.getData("text");
                url = event.dataTransfer.getData("text/uri-list");

                self.addNavigationItemDialog(url, 'unknown name');
            });

            self._element.addEventListener('dragover', function (event) {
                event.preventDefault();
                // Set the dropEffect to move
                event.dataTransfer.dropEffect = "copy";
            });

            self._element.addEventListener('click', function (event) {
                // prevent link actions
                event.preventDefault();

                var attributes = {
                    'data-staticweb-component-navigation-id': self._element.id,
                    'data-staticweb-component-navigation-type': self._element.getAttribute('data-staticweb-component-navigation-type')
                };
                var body = document.querySelector('body');
                staticWeb.initComponent(body, 'sw-navigation-dialog', attributes);
                return false;
            });
        },
        addNavigationItemDialog: function (url, name) {
            var self = this;

            var attributes = {
                'data-staticweb-component-navigation-id': self._element.id,
                'data-staticweb-component-navigation-type': self._element.getAttribute('data-staticweb-component-navigation-type'),
                'data-staticweb-component-navigation-path': url,
                'data-staticweb-component-navigation-name': name
            };
            var body = document.querySelector('body');
            staticWeb.initComponent(body, 'sw-navigation-dialog', attributes);
        },
        init: function (element) {
            var self = this;
            self._element = element;
            if (staticWeb.storage) {
                self.createInterface();
            }
        }
    }
    staticWeb.registerComponent('sw-navigation', Navigation);

})(window.StaticWeb);