/** * ioBroker.vis * https://github.com/ioBroker/ioBroker.vis * * Copyright (c) 2013-2018 bluefox https://github.com/GermanBluefox, hobbyquaker https://github.com/hobbyquaker * Creative Common Attribution-NonCommercial (CC BY-NC) * * http://creativecommons.org/licenses/by-nc/4.0/ * * Short content: * Licensees may copy, distribute, display and perform the work and make derivative works based on it only if they give the author or licensor the credits in the manner specified by these. * Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes. * (Free for non-commercial use). */ // visEdit - the ioBroker.vis Editor extensions /* jshint browser:true */ /* global _ */ /* global $ */ /* global jQuery */ /* global console */ /* global systemDictionary */ /* global vis:true */ /* jshint -W097 */// jshint strict:false 'use strict'; // Add words for bars $.extend(systemDictionary, { "Select" : {"en" : "Select", "de": "Auswählen", "ru": "Выбрать"}, "Cancel" : {"en" : "Cancel", "de": "Abbrechen", "ru": "Отмена"}, "None" : {"en": "None", "de": "Vorgegeben", "ru": "---"}, "Default" : {"en": "Default", "de": "Vorgegeben", "ru": "По умолчанию"}, "Name" : {"en" : "Name", "de": "Name", "ru": "Имя"}, "Location" : {"en" : "Location", "de": "Raum", "ru": "Комната"}, "Interface" : {"en" : "Interface", "de": "Schnittstelle", "ru": "Интерфейс"}, "Type" : {"en" : "Type", "de": "Typ", "ru": "Тип"}, "Address" : {"en" : "Address", "de": "Adresse", "ru": "Адрес"}, "Function" : {"en" : "Function", "de": "Gewerk", "ru": "Функционал"}, "Disable device filter:" : { "en": "Disable device filter:", "de": "Schalte Gerätefilter aus:", "ru": "Убрать фильтр по устройствам:" }, "Rooms" : {"en" : "Rooms", "de": "Räume", "ru": "Комнаты"}, "Functions" : {"en" : "Functions", "de": "Gewerke", "ru": "Функции"}, "Selected image: " : {"en" : "Selected file: ","de": "Ausgewählte Datei: ","ru": "Выбраный файл: "}, "Programs" : {"en" : "Programs", "de": "Programme", "ru": "Программы"}, "Variables" : {"en" : "Variables", "de": "Variablen", "ru": "Переменные"}, "Devices" : {"en" : "Devices", "de": "Geräte", "ru": "Устройства"} }); vis.styleSelect = { // local variables _internalList: null, // Functions collectClasses: function () { var result = []; var sSheetList = document.styleSheets; for (var sSheet = 0; sSheet < sSheetList.length; sSheet++) { if (!document.styleSheets[sSheet]) continue; try { var ruleList = document.styleSheets[sSheet].cssRules; if (ruleList) { for (var rule = 0; rule < ruleList.length; rule ++) { if (!ruleList[rule].selectorText) continue; var _styles = ruleList[rule].selectorText.split(','); for (var s = 0; s < _styles.length; s++) { var substyles = _styles[s].trim().split(' '); var _style = substyles[substyles.length - 1].replace('::before', '').replace('::after', '').replace(':before', '').replace(':after', ''); if (!_style || _style[0] !== '.' || _style.indexOf(':') !== -1) continue; var name = _style; name = name.replace(',', ''); name = name.replace(/^\./, ''); var val = name; name = name.replace(/^hq-background-/, ''); name = name.replace(/^hq-/, ''); name = name.replace(/^ui-/, ''); name = name.replace(/[-_]/g, ' '); if (name.length > 0) { name = name[0].toUpperCase() + name.substring(1); var fff = document.styleSheets[sSheet].href; if (fff && fff.indexOf('/') !== -1) { fff = fff.substring(fff.lastIndexOf('/') + 1); } if (!result[val]) { if (substyles.length > 1) { result[val] = {name: name, file: fff, attrs: ruleList[rule].style, parentClass: substyles[0].replace('.', '')}; } else { result[val] = {name: name, file: fff, attrs: ruleList[rule].style}; } } } } } } } catch (e) { console.error(e); } } return result; }, show: function (options) { // Fill the list of styles if (!this._internalList) this._internalList = vis.styleSelect.collectClasses(); options.filterName = options.filterName || ''; options.filterAttrs = options.filterAttrs || ''; options.filterFile = options.filterFile || ''; var styles = {}; if (options.styles) { styles = $.extend(styles, options.styles); } else { // IF filter defined if (options.filterFile || options.filterName) { var filters = (options.filterName) ? options.filterName.split(' ') : null; var attrs = (options.filterAttrs) ? options.filterAttrs.split(' ') : null; var files = (options.filterFile) ? options.filterFile.split(' ') : ['']; for (var style in this._internalList) { if (!this._internalList.hasOwnProperty(style)) continue; for (var f = 0; f < files.length; f++) { if (!options.filterFile || (this._internalList[style].file && this._internalList[style].file.indexOf(files[f]) !== -1)) { var isFound = !filters; if (!isFound) { for (var k = 0; k < filters.length; k++) { if (style.indexOf(filters[k]) !== -1) { isFound = true; break; } } } if (isFound) { isFound = !attrs; if (!isFound) { for (var u = 0; u < attrs.length; u++) { var t = this._internalList[style].attrs[attrs[u]]; if (t || t === 0) { isFound = true; break; } } } } if (isFound) { var n = this._internalList[style].name; if (options.removeName) { n = n.replace(options.removeName, ''); n = n[0].toUpperCase() + n.substring(1).toLowerCase(); } styles[style] = { name: n, file: this._internalList[style].file, parentClass: this._internalList[style].parentClass }; } } } } } else { styles = $.extend(styles, this._internalList); } } var text = ''; //noinspection JSJQueryEfficiency if (!$('#' + options.name + '_styles').length) { text = ''; } if (!$.fn.iconselectmenu) { $.widget('custom.iconselectmenu', $.ui.selectmenu, { _renderItem: function (ul, item) { var li = $('