ko.bindingHandlers.truncatedText = { update: function(element, valueAccessor, allBindingsAccessor) { var value = ko.utils.unwrapObservable(valueAccessor()), length = ko.utils.unwrapObservable(allBindingsAccessor().length) || ko.bindingHandlers.truncatedText.defaultLength, truncatedValue = value.length > length ? value.substring(0, Math.min(value.length, length)) + "…" : 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()) var maxLength = 60; if(value.length > maxLength) { var charsToShow = maxLength - 3, frontChars = Math.ceil(charsToShow/2), backChars = Math.floor(charsToShow/2); var truncatedValue = value.substr(0, frontChars) + '…' + value.substr(value.length - backChars); } else { var truncatedValue = 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()) var outputText = ''; // Any
's? if(value.length > 4) { // Inital 3, then the button, then the closing outputText += value.pop() + '
' + value.pop() + '
' + value.pop() + ' '; outputText += '(' + glitterTranslate.moreText + ')
'; outputText += ''; outputText += value.join('
'); outputText += '
'; } else { // Nothing special outputText += value.join('
'); } ko.bindingHandlers.html.update(element, function() { return outputText; }); } }; 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") $.each(e.originalEvent.dataTransfer.files, function(index) { // Add notification showNotification('.main-notification-box-uploading', 0, index+1) options.onFileDrop(this); }); }); } }; $(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 0.11.0 | (c) 2015 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/sortable", "jquery-ui/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/sortable"); require("jquery-ui/draggable"); factory(ko, jQuery); } else { // No module loader (plain