From b27c240a7e6427d1d6cd6c05b79fe9c7ac18f250 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Fri, 1 Aug 2014 10:12:28 +0300 Subject: [PATCH] Fix sortable. Previously it was changed to POST all items with automatic positions from 0 to 49. I have reverted to use GET with from & to by default. You could use data-post-all to use the POST behavior. Also the changes to the unminified JS were not committed. The unminified JS is now committed, converted to tabs and minified with UglifyJS. --- web/js/bootstrap-extensions.js | 1105 +++++++++-------- web/js/bootstrap-extensions.min.js | 2 +- .../bootstrap-jquery-ui-sortable.js | 41 +- 3 files changed, 591 insertions(+), 557 deletions(-) diff --git a/web/js/bootstrap-extensions.js b/web/js/bootstrap-extensions.js index 5a687ca..892ec98 100644 --- a/web/js/bootstrap-extensions.js +++ b/web/js/bootstrap-extensions.js @@ -136,114 +136,114 @@ * ================================= */ var Fileupload = function (element, options) { - this.$element = $(element) - this.type = this.$element.data('uploadtype') || (this.$element.find('.thumbnail').length > 0 ? "image" : "file") - - this.$input = this.$element.find(':file') - if (this.$input.length === 0) return - - this.name = this.$input.attr('name') || options.name - - this.$hidden = this.$element.find('input[type=hidden][name="'+this.name+'"]') - if (this.$hidden.length === 0) { - this.$hidden = $('') - this.$element.prepend(this.$hidden) - } - - this.$preview = this.$element.find('.fileupload-preview') - var height = this.$preview.css('height') - if (this.$preview.css('display') != 'inline' && height != '0px' && height != 'none') this.$preview.css('line-height', height) - - this.original = { - 'exists': this.$element.hasClass('fileupload-exists'), - 'preview': this.$preview.html(), - 'hiddenVal': this.$hidden.val() - } - - this.$remove = this.$element.find('[data-dismiss="fileupload"]') - - this.$element.find('[data-trigger="fileupload"]').on('click.fileupload', $.proxy(this.trigger, this)) - - this.listen() + this.$element = $(element) + this.type = this.$element.data('uploadtype') || (this.$element.find('.thumbnail').length > 0 ? "image" : "file") + + this.$input = this.$element.find(':file') + if (this.$input.length === 0) return + + this.name = this.$input.attr('name') || options.name + + this.$hidden = this.$element.find('input[type=hidden][name="'+this.name+'"]') + if (this.$hidden.length === 0) { + this.$hidden = $('') + this.$element.prepend(this.$hidden) + } + + this.$preview = this.$element.find('.fileupload-preview') + var height = this.$preview.css('height') + if (this.$preview.css('display') != 'inline' && height != '0px' && height != 'none') this.$preview.css('line-height', height) + + this.original = { + 'exists': this.$element.hasClass('fileupload-exists'), + 'preview': this.$preview.html(), + 'hiddenVal': this.$hidden.val() + } + + this.$remove = this.$element.find('[data-dismiss="fileupload"]') + + this.$element.find('[data-trigger="fileupload"]').on('click.fileupload', $.proxy(this.trigger, this)) + + this.listen() } Fileupload.prototype = { - - listen: function() { - this.$input.on('change.fileupload', $.proxy(this.change, this)) - $(this.$input[0].form).on('reset.fileupload', $.proxy(this.reset, this)) - if (this.$remove) this.$remove.on('click.fileupload', $.proxy(this.clear, this)) - }, - - change: function(e, invoked) { - if (invoked === 'clear') return - - var file = e.target.files !== undefined ? e.target.files[0] : (e.target.value ? { name: e.target.value.replace(/^.+\\/, '') } : null) - - if (!file) { - this.clear() - return - } - - this.$hidden.val('') - this.$hidden.attr('name', '') - this.$input.attr('name', this.name) - - if (this.type === "image" && this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") { - var reader = new FileReader() - var preview = this.$preview - var element = this.$element - - reader.onload = function(e) { - preview.html('') - element.addClass('fileupload-exists').removeClass('fileupload-new') - } - - reader.readAsDataURL(file) - } else { - this.$preview.text(file.name) - this.$element.addClass('fileupload-exists').removeClass('fileupload-new') - } - }, - - clear: function(e) { - this.$hidden.val('') - this.$hidden.attr('name', this.name) - this.$input.attr('name', '') - - //ie8+ doesn't support changing the value of input with type=file so clone instead - if (navigator.userAgent.match(/msie/i)){ - var inputClone = this.$input.clone(true); - this.$input.after(inputClone); - this.$input.remove(); - this.$input = inputClone; - }else{ - this.$input.val('') - } - - this.$preview.html('') - this.$element.addClass('fileupload-new').removeClass('fileupload-exists') - - if (e) { - this.$input.trigger('change', [ 'clear' ]) - e.preventDefault() - } - }, - - reset: function(e) { - this.clear() - - this.$hidden.val(this.original.hiddenVal) - this.$preview.html(this.original.preview) - - if (this.original.exists) this.$element.addClass('fileupload-exists').removeClass('fileupload-new') - else this.$element.addClass('fileupload-new').removeClass('fileupload-exists') - }, - - trigger: function(e) { - this.$input.trigger('click') - e.preventDefault() - } + + listen: function() { + this.$input.on('change.fileupload', $.proxy(this.change, this)) + $(this.$input[0].form).on('reset.fileupload', $.proxy(this.reset, this)) + if (this.$remove) this.$remove.on('click.fileupload', $.proxy(this.clear, this)) + }, + + change: function(e, invoked) { + if (invoked === 'clear') return + + var file = e.target.files !== undefined ? e.target.files[0] : (e.target.value ? { name: e.target.value.replace(/^.+\\/, '') } : null) + + if (!file) { + this.clear() + return + } + + this.$hidden.val('') + this.$hidden.attr('name', '') + this.$input.attr('name', this.name) + + if (this.type === "image" && this.$preview.length > 0 && (typeof file.type !== "undefined" ? file.type.match('image.*') : file.name.match(/\.(gif|png|jpe?g)$/i)) && typeof FileReader !== "undefined") { + var reader = new FileReader() + var preview = this.$preview + var element = this.$element + + reader.onload = function(e) { + preview.html('') + element.addClass('fileupload-exists').removeClass('fileupload-new') + } + + reader.readAsDataURL(file) + } else { + this.$preview.text(file.name) + this.$element.addClass('fileupload-exists').removeClass('fileupload-new') + } + }, + + clear: function(e) { + this.$hidden.val('') + this.$hidden.attr('name', this.name) + this.$input.attr('name', '') + + //ie8+ doesn't support changing the value of input with type=file so clone instead + if (navigator.userAgent.match(/msie/i)){ + var inputClone = this.$input.clone(true); + this.$input.after(inputClone); + this.$input.remove(); + this.$input = inputClone; + }else{ + this.$input.val('') + } + + this.$preview.html('') + this.$element.addClass('fileupload-new').removeClass('fileupload-exists') + + if (e) { + this.$input.trigger('change', [ 'clear' ]) + e.preventDefault() + } + }, + + reset: function(e) { + this.clear() + + this.$hidden.val(this.original.hiddenVal) + this.$preview.html(this.original.preview) + + if (this.original.exists) this.$element.addClass('fileupload-exists').removeClass('fileupload-new') + else this.$element.addClass('fileupload-new').removeClass('fileupload-exists') + }, + + trigger: function(e) { + this.$input.trigger('click') + e.preventDefault() + } } @@ -251,12 +251,12 @@ * =========================== */ $.fn.fileupload = function (options) { - return this.each(function () { - var $this = $(this) - , data = $this.data('fileupload') - if (!data) $this.data('fileupload', (data = new Fileupload(this, options))) - if (typeof options == 'string') data[options]() - }) + return this.each(function () { + var $this = $(this) + , data = $this.data('fileupload') + if (!data) $this.data('fileupload', (data = new Fileupload(this, options))) + if (typeof options == 'string') data[options]() + }) } $.fn.fileupload.Constructor = Fileupload @@ -266,15 +266,15 @@ * ================== */ $(document).on('click.fileupload.data-api', '[data-provides="fileupload"]', function (e) { - var $this = $(this) - if ($this.data('fileupload')) return - $this.fileupload($this.data()) - - var $target = $(e.target).closest('[data-dismiss="fileupload"],[data-trigger="fileupload"]'); - if ($target.length > 0) { - $target.trigger('click.fileupload') - e.preventDefault() - } + var $this = $(this) + if ($this.data('fileupload')) return + $this.fileupload($this.data()) + + var $target = $(e.target).closest('[data-dismiss="fileupload"],[data-trigger="fileupload"]'); + if ($target.length > 0) { + $target.trigger('click.fileupload') + e.preventDefault() + } }) }(window.jQuery); @@ -386,6 +386,17 @@ return ($(el).data('sortableId')) || $(el).find(handle).data('sortableId'); } + function buildFormData(items, itemName) { + var tagNameArr = []; + + itemName = itemName || "item"; + $.each(items, function() { + tagNameArr.push(itemName + "[]=" + $(this).data("sortableId")); + }); + + return tagNameArr.join("&"); + } + /* sortable DATA-API * ============ */ @@ -403,17 +414,23 @@ $(function () { tolerance: $this.data('tolerance'), stop: function(event, ui) { if ($(this).data('sortUrl')) { - // determine whether we move the element up or down - $.ajax([ - $(this).data('sortUrl'), - '&from=', - getElementSortableId(ui.item, $(this).data('handle')), - '&to=', - getElementSortableId(ui.item.next(), $(this).data('handle')) - ].join('')); - } - else - { + if ($(this).data('postAll')) { + $.ajax({ + url: $(this).data("sortUrl"), + data: buildFormData($(this).find("[data-sortable-id]")), + type:"post", + dataType:"json" + }); + } else { + $.ajax([ + $(this).data('sortUrl'), + '&from=', + getElementSortableId(ui.item, $(this).data('handle')), + '&to=', + getElementSortableId(ui.item.next(), $(this).data('handle')) + ].join('')); + } + } else { $(this).children().each(function(i){ $(this).find('[data-sortable="position"]').val(i); }); @@ -674,65 +691,65 @@ $(function () { * ==================== */ var SelectTab = function (element) { - this.element = $(element); + this.element = $(element); }; SelectTab.prototype = { - constructor: SelectTab, + constructor: SelectTab, - show: function () { + show: function () { - var $this = this.element, - $previous = $($this.data('previous')), - $target = $('#' + ($this.data('tabPrefix') || '') + $this.val()), - e, - transition = $.support.transition && $target.hasClass('fade'); - - if ( $target.hasClass('active') ) return; + var $this = this.element, + $previous = $($this.data('previous')), + $target = $('#' + ($this.data('tabPrefix') || '') + $this.val()), + e, + transition = $.support.transition && $target.hasClass('fade'); + + if ( $target.hasClass('active') ) return; - e = $.Event('show', { - target: $target, - relatedTarget: $previous - }); + e = $.Event('show', { + target: $target, + relatedTarget: $previous + }); - $this.trigger(e); + $this.trigger(e); - if (e.isDefaultPrevented()) return; + if (e.isDefaultPrevented()) return; - function next() { - $previous.removeClass('active'); + function next() { + $previous.removeClass('active'); - $target.addClass('active'); + $target.addClass('active'); - if (transition) { - $target.addClass('in'); - } else { - $target.removeClass('fade'); - } + if (transition) { + $target.addClass('in'); + } else { + $target.removeClass('fade'); + } - if ($this.data('disable')) { - $target.removeAttr('disabled'); - $previous.attr('disabled', 'disabled'); - } + if ($this.data('disable')) { + $target.removeAttr('disabled'); + $previous.attr('disabled', 'disabled'); + } - $this.trigger({ - type: 'shown', - target: $target, - relatedTarget: $previous - }); + $this.trigger({ + type: 'shown', + target: $target, + relatedTarget: $previous + }); - } + } - if (transition) { - $previous.one($.support.transition.end, next); - } else { - next(); - } + if (transition) { + $previous.one($.support.transition.end, next); + } else { + next(); + } - $previous.removeClass('in'); - $this.data('previous', '#' + ($this.data('tabPrefix') || '') + $this.val()); - } + $previous.removeClass('in'); + $this.data('previous', '#' + ($this.data('tabPrefix') || '') + $this.val()); + } }; @@ -742,12 +759,12 @@ $(function () { var old = $.fn.selecttab; $.fn.selecttab = function ( option ) { - return this.each(function () { - var $this = $(this), - data = $this.data('selecttab'); - if (!data) $this.data('selecttab', (data = new SelectTab(this))); - if (typeof option == 'string') data[option](); - }); + return this.each(function () { + var $this = $(this), + data = $this.data('selecttab'); + if (!data) $this.data('selecttab', (data = new SelectTab(this))); + if (typeof option == 'string') data[option](); + }); }; $.fn.selecttab.Constructor = SelectTab; @@ -757,8 +774,8 @@ $(function () { * =============== */ $.fn.selecttab.noConflict = function () { - $.fn.selecttab = old; - return this; + $.fn.selecttab = old; + return this; }; @@ -766,374 +783,374 @@ $(function () { * ============ */ $(document).on('change.selecttab.data-api', '[data-provide="selecttab"]', function (e) { - e.preventDefault(); - $(this).selecttab('show'); + e.preventDefault(); + $(this).selecttab('show'); }); -}(window.jQuery);// -// -// bootstrap-typeahead.js -// -// Bootstrap Typeahead+ v2.0 -// Terry Rosen -// https://github.com/tcrosen/twitter-bootstrap-typeahead -// -// - -! -function ($) { - - 'use strict'; - - var _defaults = { - source: [], - maxResults: 8, - minLength: 1, - menu: '', - item: '
  • ', - display: 'name', - val: 'id', - itemSelected: function () { } - }, - - _keyCodes = { - DOWN: 40, - ENTER: 13 || 108, - ESCAPE: 27, - TAB: 9, - UP: 38 - }, - - Typeahead = function (element, options) { - this.$element = $(element); - this.options = $.extend(true, {}, $.fn.typeahead.defaults, options); - this.$menu = $(this.options.menu).appendTo('body'); - this.sorter = this.options.sorter || this.sorter; - this.highlighter = this.options.highlighter || this.highlighter; - this.shown = false; - this.initSource(); - this.listen(); - } - - Typeahead.prototype = { - - constructor: Typeahead, - - initSource: function() { - - if (this.options.source) { - if (typeof this.options.source === 'string') { - this.source = $.extend({}, $.ajaxSettings, { url: this.options.source }) - } else if (typeof this.options.source === 'object') { - if (this.options.source instanceof Array) { - this.source = this.options.source; - } else { - this.source = $.extend(true, {}, $.ajaxSettings, this.options.source); - } - } - } - }, - - eventSupported: function(eventName) { - var isSupported = (eventName in this.$element); - - if (!isSupported) { - this.$element.setAttribute(eventName, 'return;'); - isSupported = typeof this.$element[eventName] === 'function'; - } - - return isSupported; - }, - - lookup: function (event) { - var that = this, - items; - - this.query = this.$element.val(); - if (!this.query || this.query.length < this.options.minLength) { - return this.shown ? this.hide() : this; - } - - if (this.source.url) { - if (this.xhr) this.xhr.abort(); - - this.xhr = $.ajax( - $.extend({}, this.source, { - data: { query: that.query }, - success: $.proxy(that.filter, that) - }) - ); - } else { - items = $.proxy(that.filter(that.source), that); - } - }, - - filter: function(data) { - var that = this, +}(window.jQuery);// +// +// bootstrap-typeahead.js +// +// Bootstrap Typeahead+ v2.0 +// Terry Rosen +// https://github.com/tcrosen/twitter-bootstrap-typeahead +// +// + +! +function ($) { + + 'use strict'; + + var _defaults = { + source: [], + maxResults: 8, + minLength: 1, + menu: '', + item: '
  • ', + display: 'name', + val: 'id', + itemSelected: function () { } + }, + + _keyCodes = { + DOWN: 40, + ENTER: 13 || 108, + ESCAPE: 27, + TAB: 9, + UP: 38 + }, + + Typeahead = function (element, options) { + this.$element = $(element); + this.options = $.extend(true, {}, $.fn.typeahead.defaults, options); + this.$menu = $(this.options.menu).appendTo('body'); + this.sorter = this.options.sorter || this.sorter; + this.highlighter = this.options.highlighter || this.highlighter; + this.shown = false; + this.initSource(); + this.listen(); + } + + Typeahead.prototype = { + + constructor: Typeahead, + + initSource: function() { + + if (this.options.source) { + if (typeof this.options.source === 'string') { + this.source = $.extend({}, $.ajaxSettings, { url: this.options.source }) + } else if (typeof this.options.source === 'object') { + if (this.options.source instanceof Array) { + this.source = this.options.source; + } else { + this.source = $.extend(true, {}, $.ajaxSettings, this.options.source); + } + } + } + }, + + eventSupported: function(eventName) { + var isSupported = (eventName in this.$element); + + if (!isSupported) { + this.$element.setAttribute(eventName, 'return;'); + isSupported = typeof this.$element[eventName] === 'function'; + } + + return isSupported; + }, + + lookup: function (event) { + var that = this, + items; + + this.query = this.$element.val(); + if (!this.query || this.query.length < this.options.minLength) { + return this.shown ? this.hide() : this; + } + + if (this.source.url) { + if (this.xhr) this.xhr.abort(); + + this.xhr = $.ajax( + $.extend({}, this.source, { + data: { query: that.query }, + success: $.proxy(that.filter, that) + }) + ); + } else { + items = $.proxy(that.filter(that.source), that); + } + }, + + filter: function(data) { + var that = this, items; - - items = $.grep(data, function (item) { + + items = $.grep(data, function (item) { var query_items = that.query.toLowerCase().split(' '), - data = item[that.options.display].toLowerCase(); + data = item[that.options.display].toLowerCase(); for (var i = query_items.length - 1; i >= 0; i--) { - if (~data.indexOf(query_items[i])) - return true; + if (~data.indexOf(query_items[i])) + return true; }; - }); - + }); + if ( ! items || ! items.length) { - return this.shown ? this.hide() : this; - } else { - items = items.slice(0, this.options.maxResults); - } - - return this.render(this.sorter(items)).show(); - }, - sorter: function (items) { - var that = this, - beginswith = [], - caseSensitive = [], - caseInsensitive = [], - item; - - while (item = items.shift()) { - if (!item[that.options.display].toLowerCase().indexOf(this.query.toLowerCase())) { - beginswith.push(item); - } else if (~item[that.options.display].indexOf(this.query)) { - caseSensitive.push(item); - } else { - caseInsensitive.push(item); - } - } - - return beginswith.concat(caseSensitive, caseInsensitive); - }, - - show: function () { - var pos = $.extend({}, this.$element.offset(), { - height: this.$element[0].offsetHeight - }); - - this.$menu.css({ - top: pos.top + pos.height, - left: pos.left - }); - - this.$menu.show(); - this.shown = true; - return this; - }, - - hide: function () { - this.$menu.hide(); - this.shown = false; - return this; - }, - - highlighter: function (text) { - var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); - return text.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { - return '' + match + ''; - }); - }, - - render: function (items) { - - var that = this, - $templateItem, - $standardItem; - - items = $(items).map(function (i, item) { - if (that.options.tmpl) { - i = $(that.options.tmpl(item)); - } else { - i = $(that.options.item); - } - - if (typeof that.options.val === 'string') { - i.attr('data-value', item[that.options.val]); - } else { - i.attr('data-value', JSON.stringify($.extend({}, that.options.val, item))) - } - - // Modification to allow html templates - $templateItem = item[that.options.display]; - $standardItem = i.find('a'); - - if ($templateItem.indexOf('typeahead-display-val') > 0) { - $standardItem.html($templateItem).find('.typeahead-display-val').each(function(){ - $(this).html(that.highlighter($(this).html())); - }); - } - else { - $standardItem.html(that.highlighter($templateItem)); - } - - return i[0]; - - // End Modification to allow html templates - - - $templateItem = i.find('.typeahead-display-val'); - $standardItem = i.find('a'); - - if ($templateItem.length) { - $templateItem.html(that.highlighter(item[that.options.display])) - } else if ($standardItem.length) { - $standardItem.html(that.highlighter(item[that.options.display])); - } - - return i[0]; - }); - - items.first().addClass('active'); - - setTimeout(function() { - that.$menu.html(items); - }, 250) - - return this; - }, - - select: function () { - var $selectedItem = this.$menu.find('.active'); - this.$element.val($selectedItem.text()).change(); - this.options.itemSelected(JSON.parse($selectedItem.attr('data-value'))); - return this.hide(); - }, - - next: function (event) { - var active = this.$menu.find('.active').removeClass('active'); - var next = active.next(); - - if (!next.length) { - next = $(this.$menu.find('li')[0]); - } - - next.addClass('active'); - }, - - prev: function (event) { - var active = this.$menu.find('.active').removeClass('active'); - var prev = active.prev(); - - if (!prev.length) { - prev = this.$menu.find('li').last(); - } - - prev.addClass('active'); - }, - - listen: function () { - this.$element - .on('blur', $.proxy(this.blur, this)) - .on('keyup', $.proxy(this.keyup, this)); - - if (this.eventSupported('keydown')) { - this.$element.on('keydown', $.proxy(this.keypress, this)); - } else { - this.$element.on('keypress', $.proxy(this.keypress, this)); - } - - this.$menu - .on('click', $.proxy(this.click, this)) - .on('mouseenter', 'li', $.proxy(this.mouseenter, this)); - }, - - keyup: function (e) { - e.stopPropagation(); - e.preventDefault(); - - switch (e.keyCode) { - case _keyCodes.DOWN: - case _keyCodes.UP: - break; - case _keyCodes.TAB: - case _keyCodes.ENTER: - if (!this.shown) return; - this.select(); - break; - case _keyCodes.ESCAPE: - this.hide(); - break; - default: - this.lookup(); - } - }, - - keypress: function (e) { - e.stopPropagation(); - - if (!this.shown) return; - - switch (e.keyCode) { - case _keyCodes.TAB: - case _keyCodes.ESCAPE: - case _keyCodes.ENTER: - e.preventDefault(); - break; - case _keyCodes.UP: - e.preventDefault(); - this.prev(); - break; - case _keyCodes.DOWN: - e.preventDefault(); - this.next(); - break; - } - }, - - blur: function (e) { - var that = this; - e.stopPropagation(); - e.preventDefault(); - setTimeout(function () { - if (!that.$menu.is(':focus')) { - that.hide(); - } - }, 150); - }, - - click: function (e) { - e.stopPropagation(); - e.preventDefault(); - this.select(); - }, - - mouseenter: function (e) { - this.$menu.find('.active').removeClass('active'); - $(e.currentTarget).addClass('active'); - } - } - - // Plugin definition - $.fn.typeahead = function (option) { - return this.each(function () { - var $this = $(this), - data = $this.data('typeahead'), - options = typeof option === 'object' && option; - - if (!data) { - $this.data('typeahead', (data = new Typeahead(this, options))); - } - - if (typeof option === 'string') { - data[option](); - } - }); - } - - $.fn.typeahead.defaults = _defaults; - $.fn.typeahead.Constructor = Typeahead; - - // Data API (no-JS implementation) - $(function () { - $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { - var $this = $(this); - if ($this.data('typeahead')) return; - e.preventDefault(); - $this.typeahead($this.data()); - }) - }); -} (window.jQuery); + return this.shown ? this.hide() : this; + } else { + items = items.slice(0, this.options.maxResults); + } + + return this.render(this.sorter(items)).show(); + }, + sorter: function (items) { + var that = this, + beginswith = [], + caseSensitive = [], + caseInsensitive = [], + item; + + while (item = items.shift()) { + if (!item[that.options.display].toLowerCase().indexOf(this.query.toLowerCase())) { + beginswith.push(item); + } else if (~item[that.options.display].indexOf(this.query)) { + caseSensitive.push(item); + } else { + caseInsensitive.push(item); + } + } + + return beginswith.concat(caseSensitive, caseInsensitive); + }, + + show: function () { + var pos = $.extend({}, this.$element.offset(), { + height: this.$element[0].offsetHeight + }); + + this.$menu.css({ + top: pos.top + pos.height, + left: pos.left + }); + + this.$menu.show(); + this.shown = true; + return this; + }, + + hide: function () { + this.$menu.hide(); + this.shown = false; + return this; + }, + + highlighter: function (text) { + var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); + return text.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { + return '' + match + ''; + }); + }, + + render: function (items) { + + var that = this, + $templateItem, + $standardItem; + + items = $(items).map(function (i, item) { + if (that.options.tmpl) { + i = $(that.options.tmpl(item)); + } else { + i = $(that.options.item); + } + + if (typeof that.options.val === 'string') { + i.attr('data-value', item[that.options.val]); + } else { + i.attr('data-value', JSON.stringify($.extend({}, that.options.val, item))) + } + + // Modification to allow html templates + $templateItem = item[that.options.display]; + $standardItem = i.find('a'); + + if ($templateItem.indexOf('typeahead-display-val') > 0) { + $standardItem.html($templateItem).find('.typeahead-display-val').each(function(){ + $(this).html(that.highlighter($(this).html())); + }); + } + else { + $standardItem.html(that.highlighter($templateItem)); + } + + return i[0]; + + // End Modification to allow html templates + + + $templateItem = i.find('.typeahead-display-val'); + $standardItem = i.find('a'); + + if ($templateItem.length) { + $templateItem.html(that.highlighter(item[that.options.display])) + } else if ($standardItem.length) { + $standardItem.html(that.highlighter(item[that.options.display])); + } + + return i[0]; + }); + + items.first().addClass('active'); + + setTimeout(function() { + that.$menu.html(items); + }, 250) + + return this; + }, + + select: function () { + var $selectedItem = this.$menu.find('.active'); + this.$element.val($selectedItem.text()).change(); + this.options.itemSelected(JSON.parse($selectedItem.attr('data-value'))); + return this.hide(); + }, + + next: function (event) { + var active = this.$menu.find('.active').removeClass('active'); + var next = active.next(); + + if (!next.length) { + next = $(this.$menu.find('li')[0]); + } + + next.addClass('active'); + }, + + prev: function (event) { + var active = this.$menu.find('.active').removeClass('active'); + var prev = active.prev(); + + if (!prev.length) { + prev = this.$menu.find('li').last(); + } + + prev.addClass('active'); + }, + + listen: function () { + this.$element + .on('blur', $.proxy(this.blur, this)) + .on('keyup', $.proxy(this.keyup, this)); + + if (this.eventSupported('keydown')) { + this.$element.on('keydown', $.proxy(this.keypress, this)); + } else { + this.$element.on('keypress', $.proxy(this.keypress, this)); + } + + this.$menu + .on('click', $.proxy(this.click, this)) + .on('mouseenter', 'li', $.proxy(this.mouseenter, this)); + }, + + keyup: function (e) { + e.stopPropagation(); + e.preventDefault(); + + switch (e.keyCode) { + case _keyCodes.DOWN: + case _keyCodes.UP: + break; + case _keyCodes.TAB: + case _keyCodes.ENTER: + if (!this.shown) return; + this.select(); + break; + case _keyCodes.ESCAPE: + this.hide(); + break; + default: + this.lookup(); + } + }, + + keypress: function (e) { + e.stopPropagation(); + + if (!this.shown) return; + + switch (e.keyCode) { + case _keyCodes.TAB: + case _keyCodes.ESCAPE: + case _keyCodes.ENTER: + e.preventDefault(); + break; + case _keyCodes.UP: + e.preventDefault(); + this.prev(); + break; + case _keyCodes.DOWN: + e.preventDefault(); + this.next(); + break; + } + }, + + blur: function (e) { + var that = this; + e.stopPropagation(); + e.preventDefault(); + setTimeout(function () { + if (!that.$menu.is(':focus')) { + that.hide(); + } + }, 150); + }, + + click: function (e) { + e.stopPropagation(); + e.preventDefault(); + this.select(); + }, + + mouseenter: function (e) { + this.$menu.find('.active').removeClass('active'); + $(e.currentTarget).addClass('active'); + } + } + + // Plugin definition + $.fn.typeahead = function (option) { + return this.each(function () { + var $this = $(this), + data = $this.data('typeahead'), + options = typeof option === 'object' && option; + + if (!data) { + $this.data('typeahead', (data = new Typeahead(this, options))); + } + + if (typeof option === 'string') { + data[option](); + } + }); + } + + $.fn.typeahead.defaults = _defaults; + $.fn.typeahead.Constructor = Typeahead; + + // Data API (no-JS implementation) + $(function () { + $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { + var $this = $(this); + if ($this.data('typeahead')) return; + e.preventDefault(); + $this.typeahead($this.data()); + }) + }); +} (window.jQuery); diff --git a/web/js/bootstrap-extensions.min.js b/web/js/bootstrap-extensions.min.js index e2bf37b..e0b6306 100644 --- a/web/js/bootstrap-extensions.min.js +++ b/web/js/bootstrap-extensions.min.js @@ -3,4 +3,4 @@ * Copyright 2013 OpenBuildings, Inc. * http://www.apache.org/licenses/LICENSE-2.0.txt */ -!function(e){"use strict";var t=function(t,n){var r=e(t);r.on("dragstart",function(t){t.originalEvent.dataTransfer.setData("text/plain",r.text());e(t.currentTarget).data("current",t.target).data("x",t.originalEvent.clientX).data("y",t.originalEvent.clientY)});r.on("dragover",function(e){e.preventDefault()});r.on("drop",function(t){var n=e(e(t.currentTarget).data("current")),r=n.position().left+t.originalEvent.clientX-e(t.currentTarget).data("x"),i=n.position().top+t.originalEvent.clientY-e(t.currentTarget).data("y");n.css({left:r/e(t.currentTarget).width()*100+"%",top:i/e(t.currentTarget).height()*100+"%"});n.find('[data-draggable="left"]').val(r/e(t.currentTarget).width()*100);n.find('[data-draggable="top"]').val(i/e(t.currentTarget).height()*100)})};t.prototype={constructor:t};var n=e.fn.draggable;e.fn.draggable=function(n){return this.each(function(){var r=e(this),i=r.data("draggable"),s=typeof n==="object"&&n;if(!i){r.data("draggable",i=new t(this,s))}if(typeof n==="string"){i[n]()}})};e.fn.draggable.Constructor=t;e.fn.draggable.noConflict=function(){e.fn.draggable=n;return this};e(function(){e(document).on("mouseover.draggable.data-api",'[data-provide="draggable"]',function(t){var n=e(this);if(n.data("draggable"))return;t.preventDefault();n.draggable(n.data())})})}(window.jQuery);!function(e){"use strict";var t=function(t,n){this.$element=e(t);this.type=this.$element.data("uploadtype")||(this.$element.find(".thumbnail").length>0?"image":"file");this.$input=this.$element.find(":file");if(this.$input.length===0)return;this.name=this.$input.attr("name")||n.name;this.$hidden=this.$element.find('input[type=hidden][name="'+this.name+'"]');if(this.$hidden.length===0){this.$hidden=e('');this.$element.prepend(this.$hidden)}this.$preview=this.$element.find(".fileupload-preview");var r=this.$preview.css("height");if(this.$preview.css("display")!="inline"&&r!="0px"&&r!="none")this.$preview.css("line-height",r);this.original={exists:this.$element.hasClass("fileupload-exists"),preview:this.$preview.html(),hiddenVal:this.$hidden.val()};this.$remove=this.$element.find('[data-dismiss="fileupload"]');this.$element.find('[data-trigger="fileupload"]').on("click.fileupload",e.proxy(this.trigger,this));this.listen()};t.prototype={listen:function(){this.$input.on("change.fileupload",e.proxy(this.change,this));e(this.$input[0].form).on("reset.fileupload",e.proxy(this.reset,this));if(this.$remove)this.$remove.on("click.fileupload",e.proxy(this.clear,this))},change:function(e,t){if(t==="clear")return;var n=e.target.files!==undefined?e.target.files[0]:e.target.value?{name:e.target.value.replace(/^.+\\/,"")}:null;if(!n){this.clear();return}this.$hidden.val("");this.$hidden.attr("name","");this.$input.attr("name",this.name);if(this.type==="image"&&this.$preview.length>0&&(typeof n.type!=="undefined"?n.type.match("image.*"):n.name.match(/\.(gif|png|jpe?g)$/i))&&typeof FileReader!=="undefined"){var r=new FileReader;var i=this.$preview;var s=this.$element;r.onload=function(e){i.html('");s.addClass("fileupload-exists").removeClass("fileupload-new")};r.readAsDataURL(n)}else{this.$preview.text(n.name);this.$element.addClass("fileupload-exists").removeClass("fileupload-new")}},clear:function(e){this.$hidden.val("");this.$hidden.attr("name",this.name);this.$input.attr("name","");if(navigator.userAgent.match(/msie/i)){var t=this.$input.clone(true);this.$input.after(t);this.$input.remove();this.$input=t}else{this.$input.val("")}this.$preview.html("");this.$element.addClass("fileupload-new").removeClass("fileupload-exists");if(e){this.$input.trigger("change",["clear"]);e.preventDefault()}},reset:function(e){this.clear();this.$hidden.val(this.original.hiddenVal);this.$preview.html(this.original.preview);if(this.original.exists)this.$element.addClass("fileupload-exists").removeClass("fileupload-new");else this.$element.addClass("fileupload-new").removeClass("fileupload-exists")},trigger:function(e){this.$input.trigger("click");e.preventDefault()}};e.fn.fileupload=function(n){return this.each(function(){var r=e(this),i=r.data("fileupload");if(!i)r.data("fileupload",i=new t(this,n));if(typeof n=="string")i[n]()})};e.fn.fileupload.Constructor=t;e(document).on("click.fileupload.data-api",'[data-provides="fileupload"]',function(t){var n=e(this);if(n.data("fileupload"))return;n.fileupload(n.data());var r=e(t.target).closest('[data-dismiss="fileupload"],[data-trigger="fileupload"]');if(r.length>0){r.trigger("click.fileupload");t.preventDefault()}})}(window.jQuery);!function(e){"use strict";var t=function(t,n){var r=e(t);r.on("dragstart",function(t){var i=t.target;t.originalEvent.dataTransfer.setData("text/plain",r.text());e(n.dropzone).addClass("drop-target").height(e(n.dropzone).closest(".row-fluid").height()).data("href",e(i).data("href"))}).on("dragover",function(e){e.preventDefault()}).on("dragend",function(t){e(n.dropzone).removeClass("drop-target").data("href",false)});e(n.dropzone).on("dragover",function(e){e.preventDefault()}).on("drop",function(t){if(e(t.currentTarget).data("href")){window.location=e(t.currentTarget).data("href")}return false})};t.prototype={constructor:t};var n=e.fn.filters;e.fn.filters=function(n){return this.each(function(){var r=e(this),i=r.data("filters"),s=typeof n==="object"&&n;if(!i){r.data("filters",i=new t(this,s))}if(typeof n==="string"){i[n]()}})};e.fn.filters.Constructor=t;e.fn.filters.noConflict=function(){e.fn.filters=n;return this};e(function(){e(document).on("mouseover.filters.data-api",'[data-provide="filters"]',function(t){var n=e(this);if(n.data("filters"))return;t.preventDefault();n.filters(n.data())})})}(window.jQuery);!function(e){"use strict";function t(t,n){return e(t).data("sortableId")||e(t).find(n).data("sortableId")}e(function(){function t(t,n){var r=[],n=n||"item";e.each(t,function(){r.push(n+"[]="+e(this).data("sortableId"))});return r.join("&")}document.addEventListener("mousedown",function(n){if(e(n.target).closest('[data-provide="sortable"]').length){var r=e(n.target).closest('[data-provide="sortable"]');if(r.data("sortable"))return;r.sortable({handle:r.data("handle"),items:r.data("items"),placeholder:r.data("placeholder"),tolerance:r.data("tolerance"),stop:function(n,r){if(e(this).data("sortUrl")){e.ajax({url:e(this).data("sortUrl"),data:t(e(this).find("[data-sortable-id]")),type:"post",dataType:"json"})}else{e(this).children().each(function(t){e(this).find('[data-sortable="position"]').val(t)})}}})}},true)})}(window.jQuery);!function(e){"use strict";var t=function(t,n){this.$element=e(t)};t.prototype={constructor:t,reindex:function(){var t=this.$element;var n=new RegExp(t.attr("data-index").replace(/[\-\[\]\/\(\)\*\+\?\.\\\^\$\|]/g,"\\$&").replace("{{index}}","(\\d+)"));t.children(".multiform").each(function(r){e(this).find("input,select,textarea").each(function(){e(this).attr("name",e(this).attr("name").replace(n,t.attr("data-index").replace("{{index}}",r)))})})},add:function(t){e('
    ').html(e(t).clone().html()).prependTo(this.$element).addClass("in");this.$element.multiform("reindex")}};var n=e.fn.multiform;e.fn.multiform=function(n,r){return this.each(function(){var i=e(this),s=i.data("multiform"),o=typeof n==="object"&&n;if(!s){i.data("multiform",s=new t(this,o))}if(typeof n==="string"){s[n](r)}})};e.fn.multiform.Constructor=t;e.fn.multiform.noConflict=function(){e.fn.multiform=n;return this};e(function(){e(document).on("click.multiform.data-api","[data-multiform-add]",function(t){var n=e(e(this).data("multiformAdd"));t.preventDefault();n.multiform("add",e(this).attr("href"))});e(document).on("click.multiform.data-api",'[data-dismiss="multiform"]',function(t){function i(){n.remove();r.multiform("reindex")}var n=e(this).closest(".multiform"),r=n.parent();t.preventDefault();if(e.support.transition){n.addClass("fade").removeClass("in").on(e.support.transition.end,i)}else{i()}})})}(window.jQuery);!function(e){"use strict";var t=function(t,n){var r=this.$element=e(t);this.url=n.url;this.templatestring=n.templatestring;this.count=n.count||e(n.container).children().length;this.$container=e(n.container);this.$element.typeahead({source:n.source,val:{},itemSelected:function(t){if(n.overwrite){e(n.container).empty();r.addClass("hide")}r.val("").remoteselect("add",t)}})};t.prototype={constructor:t,add:function(t){var n=this.$container;if(this.templatestring){n.append(this.templatestring.replace(/\{\{id\}\}/g,t.id).replace(/\{\{variations\}\}/g,t.variations).replace(/\{\{count\}\}/g,this.count++).replace(/\{\{model\}\}/g,t.model).replace(/\{\{name\}\}/g,t.name).replace(/\{\{price\}\}/g,t.price).replace(/\{\{url\}\}/g,t.url));e(".chzn-select").chosen()}else{e.get(this.url.replace(/\{\{id\}\}/g,t?t.id:"").replace(/\{\{count\}\}/g,this.count++).replace(/\{\{model\}\}/g,t?t.model:""),function(t){n.append(t);e(".chzn-select").chosen()})}}};var n=e.fn.remoteselect;e.fn.remoteselect=function(n,r,i){return this.each(function(){var s=e(this),o=s.data("remoteselect"),u=typeof n==="object"&&n;if(!o){s.data("remoteselect",o=new t(this,u||s.data()))}if(typeof n==="string"){o[n](r,i)}})};e.fn.remoteselect.Constructor=t;e.fn.remoteselect.noConflict=function(){e.fn.remoteselect=n;return this};e(function(){e(document).on("focus.remoteselect.data-api",'[data-provide="remoteselect"]',function(t){var n=e(this);if(n.data("remoteselect"))return;t.preventDefault();n.remoteselect(n.data())});e(document).on("click.remoteselect.data-api",'[data-dismiss="remoteselect"]',function(t){function r(){e('input[data-container="#'+n.parent().attr("id")+'"]').removeClass("hide").addClass("in");n.remove()}var n=e(this).closest(".remoteselect-item");t.preventDefault();if(e.support.transition){n.addClass("fade").on(e.support.transition.end,r)}else{r()}});e(document).on("click.remoteselect.data-api","[data-remoteselect-new]",function(t){var n=e(e(this).attr("href")).length?e(e(this).attr("href")):e(this).siblings('[data-provide="remoteselect"]');t.preventDefault();n.remoteselect("add",null,e(this).data("remoteselectNew"))})})}(window.jQuery);!function(e){"use strict";var t=function(t){this.element=e(t)};t.prototype={constructor:t,show:function(){function o(){n.removeClass("active");r.addClass("active");if(s){r.addClass("in")}else{r.removeClass("fade")}if(t.data("disable")){r.removeAttr("disabled");n.attr("disabled","disabled")}t.trigger({type:"shown",target:r,relatedTarget:n})}var t=this.element,n=e(t.data("previous")),r=e("#"+(t.data("tabPrefix")||"")+t.val()),i,s=e.support.transition&&r.hasClass("fade");if(r.hasClass("active"))return;i=e.Event("show",{target:r,relatedTarget:n});t.trigger(i);if(i.isDefaultPrevented())return;if(s){n.one(e.support.transition.end,o)}else{o()}n.removeClass("in");t.data("previous","#"+(t.data("tabPrefix")||"")+t.val())}};var n=e.fn.selecttab;e.fn.selecttab=function(n){return this.each(function(){var r=e(this),i=r.data("selecttab");if(!i)r.data("selecttab",i=new t(this));if(typeof n=="string")i[n]()})};e.fn.selecttab.Constructor=t;e.fn.selecttab.noConflict=function(){e.fn.selecttab=n;return this};e(document).on("change.selecttab.data-api",'[data-provide="selecttab"]',function(t){t.preventDefault();e(this).selecttab("show")})}(window.jQuery);!function(e){"use strict";var t={source:[],maxResults:8,minLength:1,menu:'',item:'
  • ',display:"name",val:"id",itemSelected:function(){}},n={DOWN:40,ENTER:13||108,ESCAPE:27,TAB:9,UP:38},r=function(t,n){this.$element=e(t);this.options=e.extend(true,{},e.fn.typeahead.defaults,n);this.$menu=e(this.options.menu).appendTo("body");this.sorter=this.options.sorter||this.sorter;this.highlighter=this.options.highlighter||this.highlighter;this.shown=false;this.initSource();this.listen()};r.prototype={constructor:r,initSource:function(){if(this.options.source){if(typeof this.options.source==="string"){this.source=e.extend({},e.ajaxSettings,{url:this.options.source})}else if(typeof this.options.source==="object"){if(this.options.source instanceof Array){this.source=this.options.source}else{this.source=e.extend(true,{},e.ajaxSettings,this.options.source)}}}},eventSupported:function(e){var t=e in this.$element;if(!t){this.$element.setAttribute(e,"return;");t=typeof this.$element[e]==="function"}return t},lookup:function(t){var n=this,r;this.query=this.$element.val();if(!this.query||this.query.length=0;i--){if(~r.indexOf(t[i]))return true}});if(!r||!r.length){return this.shown?this.hide():this}else{r=r.slice(0,this.options.maxResults)}return this.render(this.sorter(r)).show()},sorter:function(e){var t=this,n=[],r=[],i=[],s;while(s=e.shift()){if(!s[t.options.display].toLowerCase().indexOf(this.query.toLowerCase())){n.push(s)}else if(~s[t.options.display].indexOf(this.query)){r.push(s)}else{i.push(s)}}return n.concat(r,i)},show:function(){var t=e.extend({},this.$element.offset(),{height:this.$element[0].offsetHeight});this.$menu.css({top:t.top+t.height,left:t.left});this.$menu.show();this.shown=true;return this},hide:function(){this.$menu.hide();this.shown=false;return this},highlighter:function(e){var t=this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&");return e.replace(new RegExp("("+t+")","ig"),function(e,t){return""+t+""})},render:function(t){var n=this,r,i;t=e(t).map(function(t,s){if(n.options.tmpl){t=e(n.options.tmpl(s))}else{t=e(n.options.item)}if(typeof n.options.val==="string"){t.attr("data-value",s[n.options.val])}else{t.attr("data-value",JSON.stringify(e.extend({},n.options.val,s)))}r=s[n.options.display];i=t.find("a");if(r.indexOf("typeahead-display-val")>0){i.html(r).find(".typeahead-display-val").each(function(){e(this).html(n.highlighter(e(this).html()))})}else{i.html(n.highlighter(r))}return t[0];r=t.find(".typeahead-display-val");i=t.find("a");if(r.length){r.html(n.highlighter(s[n.options.display]))}else if(i.length){i.html(n.highlighter(s[n.options.display]))}return t[0]});t.first().addClass("active");setTimeout(function(){n.$menu.html(t)},250);return this},select:function(){var e=this.$menu.find(".active");this.$element.val(e.text()).change();this.options.itemSelected(JSON.parse(e.attr("data-value")));return this.hide()},next:function(t){var n=this.$menu.find(".active").removeClass("active");var r=n.next();if(!r.length){r=e(this.$menu.find("li")[0])}r.addClass("active")},prev:function(e){var t=this.$menu.find(".active").removeClass("active");var n=t.prev();if(!n.length){n=this.$menu.find("li").last()}n.addClass("active")},listen:function(){this.$element.on("blur",e.proxy(this.blur,this)).on("keyup",e.proxy(this.keyup,this));if(this.eventSupported("keydown")){this.$element.on("keydown",e.proxy(this.keypress,this))}else{this.$element.on("keypress",e.proxy(this.keypress,this))}this.$menu.on("click",e.proxy(this.click,this)).on("mouseenter","li",e.proxy(this.mouseenter,this))},keyup:function(e){e.stopPropagation();e.preventDefault();switch(e.keyCode){case n.DOWN:case n.UP:break;case n.TAB:case n.ENTER:if(!this.shown)return;this.select();break;case n.ESCAPE:this.hide();break;default:this.lookup()}},keypress:function(e){e.stopPropagation();if(!this.shown)return;switch(e.keyCode){case n.TAB:case n.ESCAPE:case n.ENTER:e.preventDefault();break;case n.UP:e.preventDefault();this.prev();break;case n.DOWN:e.preventDefault();this.next();break}},blur:function(e){var t=this;e.stopPropagation();e.preventDefault();setTimeout(function(){if(!t.$menu.is(":focus")){t.hide()}},150)},click:function(e){e.stopPropagation();e.preventDefault();this.select()},mouseenter:function(t){this.$menu.find(".active").removeClass("active");e(t.currentTarget).addClass("active")}};e.fn.typeahead=function(t){return this.each(function(){var n=e(this),i=n.data("typeahead"),s=typeof t==="object"&&t;if(!i){n.data("typeahead",i=new r(this,s))}if(typeof t==="string"){i[t]()}})};e.fn.typeahead.defaults=t;e.fn.typeahead.Constructor=r;e(function(){e("body").on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(t){var n=e(this);if(n.data("typeahead"))return;t.preventDefault();n.typeahead(n.data())})})}(window.jQuery) \ No newline at end of file +!function(a){"use strict";var b=function(b){var d=a(b);d.on("dragstart",function(b){b.originalEvent.dataTransfer.setData("text/plain",d.text()),a(b.currentTarget).data("current",b.target).data("x",b.originalEvent.clientX).data("y",b.originalEvent.clientY)}),d.on("dragover",function(a){a.preventDefault()}),d.on("drop",function(b){var c=a(a(b.currentTarget).data("current")),d=c.position().left+b.originalEvent.clientX-a(b.currentTarget).data("x"),e=c.position().top+b.originalEvent.clientY-a(b.currentTarget).data("y");c.css({left:100*(d/a(b.currentTarget).width())+"%",top:100*(e/a(b.currentTarget).height())+"%"}),c.find('[data-draggable="left"]').val(100*(d/a(b.currentTarget).width())),c.find('[data-draggable="top"]').val(100*(e/a(b.currentTarget).height()))})};b.prototype={constructor:b};var c=a.fn.draggable;a.fn.draggable=function(c){return this.each(function(){var d=a(this),e=d.data("draggable"),f="object"==typeof c&&c;e||d.data("draggable",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.draggable.Constructor=b,a.fn.draggable.noConflict=function(){return a.fn.draggable=c,this},a(function(){a(document).on("mouseover.draggable.data-api",'[data-provide="draggable"]',function(b){var c=a(this);c.data("draggable")||(b.preventDefault(),c.draggable(c.data()))})})}(window.jQuery),!function(a){"use strict";var b=function(b,c){if(this.$element=a(b),this.type=this.$element.data("uploadtype")||(this.$element.find(".thumbnail").length>0?"image":"file"),this.$input=this.$element.find(":file"),0!==this.$input.length){this.name=this.$input.attr("name")||c.name,this.$hidden=this.$element.find('input[type=hidden][name="'+this.name+'"]'),0===this.$hidden.length&&(this.$hidden=a(''),this.$element.prepend(this.$hidden)),this.$preview=this.$element.find(".fileupload-preview");var d=this.$preview.css("height");"inline"!=this.$preview.css("display")&&"0px"!=d&&"none"!=d&&this.$preview.css("line-height",d),this.original={exists:this.$element.hasClass("fileupload-exists"),preview:this.$preview.html(),hiddenVal:this.$hidden.val()},this.$remove=this.$element.find('[data-dismiss="fileupload"]'),this.$element.find('[data-trigger="fileupload"]').on("click.fileupload",a.proxy(this.trigger,this)),this.listen()}};b.prototype={listen:function(){this.$input.on("change.fileupload",a.proxy(this.change,this)),a(this.$input[0].form).on("reset.fileupload",a.proxy(this.reset,this)),this.$remove&&this.$remove.on("click.fileupload",a.proxy(this.clear,this))},change:function(a,b){if("clear"!==b){var c=void 0!==a.target.files?a.target.files[0]:a.target.value?{name:a.target.value.replace(/^.+\\/,"")}:null;if(!c)return this.clear(),void 0;if(this.$hidden.val(""),this.$hidden.attr("name",""),this.$input.attr("name",this.name),"image"===this.type&&this.$preview.length>0&&("undefined"!=typeof c.type?c.type.match("image.*"):c.name.match(/\.(gif|png|jpe?g)$/i))&&"undefined"!=typeof FileReader){var d=new FileReader,e=this.$preview,f=this.$element;d.onload=function(a){e.html('"),f.addClass("fileupload-exists").removeClass("fileupload-new")},d.readAsDataURL(c)}else this.$preview.text(c.name),this.$element.addClass("fileupload-exists").removeClass("fileupload-new")}},clear:function(a){if(this.$hidden.val(""),this.$hidden.attr("name",this.name),this.$input.attr("name",""),navigator.userAgent.match(/msie/i)){var b=this.$input.clone(!0);this.$input.after(b),this.$input.remove(),this.$input=b}else this.$input.val("");this.$preview.html(""),this.$element.addClass("fileupload-new").removeClass("fileupload-exists"),a&&(this.$input.trigger("change",["clear"]),a.preventDefault())},reset:function(){this.clear(),this.$hidden.val(this.original.hiddenVal),this.$preview.html(this.original.preview),this.original.exists?this.$element.addClass("fileupload-exists").removeClass("fileupload-new"):this.$element.addClass("fileupload-new").removeClass("fileupload-exists")},trigger:function(a){this.$input.trigger("click"),a.preventDefault()}},a.fn.fileupload=function(c){return this.each(function(){var d=a(this),e=d.data("fileupload");e||d.data("fileupload",e=new b(this,c)),"string"==typeof c&&e[c]()})},a.fn.fileupload.Constructor=b,a(document).on("click.fileupload.data-api",'[data-provides="fileupload"]',function(b){var c=a(this);if(!c.data("fileupload")){c.fileupload(c.data());var d=a(b.target).closest('[data-dismiss="fileupload"],[data-trigger="fileupload"]');d.length>0&&(d.trigger("click.fileupload"),b.preventDefault())}})}(window.jQuery),!function(a){"use strict";var b=function(b,c){var d=a(b);d.on("dragstart",function(b){var e=b.target;b.originalEvent.dataTransfer.setData("text/plain",d.text()),a(c.dropzone).addClass("drop-target").height(a(c.dropzone).closest(".row-fluid").height()).data("href",a(e).data("href"))}).on("dragover",function(a){a.preventDefault()}).on("dragend",function(){a(c.dropzone).removeClass("drop-target").data("href",!1)}),a(c.dropzone).on("dragover",function(a){a.preventDefault()}).on("drop",function(b){return a(b.currentTarget).data("href")&&(window.location=a(b.currentTarget).data("href")),!1})};b.prototype={constructor:b};var c=a.fn.filters;a.fn.filters=function(c){return this.each(function(){var d=a(this),e=d.data("filters"),f="object"==typeof c&&c;e||d.data("filters",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.filters.Constructor=b,a.fn.filters.noConflict=function(){return a.fn.filters=c,this},a(function(){a(document).on("mouseover.filters.data-api",'[data-provide="filters"]',function(b){var c=a(this);c.data("filters")||(b.preventDefault(),c.filters(c.data()))})})}(window.jQuery),!function(a){"use strict";function b(b,c){return a(b).data("sortableId")||a(b).find(c).data("sortableId")}function c(b,c){var d=[];return c=c||"item",a.each(b,function(){d.push(c+"[]="+a(this).data("sortableId"))}),d.join("&")}a(function(){document.addEventListener("mousedown",function(d){if(a(d.target).closest('[data-provide="sortable"]').length){var e=a(d.target).closest('[data-provide="sortable"]');if(e.data("sortable"))return;e.sortable({handle:e.data("handle"),items:e.data("items"),placeholder:e.data("placeholder"),tolerance:e.data("tolerance"),stop:function(d,e){a(this).data("sortUrl")?a(this).data("postAll")?a.ajax({url:a(this).data("sortUrl"),data:c(a(this).find("[data-sortable-id]")),type:"post",dataType:"json"}):a.ajax([a(this).data("sortUrl"),"&from=",b(e.item,a(this).data("handle")),"&to=",b(e.item.next(),a(this).data("handle"))].join("")):a(this).children().each(function(b){a(this).find('[data-sortable="position"]').val(b)})}})}},!0)})}(window.jQuery),!function(a){"use strict";var b=function(b){this.$element=a(b)};b.prototype={constructor:b,reindex:function(){var b=this.$element,c=new RegExp(b.attr("data-index").replace(/[\-\[\]\/\(\)\*\+\?\.\\\^\$\|]/g,"\\$&").replace("{{index}}","(\\d+)"));b.children(".multiform").each(function(d){a(this).find("input,select,textarea").each(function(){a(this).attr("name",a(this).attr("name").replace(c,b.attr("data-index").replace("{{index}}",d)))})})},add:function(b){a('
    ').html(a(b).clone().html()).prependTo(this.$element).addClass("in"),this.$element.multiform("reindex")}};var c=a.fn.multiform;a.fn.multiform=function(c,d){return this.each(function(){var e=a(this),f=e.data("multiform"),g="object"==typeof c&&c;f||e.data("multiform",f=new b(this,g)),"string"==typeof c&&f[c](d)})},a.fn.multiform.Constructor=b,a.fn.multiform.noConflict=function(){return a.fn.multiform=c,this},a(function(){a(document).on("click.multiform.data-api","[data-multiform-add]",function(b){var c=a(a(this).data("multiformAdd"));b.preventDefault(),c.multiform("add",a(this).attr("href"))}),a(document).on("click.multiform.data-api",'[data-dismiss="multiform"]',function(b){function e(){c.remove(),d.multiform("reindex")}var c=a(this).closest(".multiform"),d=c.parent();b.preventDefault(),a.support.transition?c.addClass("fade").removeClass("in").on(a.support.transition.end,e):e()})})}(window.jQuery),!function(a){"use strict";var b=function(b,c){var d=this.$element=a(b);this.url=c.url,this.templatestring=c.templatestring,this.count=c.count||a(c.container).children().length,this.$container=a(c.container),this.$element.typeahead({source:c.source,val:{},itemSelected:function(b){c.overwrite&&(a(c.container).empty(),d.addClass("hide")),d.val("").remoteselect("add",b)}})};b.prototype={constructor:b,add:function(b){var c=this.$container;this.templatestring?(c.append(this.templatestring.replace(/\{\{id\}\}/g,b.id).replace(/\{\{variations\}\}/g,b.variations).replace(/\{\{count\}\}/g,this.count++).replace(/\{\{model\}\}/g,b.model).replace(/\{\{name\}\}/g,b.name).replace(/\{\{price\}\}/g,b.price).replace(/\{\{url\}\}/g,b.url)),a(".chzn-select").chosen()):a.get(this.url.replace(/\{\{id\}\}/g,b?b.id:"").replace(/\{\{count\}\}/g,this.count++).replace(/\{\{model\}\}/g,b?b.model:""),function(b){c.append(b),a(".chzn-select").chosen()})}};var c=a.fn.remoteselect;a.fn.remoteselect=function(c,d,e){return this.each(function(){var f=a(this),g=f.data("remoteselect"),h="object"==typeof c&&c;g||f.data("remoteselect",g=new b(this,h||f.data())),"string"==typeof c&&g[c](d,e)})},a.fn.remoteselect.Constructor=b,a.fn.remoteselect.noConflict=function(){return a.fn.remoteselect=c,this},a(function(){a(document).on("focus.remoteselect.data-api",'[data-provide="remoteselect"]',function(b){var c=a(this);c.data("remoteselect")||(b.preventDefault(),c.remoteselect(c.data()))}),a(document).on("click.remoteselect.data-api",'[data-dismiss="remoteselect"]',function(b){function d(){a('input[data-container="#'+c.parent().attr("id")+'"]').removeClass("hide").addClass("in"),c.remove()}var c=a(this).closest(".remoteselect-item");b.preventDefault(),a.support.transition?c.addClass("fade").on(a.support.transition.end,d):d()}),a(document).on("click.remoteselect.data-api","[data-remoteselect-new]",function(b){var c=a(a(this).attr("href")).length?a(a(this).attr("href")):a(this).siblings('[data-provide="remoteselect"]');b.preventDefault(),c.remoteselect("add",null,a(this).data("remoteselectNew"))})})}(window.jQuery),!function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype={constructor:b,show:function(){function g(){c.removeClass("active"),d.addClass("active"),f?d.addClass("in"):d.removeClass("fade"),b.data("disable")&&(d.removeAttr("disabled"),c.attr("disabled","disabled")),b.trigger({type:"shown",target:d,relatedTarget:c})}var e,b=this.element,c=a(b.data("previous")),d=a("#"+(b.data("tabPrefix")||"")+b.val()),f=a.support.transition&&d.hasClass("fade");d.hasClass("active")||(e=a.Event("show",{target:d,relatedTarget:c}),b.trigger(e),e.isDefaultPrevented()||(f?c.one(a.support.transition.end,g):g(),c.removeClass("in"),b.data("previous","#"+(b.data("tabPrefix")||"")+b.val())))}};var c=a.fn.selecttab;a.fn.selecttab=function(c){return this.each(function(){var d=a(this),e=d.data("selecttab");e||d.data("selecttab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.selecttab.Constructor=b,a.fn.selecttab.noConflict=function(){return a.fn.selecttab=c,this},a(document).on("change.selecttab.data-api",'[data-provide="selecttab"]',function(b){b.preventDefault(),a(this).selecttab("show")})}(window.jQuery),!function(a){"use strict";var b={source:[],maxResults:8,minLength:1,menu:'',item:'
  • ',display:"name",val:"id",itemSelected:function(){}},c={DOWN:40,ENTER:13,ESCAPE:27,TAB:9,UP:38},d=function(b,c){this.$element=a(b),this.options=a.extend(!0,{},a.fn.typeahead.defaults,c),this.$menu=a(this.options.menu).appendTo("body"),this.sorter=this.options.sorter||this.sorter,this.highlighter=this.options.highlighter||this.highlighter,this.shown=!1,this.initSource(),this.listen()};d.prototype={constructor:d,initSource:function(){this.options.source&&("string"==typeof this.options.source?this.source=a.extend({},a.ajaxSettings,{url:this.options.source}):"object"==typeof this.options.source&&(this.source=this.options.source instanceof Array?this.options.source:a.extend(!0,{},a.ajaxSettings,this.options.source)))},eventSupported:function(a){var b=a in this.$element;return b||(this.$element.setAttribute(a,"return;"),b="function"==typeof this.$element[a]),b},lookup:function(){var d,c=this;return this.query=this.$element.val(),!this.query||this.query.length=0;e--)if(~d.indexOf(b[e]))return!0}),d&&d.length?(d=d.slice(0,this.options.maxResults),this.render(this.sorter(d)).show()):this.shown?this.hide():this},sorter:function(a){for(var f,b=this,c=[],d=[],e=[];f=a.shift();)f[b.options.display].toLowerCase().indexOf(this.query.toLowerCase())?~f[b.options.display].indexOf(this.query)?d.push(f):e.push(f):c.push(f);return c.concat(d,e)},show:function(){var b=a.extend({},this.$element.offset(),{height:this.$element[0].offsetHeight});return this.$menu.css({top:b.top+b.height,left:b.left}),this.$menu.show(),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},highlighter:function(a){var b=this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&");return a.replace(new RegExp("("+b+")","ig"),function(a,b){return""+b+""})},render:function(b){var d,e,c=this;return b=a(b).map(function(b,f){return b=c.options.tmpl?a(c.options.tmpl(f)):a(c.options.item),"string"==typeof c.options.val?b.attr("data-value",f[c.options.val]):b.attr("data-value",JSON.stringify(a.extend({},c.options.val,f))),d=f[c.options.display],e=b.find("a"),d.indexOf("typeahead-display-val")>0?e.html(d).find(".typeahead-display-val").each(function(){a(this).html(c.highlighter(a(this).html()))}):e.html(c.highlighter(d)),b[0]}),b.first().addClass("active"),setTimeout(function(){c.$menu.html(b)},250),this},select:function(){var a=this.$menu.find(".active");return this.$element.val(a.text()).change(),this.options.itemSelected(JSON.parse(a.attr("data-value"))),this.hide()},next:function(){var c=this.$menu.find(".active").removeClass("active"),d=c.next();d.length||(d=a(this.$menu.find("li")[0])),d.addClass("active")},prev:function(){var b=this.$menu.find(".active").removeClass("active"),c=b.prev();c.length||(c=this.$menu.find("li").last()),c.addClass("active")},listen:function(){this.$element.on("blur",a.proxy(this.blur,this)).on("keyup",a.proxy(this.keyup,this)),this.eventSupported("keydown")?this.$element.on("keydown",a.proxy(this.keypress,this)):this.$element.on("keypress",a.proxy(this.keypress,this)),this.$menu.on("click",a.proxy(this.click,this)).on("mouseenter","li",a.proxy(this.mouseenter,this))},keyup:function(a){switch(a.stopPropagation(),a.preventDefault(),a.keyCode){case c.DOWN:case c.UP:break;case c.TAB:case c.ENTER:if(!this.shown)return;this.select();break;case c.ESCAPE:this.hide();break;default:this.lookup()}},keypress:function(a){if(a.stopPropagation(),this.shown)switch(a.keyCode){case c.TAB:case c.ESCAPE:case c.ENTER:a.preventDefault();break;case c.UP:a.preventDefault(),this.prev();break;case c.DOWN:a.preventDefault(),this.next()}},blur:function(a){var b=this;a.stopPropagation(),a.preventDefault(),setTimeout(function(){b.$menu.is(":focus")||b.hide()},150)},click:function(a){a.stopPropagation(),a.preventDefault(),this.select()},mouseenter:function(b){this.$menu.find(".active").removeClass("active"),a(b.currentTarget).addClass("active")}},a.fn.typeahead=function(b){return this.each(function(){var c=a(this),e=c.data("typeahead"),f="object"==typeof b&&b;e||c.data("typeahead",e=new d(this,f)),"string"==typeof b&&e[b]()})},a.fn.typeahead.defaults=b,a.fn.typeahead.Constructor=d,a(function(){a("body").on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(b){var c=a(this);c.data("typeahead")||(b.preventDefault(),c.typeahead(c.data()))})})}(window.jQuery); diff --git a/web/js/bootstrap-extensions/bootstrap-jquery-ui-sortable.js b/web/js/bootstrap-extensions/bootstrap-jquery-ui-sortable.js index 6c8d55a..a20a7ba 100644 --- a/web/js/bootstrap-extensions/bootstrap-jquery-ui-sortable.js +++ b/web/js/bootstrap-extensions/bootstrap-jquery-ui-sortable.js @@ -6,6 +6,17 @@ return ($(el).data('sortableId')) || $(el).find(handle).data('sortableId'); } + function buildFormData(items, itemName) { + var tagNameArr = []; + + itemName = itemName || "item"; + $.each(items, function() { + tagNameArr.push(itemName + "[]=" + $(this).data("sortableId")); + }); + + return tagNameArr.join("&"); + } + /* sortable DATA-API * ============ */ @@ -23,17 +34,23 @@ $(function () { tolerance: $this.data('tolerance'), stop: function(event, ui) { if ($(this).data('sortUrl')) { - // determine whether we move the element up or down - $.ajax([ - $(this).data('sortUrl'), - '&from=', - getElementSortableId(ui.item, $(this).data('handle')), - '&to=', - getElementSortableId(ui.item.next(), $(this).data('handle')) - ].join('')); - } - else - { + if ($(this).data('postAll')) { + $.ajax({ + url: $(this).data("sortUrl"), + data: buildFormData($(this).find("[data-sortable-id]")), + type:"post", + dataType:"json" + }); + } else { + $.ajax([ + $(this).data('sortUrl'), + '&from=', + getElementSortableId(ui.item, $(this).data('handle')), + '&to=', + getElementSortableId(ui.item.next(), $(this).data('handle')) + ].join('')); + } + } else { $(this).children().each(function(i){ $(this).find('[data-sortable="position"]').val(i); }); @@ -44,4 +61,4 @@ $(function () { }, true); }); -}(window.jQuery); \ No newline at end of file +}(window.jQuery);