/** * Kendo UI v2016.1.112 (http://www.telerik.com/kendo-ui) * Copyright 2016 Telerik AD. All rights reserved. * * Kendo UI commercial licenses may be obtained at * http://www.telerik.com/purchase/license-agreement/kendo-ui-complete * If you do not own a commercial license, this file shall be governed by the trial license terms. */ (function (f, define) { define('kendo.imagebrowser', ['kendo.filebrowser'], f); }(function () { var __meta__ = { id: 'imagebrowser', name: 'ImageBrowser', category: 'web', description: '', hidden: true, depends: ['filebrowser'] }; (function ($, undefined) { var kendo = window.kendo, FileBrowser = kendo.ui.FileBrowser, isPlainObject = $.isPlainObject, proxy = $.proxy, extend = $.extend, browser = kendo.support.browser, isFunction = kendo.isFunction, trimSlashesRegExp = /(^\/|\/$)/g, ERROR = 'error', NS = '.kendoImageBrowser', NAMEFIELD = 'name', SIZEFIELD = 'size', TYPEFIELD = 'type', DEFAULTSORTORDER = { field: TYPEFIELD, dir: 'asc' }, EMPTYTILE = kendo.template('
  • ${text}
  • '); extend(true, kendo.data, { schemas: { 'imagebrowser': { data: function (data) { return data.items || data || []; }, model: { id: 'name', fields: { name: 'name', size: 'size', type: 'type' } } } } }); extend(true, kendo.data, { transports: { 'imagebrowser': kendo.data.RemoteTransport.extend({ init: function (options) { kendo.data.RemoteTransport.fn.init.call(this, $.extend(true, {}, this.options, options)); }, _call: function (type, options) { options.data = $.extend({}, options.data, { path: this.options.path() }); if (isFunction(this.options[type])) { this.options[type].call(this, options); } else { kendo.data.RemoteTransport.fn[type].call(this, options); } }, read: function (options) { this._call('read', options); }, create: function (options) { this._call('create', options); }, destroy: function (options) { this._call('destroy', options); }, update: function () { }, options: { read: { type: 'POST' }, update: { type: 'POST' }, create: { type: 'POST' }, destroy: { type: 'POST' } } }) } }); var offsetTop; if (browser.msie && browser.version < 8) { offsetTop = function (element) { return element.offsetTop; }; } else { offsetTop = function (element) { return element.offsetTop - $(element).height(); }; } function concatPaths(path, name) { if (path === undefined || !path.match(/\/$/)) { path = (path || '') + '/'; } return path + name; } function sizeFormatter(value) { if (!value) { return ''; } var suffix = ' bytes'; if (value >= 1073741824) { suffix = ' GB'; value /= 1073741824; } else if (value >= 1048576) { suffix = ' MB'; value /= 1048576; } else if (value >= 1024) { suffix = ' KB'; value /= 1024; } return Math.round(value * 100) / 100 + suffix; } var ImageBrowser = FileBrowser.extend({ init: function (element, options) { var that = this; options = options || {}; FileBrowser.fn.init.call(that, element, options); that.element.addClass('k-imagebrowser'); }, options: { name: 'ImageBrowser', fileTypes: '*.png,*.gif,*.jpg,*.jpeg' }, value: function () { var that = this, selected = that._selectedItem(), path, imageUrl = that.options.transport.imageUrl; if (selected && selected.get(TYPEFIELD) === 'f') { path = concatPaths(that.path(), selected.get(NAMEFIELD)).replace(trimSlashesRegExp, ''); if (imageUrl) { path = isFunction(imageUrl) ? imageUrl(path) : kendo.format(imageUrl, encodeURIComponent(path)); } return path; } }, _fileUpload: function (e) { var that = this, options = that.options, fileTypes = options.fileTypes, filterRegExp = new RegExp(('(' + fileTypes.split(',').join(')|(') + ')').replace(/\*\./g, '.*.'), 'i'), fileName = e.files[0].name, fileNameField = NAMEFIELD, sizeField = SIZEFIELD, model; if (filterRegExp.test(fileName)) { e.data = { path: that.path() }; model = that._createFile(fileName); if (!model) { e.preventDefault(); } else { model._uploading = true; that.upload.one('success', function (e) { delete model._uploading; model.set(fileNameField, e.response[that._getFieldName(fileNameField)]); model.set(sizeField, e.response[that._getFieldName(sizeField)]); that._tiles = that.listView.items().filter('[' + kendo.attr('type') + '=f]'); that._scroll(); }); } } else { e.preventDefault(); that._showMessage(kendo.format(options.messages.invalidFileType, fileName, fileTypes)); } }, _content: function () { var that = this; that.list = $('