ko.bindingHandlers.truncatedText = { update: function(element, valueAccessor, allBindingsAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()); if (!value) return var length = ko.utils.unwrapObservable(allBindingsAccessor().length) || ko.bindingHandlers.truncatedText.defaultLength, truncatedValue = value.length > length ? convertHTMLtoText(value.substring(0, Math.min(value.length, length))) + "…" : convertHTMLtoText(value); ko.bindingHandlers.html.update(element, function() { return truncatedValue; }); }, defaultLength: 15 }; ko.bindingHandlers.truncatedTextCenter = { update: function(element, valueAccessor, allBindingsAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()) if (!value) return var maxLength = 60; if(value.length > maxLength) { var charsToShow = maxLength - 3, frontChars = Math.ceil(charsToShow/2), backChars = Math.floor(charsToShow/2); var truncatedValue = convertHTMLtoText(value.substr(0, frontChars)) + '…' + convertHTMLtoText(value.substr(value.length - backChars)); } else { var truncatedValue = convertHTMLtoText(value); } ko.bindingHandlers.html.update(element, function() { return truncatedValue; }); } }; ko.bindingHandlers.longText = { update: function(element, valueAccessor, allBindingsAccessor) { // Input is an array var value = ko.utils.unwrapObservable(valueAccessor()) // Convert HTML entities for all but the Script (because of the (more)-link) if(allBindingsAccessor.get('longTextType') != "Script") { value = value.map(convertHTMLtoText) } // Any
's? var outputText = ''; if(value.length > 4) { // Inital 3, then the button, then the closing outputText += value.shift() + '
' + value.shift() + '
' + value.shift() + ' '; outputText += '(' + glitterTranslate.moreText + ')
'; outputText += ''; outputText += value.join('
'); outputText += '
'; } else { // Nothing special outputText += value.join('
'); } // Replace link to our website outputText = outputText.replace('https://sabnzbd.org/not-complete', 'https://sabnzbd.org/not-complete') ko.bindingHandlers.html.update(element, function() { return outputText; }); } }; // Adapted for SABnzbd usage ko.bindingHandlers.filedrop = { init: function(element, valueAccessor) { var options = $.extend({}, { overlaySelector: null }, valueAccessor()); if(!options.onFileDrop) return; else if(!window.File || !window.FileReader || !window.FileList || !window.FormData) { console.log("File drop disabled because this browser is too old"); return; } // EDITED to prevent drag-and-drop from inside own screen $(element).bind("dragstart", function(e) { $(element).data('internal-drag', true) // Remove after timeout setTimeout(function() { $(element).data('internal-drag', false) }, 2000) }); $(element).bind("dragenter", function(e) { e.stopPropagation(); e.preventDefault(); // Was it external or internal? if($(element).data('internal-drag')) return; if(options.overlaySelector) $(options.overlaySelector).show(); }); $(element).bind("dragleave", function(e) { e.stopPropagation(); e.preventDefault(); // EDITED FOR FIREFOX! // Without the check for is(), the screen will blink in firefox! if(options.overlaySelector && $(e.target).is('.main-filedrop')) $(options.overlaySelector).hide(); }); $(element).bind("drop", function(e) { e.stopPropagation(); e.preventDefault(); if(options.overlaySelector) $(options.overlaySelector).hide(); if(typeof options.onFileDrop === "function") { options.onFileDrop(e.originalEvent.dataTransfer.files) } }); } }; $(document).bind('dragover', function(e) { e.preventDefault(); }); /*! Knockout Persist - v0.1.0 - 2015-12-28 * https://github.com/spoike/knockout.persist * Copyright (c) 2013 Mikael Brassman; Licensed MIT * Safihre edited to better detect if localStorage is possible */ (function(ko) { // Don't crash on browsers that are missing localStorage try { localStorage.setItem('test', 'test'); localStorage.removeItem('test'); } catch(e) { return false; } ko.extenders.persist = function(target, key) { var initialValue = target(); // Load existing value from localStorage if set if (key && localStorage.getItem(key) !== null) { try { initialValue = JSON.parse(localStorage.getItem(key)); } catch (e) { } } target(initialValue); // Subscribe to new values and add them to localStorage target.subscribe(function (newValue) { localStorage.setItem(key, ko.toJSON(newValue)); }); return target; }; })(ko); // knockout-sortable 1.2.0 | (c) 2019 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license ;(function(factory) { if (typeof define === "function" && define.amd) { // AMD anonymous module define(["knockout", "jquery", "jquery-ui/ui/widgets/sortable", "jquery-ui/ui/widgets/draggable"], factory); } else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { // CommonJS module var ko = require("knockout"), jQuery = require("jquery"); require("jquery-ui/ui/widgets/sortable"); require("jquery-ui/ui/widgets/draggable"); factory(ko, jQuery); } else { // No module loader (plain