diff --git a/app/assets/javascripts/desktop/books_pages.js b/app/assets/javascripts/desktop/books_pages.js
new file mode 100644
index 00000000..48833ff8
--- /dev/null
+++ b/app/assets/javascripts/desktop/books_pages.js
@@ -0,0 +1,33 @@
+orbitDesktop.prototype.initializeBooks = function(target,url,cache){
+ this.initializeBooks.list = function(){
+ var bindHandlers = function(){
+ o.simple_drop_down();
+
+ o.tinyscrollbar_ext({
+ main: '.tinycanvas',
+ fill: '.list_t'
+ })
+ }
+
+
+ bindHandlers();
+
+ }
+
+ this.initializeBooks.addbook = function(){
+ var bindHandlers = function(){
+ o.simple_drop_down();
+
+ o.tinyscrollbar_ext({
+ main: '.tinycanvas',
+ fill: '.s_grid_con'
+ })
+
+ }
+
+ bindHandlers();
+
+ }
+ this.initializeBooks.list();
+
+}
diff --git a/app/assets/javascripts/desktop/bootstrap.js b/app/assets/javascripts/desktop/bootstrap.js
new file mode 100644
index 00000000..7b3d7982
--- /dev/null
+++ b/app/assets/javascripts/desktop/bootstrap.js
@@ -0,0 +1,2164 @@
+/* ===================================================
+ * bootstrap-transition.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#transitions
+ * ===================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* CSS TRANSITION SUPPORT (http://www.modernizr.com/)
+ * ======================================================= */
+
+ $(function () {
+
+ $.support.transition = (function () {
+
+ var transitionEnd = (function () {
+
+ var el = document.createElement('bootstrap')
+ , transEndEventNames = {
+ 'WebkitTransition' : 'webkitTransitionEnd'
+ , 'MozTransition' : 'transitionend'
+ , 'OTransition' : 'oTransitionEnd otransitionend'
+ , 'transition' : 'transitionend'
+ }
+ , name
+
+ for (name in transEndEventNames){
+ if (el.style[name] !== undefined) {
+ return transEndEventNames[name]
+ }
+ }
+
+ }())
+
+ return transitionEnd && {
+ end: transitionEnd
+ }
+
+ })()
+
+ })
+
+}(window.jQuery);/* ==========================================================
+ * bootstrap-alert.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#alerts
+ * ==========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* ALERT CLASS DEFINITION
+ * ====================== */
+
+ var dismiss = '[data-dismiss="alert"]'
+ , Alert = function (el) {
+ $(el).on('click', dismiss, this.close)
+ }
+
+ Alert.prototype.close = function (e) {
+ var $this = $(this)
+ , selector = $this.attr('data-target')
+ , $parent
+
+ if (!selector) {
+ selector = $this.attr('href')
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
+ }
+
+ $parent = $(selector)
+
+ e && e.preventDefault()
+
+ $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
+
+ $parent.trigger(e = $.Event('close'))
+
+ if (e.isDefaultPrevented()) return
+
+ $parent.removeClass('in')
+
+ function removeElement() {
+ $parent
+ .trigger('closed')
+ .remove()
+ }
+
+ $.support.transition && $parent.hasClass('fade') ?
+ $parent.on($.support.transition.end, removeElement) :
+ removeElement()
+ }
+
+
+ /* ALERT PLUGIN DEFINITION
+ * ======================= */
+
+ var old = $.fn.alert
+
+ $.fn.alert = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('alert')
+ if (!data) $this.data('alert', (data = new Alert(this)))
+ if (typeof option == 'string') data[option].call($this)
+ })
+ }
+
+ $.fn.alert.Constructor = Alert
+
+
+ /* ALERT NO CONFLICT
+ * ================= */
+
+ $.fn.alert.noConflict = function () {
+ $.fn.alert = old
+ return this
+ }
+
+
+ /* ALERT DATA-API
+ * ============== */
+
+ $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)
+
+}(window.jQuery);/* ============================================================
+ * bootstrap-button.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#buttons
+ * ============================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================ */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* BUTTON PUBLIC CLASS DEFINITION
+ * ============================== */
+
+ var Button = function (element, options) {
+ this.$element = $(element)
+ this.options = $.extend({}, $.fn.button.defaults, options)
+ }
+
+ Button.prototype.setState = function (state) {
+ var d = 'disabled'
+ , $el = this.$element
+ , data = $el.data()
+ , val = $el.is('input') ? 'val' : 'html'
+
+ state = state + 'Text'
+ data.resetText || $el.data('resetText', $el[val]())
+
+ $el[val](data[state] || this.options[state])
+
+ // push to event loop to allow forms to submit
+ setTimeout(function () {
+ state == 'loadingText' ?
+ $el.addClass(d).attr(d, d) :
+ $el.removeClass(d).removeAttr(d)
+ }, 0)
+ }
+
+ Button.prototype.toggle = function () {
+ var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
+
+ $parent && $parent
+ .find('.active')
+ .removeClass('active')
+
+ this.$element.toggleClass('active')
+ }
+
+
+ /* BUTTON PLUGIN DEFINITION
+ * ======================== */
+
+ var old = $.fn.button
+
+ $.fn.button = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('button')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('button', (data = new Button(this, options)))
+ if (option == 'toggle') data.toggle()
+ else if (option) data.setState(option)
+ })
+ }
+
+ $.fn.button.defaults = {
+ loadingText: 'loading...'
+ }
+
+ $.fn.button.Constructor = Button
+
+
+ /* BUTTON NO CONFLICT
+ * ================== */
+
+ $.fn.button.noConflict = function () {
+ $.fn.button = old
+ return this
+ }
+
+
+ /* BUTTON DATA-API
+ * =============== */
+
+ $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) {
+ var $btn = $(e.target)
+ if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
+ $btn.button('toggle')
+ })
+
+}(window.jQuery);/* ==========================================================
+ * bootstrap-carousel.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#carousel
+ * ==========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* CAROUSEL CLASS DEFINITION
+ * ========================= */
+
+ var Carousel = function (element, options) {
+ this.$element = $(element)
+ this.options = options
+ this.options.pause == 'hover' && this.$element
+ .on('mouseenter', $.proxy(this.pause, this))
+ .on('mouseleave', $.proxy(this.cycle, this))
+ }
+
+ Carousel.prototype = {
+
+ cycle: function (e) {
+ if (!e) this.paused = false
+ this.options.interval
+ && !this.paused
+ && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
+ return this
+ }
+
+ , to: function (pos) {
+ var $active = this.$element.find('.item.active')
+ , children = $active.parent().children()
+ , activePos = children.index($active)
+ , that = this
+
+ if (pos > (children.length - 1) || pos < 0) return
+
+ if (this.sliding) {
+ return this.$element.one('slid', function () {
+ that.to(pos)
+ })
+ }
+
+ if (activePos == pos) {
+ return this.pause().cycle()
+ }
+
+ return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
+ }
+
+ , pause: function (e) {
+ if (!e) this.paused = true
+ if (this.$element.find('.next, .prev').length && $.support.transition.end) {
+ this.$element.trigger($.support.transition.end)
+ this.cycle()
+ }
+ clearInterval(this.interval)
+ this.interval = null
+ return this
+ }
+
+ , next: function () {
+ if (this.sliding) return
+ return this.slide('next')
+ }
+
+ , prev: function () {
+ if (this.sliding) return
+ return this.slide('prev')
+ }
+
+ , slide: function (type, next) {
+ var $active = this.$element.find('.item.active')
+ , $next = next || $active[type]()
+ , isCycling = this.interval
+ , direction = type == 'next' ? 'left' : 'right'
+ , fallback = type == 'next' ? 'first' : 'last'
+ , that = this
+ , e
+
+ this.sliding = true
+
+ isCycling && this.pause()
+
+ $next = $next.length ? $next : this.$element.find('.item')[fallback]()
+
+ e = $.Event('slide', {
+ relatedTarget: $next[0]
+ })
+
+ if ($next.hasClass('active')) return
+
+ if ($.support.transition && this.$element.hasClass('slide')) {
+ this.$element.trigger(e)
+ if (e.isDefaultPrevented()) return
+ $next.addClass(type)
+ $next[0].offsetWidth // force reflow
+ $active.addClass(direction)
+ $next.addClass(direction)
+ this.$element.one($.support.transition.end, function () {
+ $next.removeClass([type, direction].join(' ')).addClass('active')
+ $active.removeClass(['active', direction].join(' '))
+ that.sliding = false
+ setTimeout(function () { that.$element.trigger('slid') }, 0)
+ })
+ } else {
+ this.$element.trigger(e)
+ if (e.isDefaultPrevented()) return
+ $active.removeClass('active')
+ $next.addClass('active')
+ this.sliding = false
+ this.$element.trigger('slid')
+ }
+
+ isCycling && this.cycle()
+
+ return this
+ }
+
+ }
+
+
+ /* CAROUSEL PLUGIN DEFINITION
+ * ========================== */
+
+ var old = $.fn.carousel
+
+ $.fn.carousel = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('carousel')
+ , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option)
+ , action = typeof option == 'string' ? option : options.slide
+ if (!data) $this.data('carousel', (data = new Carousel(this, options)))
+ if (typeof option == 'number') data.to(option)
+ else if (action) data[action]()
+ else if (options.interval) data.cycle()
+ })
+ }
+
+ $.fn.carousel.defaults = {
+ interval: 5000
+ , pause: 'hover'
+ }
+
+ $.fn.carousel.Constructor = Carousel
+
+
+ /* CAROUSEL NO CONFLICT
+ * ==================== */
+
+ $.fn.carousel.noConflict = function () {
+ $.fn.carousel = old
+ return this
+ }
+
+ /* CAROUSEL DATA-API
+ * ================= */
+
+ $(document).on('click.carousel.data-api', '[data-slide]', function (e) {
+ var $this = $(this), href
+ , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
+ , options = $.extend({}, $target.data(), $this.data())
+ $target.carousel(options)
+ e.preventDefault()
+ })
+
+}(window.jQuery);/* =============================================================
+ * bootstrap-collapse.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#collapse
+ * =============================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================ */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* COLLAPSE PUBLIC CLASS DEFINITION
+ * ================================ */
+
+ var Collapse = function (element, options) {
+ this.$element = $(element)
+ this.options = $.extend({}, $.fn.collapse.defaults, options)
+
+ if (this.options.parent) {
+ this.$parent = $(this.options.parent)
+ }
+
+ this.options.toggle && this.toggle()
+ }
+
+ Collapse.prototype = {
+
+ constructor: Collapse
+
+ , dimension: function () {
+ var hasWidth = this.$element.hasClass('width')
+ return hasWidth ? 'width' : 'height'
+ }
+
+ , show: function () {
+ var dimension
+ , scroll
+ , actives
+ , hasData
+
+ if (this.transitioning) return
+
+ dimension = this.dimension()
+ scroll = $.camelCase(['scroll', dimension].join('-'))
+ actives = this.$parent && this.$parent.find('> .accordion-group > .in')
+
+ if (actives && actives.length) {
+ hasData = actives.data('collapse')
+ if (hasData && hasData.transitioning) return
+ actives.collapse('hide')
+ hasData || actives.data('collapse', null)
+ }
+
+ this.$element[dimension](0)
+ this.transition('addClass', $.Event('show'), 'shown')
+ $.support.transition && this.$element[dimension](this.$element[0][scroll])
+ }
+
+ , hide: function () {
+ var dimension
+ if (this.transitioning) return
+ dimension = this.dimension()
+ this.reset(this.$element[dimension]())
+ this.transition('removeClass', $.Event('hide'), 'hidden')
+ this.$element[dimension](0)
+ }
+
+ , reset: function (size) {
+ var dimension = this.dimension()
+
+ this.$element
+ .removeClass('collapse')
+ [dimension](size || 'auto')
+ [0].offsetWidth
+
+ this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')
+
+ return this
+ }
+
+ , transition: function (method, startEvent, completeEvent) {
+ var that = this
+ , complete = function () {
+ if (startEvent.type == 'show') that.reset()
+ that.transitioning = 0
+ that.$element.trigger(completeEvent)
+ // for orbit
+ setTimeout(mainTablePosition,150);
+ }
+
+ this.$element.trigger(startEvent)
+
+ if (startEvent.isDefaultPrevented()) return
+
+ this.transitioning = 1
+
+ this.$element[method]('in')
+
+ $.support.transition && this.$element.hasClass('collapse') ?
+ this.$element.one($.support.transition.end, complete) :
+ complete()
+ }
+
+ , toggle: function () {
+ this[this.$element.hasClass('in') ? 'hide' : 'show']()
+ }
+
+ }
+
+
+ /* COLLAPSE PLUGIN DEFINITION
+ * ========================== */
+
+ var old = $.fn.collapse
+
+ $.fn.collapse = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('collapse')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('collapse', (data = new Collapse(this, options)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.collapse.defaults = {
+ toggle: true
+ }
+
+ $.fn.collapse.Constructor = Collapse
+
+
+ /* COLLAPSE NO CONFLICT
+ * ==================== */
+
+ $.fn.collapse.noConflict = function () {
+ $.fn.collapse = old
+ return this
+ }
+
+
+ /* COLLAPSE DATA-API
+ * ================= */
+
+ $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
+ var $this = $(this), href
+ , target = $this.attr('data-target')
+ || e.preventDefault()
+ || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
+ , option = $(target).data('collapse') ? 'toggle' : $this.data()
+ $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
+ $(target).collapse(option)
+ // for orbit
+ $this.parents('li').siblings().removeClass('active');
+ $this.parents('li').toggleClass('active');
+ })
+
+}(window.jQuery);/* ============================================================
+ * bootstrap-dropdown.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#dropdowns
+ * ============================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================ */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* DROPDOWN CLASS DEFINITION
+ * ========================= */
+
+ var toggle = '[data-toggle=dropdown]'
+ , Dropdown = function (element) {
+ var $el = $(element).on('click.dropdown.data-api', this.toggle)
+ $('html').on('click.dropdown.data-api', function () {
+ $el.parent().removeClass('open')
+ })
+ }
+
+ Dropdown.prototype = {
+
+ constructor: Dropdown
+
+ , toggle: function (e) {
+ var $this = $(this)
+ , $parent
+ , isActive
+
+ if ($this.is('.disabled, :disabled')) return
+
+ $parent = getParent($this)
+
+ isActive = $parent.hasClass('open')
+
+ clearMenus()
+
+ if (!isActive) {
+ $parent.toggleClass('open')
+ }
+
+ $this.focus()
+
+ return false
+ }
+
+ , keydown: function (e) {
+ var $this
+ , $items
+ , $active
+ , $parent
+ , isActive
+ , index
+
+ if (!/(38|40|27)/.test(e.keyCode)) return
+
+ $this = $(this)
+
+ e.preventDefault()
+ e.stopPropagation()
+
+ if ($this.is('.disabled, :disabled')) return
+
+ $parent = getParent($this)
+
+ isActive = $parent.hasClass('open')
+
+ if (!isActive || (isActive && e.keyCode == 27)) return $this.click()
+
+ $items = $('[role=menu] li:not(.divider):visible a', $parent)
+
+ if (!$items.length) return
+
+ index = $items.index($items.filter(':focus'))
+
+ if (e.keyCode == 38 && index > 0) index-- // up
+ if (e.keyCode == 40 && index < $items.length - 1) index++ // down
+ if (!~index) index = 0
+
+ $items
+ .eq(index)
+ .focus()
+ }
+
+ }
+
+ function clearMenus() {
+ $(toggle).each(function () {
+ getParent($(this)).removeClass('open')
+ })
+ }
+
+ function getParent($this) {
+ var selector = $this.attr('data-target')
+ , $parent
+
+ if (!selector) {
+ selector = $this.attr('href')
+ selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
+ }
+
+ $parent = $(selector)
+ $parent.length || ($parent = $this.parent())
+
+ return $parent
+ }
+
+
+ /* DROPDOWN PLUGIN DEFINITION
+ * ========================== */
+
+ var old = $.fn.dropdown
+
+ $.fn.dropdown = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('dropdown')
+ if (!data) $this.data('dropdown', (data = new Dropdown(this)))
+ if (typeof option == 'string') data[option].call($this)
+ })
+ }
+
+ $.fn.dropdown.Constructor = Dropdown
+
+
+ /* DROPDOWN NO CONFLICT
+ * ==================== */
+
+ $.fn.dropdown.noConflict = function () {
+ $.fn.dropdown = old
+ return this
+ }
+
+
+ /* APPLY TO STANDARD DROPDOWN ELEMENTS
+ * =================================== */
+
+ $(document)
+ .on('click.dropdown.data-api touchstart.dropdown.data-api', clearMenus)
+ .on('click.dropdown touchstart.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
+ .on('touchstart.dropdown.data-api', '.dropdown-menu', function (e) { e.stopPropagation() })
+ .on('click.dropdown.data-api touchstart.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
+ .on('keydown.dropdown.data-api touchstart.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
+
+}(window.jQuery);/* =========================================================
+ * bootstrap-modal.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#modals
+ * =========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================= */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* MODAL CLASS DEFINITION
+ * ====================== */
+
+ var Modal = function (element, options) {
+ this.options = options
+ this.$element = $(element)
+ .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
+ this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
+ }
+
+ Modal.prototype = {
+
+ constructor: Modal
+
+ , toggle: function () {
+ return this[!this.isShown ? 'show' : 'hide']()
+ }
+
+ , show: function () {
+ var that = this
+ , e = $.Event('show')
+
+ this.$element.trigger(e)
+
+ if (this.isShown || e.isDefaultPrevented()) return
+
+ this.isShown = true
+
+ this.escape()
+
+ this.backdrop(function () {
+ var transition = $.support.transition && that.$element.hasClass('fade')
+
+ if (!that.$element.parent().length) {
+ that.$element.appendTo(document.body) //don't move modals dom position
+ }
+
+ that.$element
+ .show()
+
+ if (transition) {
+ that.$element[0].offsetWidth // force reflow
+ }
+
+ that.$element
+ .addClass('in')
+ .attr('aria-hidden', false)
+
+ that.enforceFocus()
+
+ transition ?
+ that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) :
+ that.$element.focus().trigger('shown')
+
+ })
+ }
+
+ , hide: function (e) {
+ e && e.preventDefault()
+
+ var that = this
+
+ e = $.Event('hide')
+
+ this.$element.trigger(e)
+
+ if (!this.isShown || e.isDefaultPrevented()) return
+
+ this.isShown = false
+
+ this.escape()
+
+ $(document).off('focusin.modal')
+
+ this.$element
+ .removeClass('in')
+ .attr('aria-hidden', true)
+
+ $.support.transition && this.$element.hasClass('fade') ?
+ this.hideWithTransition() :
+ this.hideModal()
+ }
+
+ , enforceFocus: function () {
+ var that = this
+ $(document).on('focusin.modal', function (e) {
+ if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
+ that.$element.focus()
+ }
+ })
+ }
+
+ , escape: function () {
+ var that = this
+ if (this.isShown && this.options.keyboard) {
+ this.$element.on('keyup.dismiss.modal', function ( e ) {
+ e.which == 27 && that.hide()
+ })
+ } else if (!this.isShown) {
+ this.$element.off('keyup.dismiss.modal')
+ }
+ }
+
+ , hideWithTransition: function () {
+ var that = this
+ , timeout = setTimeout(function () {
+ that.$element.off($.support.transition.end)
+ that.hideModal()
+ }, 500)
+
+ this.$element.one($.support.transition.end, function () {
+ clearTimeout(timeout)
+ that.hideModal()
+ })
+ }
+
+ , hideModal: function (that) {
+ this.$element
+ .hide()
+ .trigger('hidden')
+
+ this.backdrop()
+ }
+
+ , removeBackdrop: function () {
+ this.$backdrop.remove()
+ this.$backdrop = null
+ }
+
+ , backdrop: function (callback) {
+ var that = this
+ , animate = this.$element.hasClass('fade') ? 'fade' : ''
+
+ if (this.isShown && this.options.backdrop) {
+ var doAnimate = $.support.transition && animate
+
+ this.$backdrop = $('
')
+ .appendTo(document.body)
+
+ this.$backdrop.click(
+ this.options.backdrop == 'static' ?
+ $.proxy(this.$element[0].focus, this.$element[0])
+ : $.proxy(this.hide, this)
+ )
+
+ if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
+
+ this.$backdrop.addClass('in')
+
+ doAnimate ?
+ this.$backdrop.one($.support.transition.end, callback) :
+ callback()
+
+ } else if (!this.isShown && this.$backdrop) {
+ this.$backdrop.removeClass('in')
+
+ $.support.transition && this.$element.hasClass('fade')?
+ this.$backdrop.one($.support.transition.end, $.proxy(this.removeBackdrop, this)) :
+ this.removeBackdrop()
+
+ } else if (callback) {
+ callback()
+ }
+ }
+ }
+
+
+ /* MODAL PLUGIN DEFINITION
+ * ======================= */
+
+ var old = $.fn.modal
+
+ $.fn.modal = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('modal')
+ , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
+ if (!data) $this.data('modal', (data = new Modal(this, options)))
+ if (typeof option == 'string') data[option]()
+ else if (options.show) data.show()
+ })
+ }
+
+ $.fn.modal.defaults = {
+ backdrop: true
+ , keyboard: true
+ , show: true
+ }
+
+ $.fn.modal.Constructor = Modal
+
+
+ /* MODAL NO CONFLICT
+ * ================= */
+
+ $.fn.modal.noConflict = function () {
+ $.fn.modal = old
+ return this
+ }
+
+
+ /* MODAL DATA-API
+ * ============== */
+
+ $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
+ var $this = $(this)
+ , href = $this.attr('href')
+ , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
+ , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())
+
+ e.preventDefault()
+
+ $target
+ .modal(option)
+ .one('hide', function () {
+ $this.focus()
+ })
+ })
+
+}(window.jQuery);
+/* ===========================================================
+ * bootstrap-tooltip.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#tooltips
+ * Inspired by the original jQuery.tipsy by Jason Frame
+ * ===========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* TOOLTIP PUBLIC CLASS DEFINITION
+ * =============================== */
+
+ var Tooltip = function (element, options) {
+ this.init('tooltip', element, options)
+ }
+
+ Tooltip.prototype = {
+
+ constructor: Tooltip
+
+ , init: function (type, element, options) {
+ var eventIn
+ , eventOut
+
+ this.type = type
+ this.$element = $(element)
+ this.options = this.getOptions(options)
+ this.enabled = true
+
+ if (this.options.trigger == 'click') {
+ this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
+ } else if (this.options.trigger != 'manual') {
+ eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
+ eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
+ this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
+ this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
+ }
+
+ this.options.selector ?
+ (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
+ this.fixTitle()
+ }
+
+ , getOptions: function (options) {
+ options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
+
+ if (options.delay && typeof options.delay == 'number') {
+ options.delay = {
+ show: options.delay
+ , hide: options.delay
+ }
+ }
+
+ return options
+ }
+
+ , enter: function (e) {
+ var self = $(e.currentTarget)[this.type](this._options).data(this.type)
+
+ if (!self.options.delay || !self.options.delay.show) return self.show()
+
+ clearTimeout(this.timeout)
+ self.hoverState = 'in'
+ this.timeout = setTimeout(function() {
+ if (self.hoverState == 'in') self.show()
+ }, self.options.delay.show)
+ }
+
+ , leave: function (e) {
+ var self = $(e.currentTarget)[this.type](this._options).data(this.type)
+
+ if (this.timeout) clearTimeout(this.timeout)
+ if (!self.options.delay || !self.options.delay.hide) return self.hide()
+
+ self.hoverState = 'out'
+ this.timeout = setTimeout(function() {
+ if (self.hoverState == 'out') self.hide()
+ }, self.options.delay.hide)
+ }
+
+ , show: function () {
+ var $tip
+ , inside
+ , pos
+ , actualWidth
+ , actualHeight
+ , placement
+ , tp
+
+ if (this.hasContent() && this.enabled) {
+ $tip = this.tip()
+ this.setContent()
+
+ if (this.options.animation) {
+ $tip.addClass('fade')
+ }
+
+ placement = typeof this.options.placement == 'function' ?
+ this.options.placement.call(this, $tip[0], this.$element[0]) :
+ this.options.placement
+
+ inside = /in/.test(placement)
+
+ $tip
+ .detach()
+ .css({ top: 0, left: 0, display: 'block' })
+ .insertAfter(this.$element)
+
+ pos = this.getPosition(inside)
+
+ actualWidth = $tip[0].offsetWidth
+ actualHeight = $tip[0].offsetHeight
+
+ switch (inside ? placement.split(' ')[1] : placement) {
+ case 'bottom':
+ tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
+ break
+ case 'top':
+ tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
+ break
+ case 'left':
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
+ break
+ case 'right':
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
+ break
+ }
+
+ $tip
+ .offset(tp)
+ .addClass(placement)
+ .addClass('in')
+ }
+ }
+
+ , setContent: function () {
+ var $tip = this.tip()
+ , title = this.getTitle()
+
+ $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
+ $tip.removeClass('fade in top bottom left right')
+ }
+
+ , hide: function () {
+ var that = this
+ , $tip = this.tip()
+
+ $tip.removeClass('in')
+
+ function removeWithAnimation() {
+ var timeout = setTimeout(function () {
+ $tip.off($.support.transition.end).detach()
+ }, 500)
+
+ $tip.one($.support.transition.end, function () {
+ clearTimeout(timeout)
+ $tip.detach()
+ })
+ }
+
+ $.support.transition && this.$tip.hasClass('fade') ?
+ removeWithAnimation() :
+ $tip.detach()
+
+ return this
+ }
+
+ , fixTitle: function () {
+ var $e = this.$element
+ if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
+ $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
+ }
+ }
+
+ , hasContent: function () {
+ return this.getTitle()
+ }
+
+ , getPosition: function (inside) {
+ return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
+ width: this.$element[0].offsetWidth
+ , height: this.$element[0].offsetHeight
+ })
+ }
+
+ , getTitle: function () {
+ var title
+ , $e = this.$element
+ , o = this.options
+
+ title = $e.attr('data-original-title')
+ || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
+
+ return title
+ }
+
+ , tip: function () {
+ return this.$tip = this.$tip || $(this.options.template)
+ }
+
+ , validate: function () {
+ if (!this.$element[0].parentNode) {
+ this.hide()
+ this.$element = null
+ this.options = null
+ }
+ }
+
+ , enable: function () {
+ this.enabled = true
+ }
+
+ , disable: function () {
+ this.enabled = false
+ }
+
+ , toggleEnabled: function () {
+ this.enabled = !this.enabled
+ }
+
+ , toggle: function (e) {
+ var self = $(e.currentTarget)[this.type](this._options).data(this.type)
+ self[self.tip().hasClass('in') ? 'hide' : 'show']()
+ }
+
+ , destroy: function () {
+ this.hide().$element.off('.' + this.type).removeData(this.type)
+ }
+
+ }
+
+
+ /* TOOLTIP PLUGIN DEFINITION
+ * ========================= */
+
+ var old = $.fn.tooltip
+
+ $.fn.tooltip = function ( option ) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('tooltip')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.tooltip.Constructor = Tooltip
+
+ $.fn.tooltip.defaults = {
+ animation: true
+ , placement: 'top'
+ , selector: false
+ , template: ''
+ , trigger: 'hover'
+ , title: ''
+ , delay: 0
+ , html: false
+ }
+
+
+ /* TOOLTIP NO CONFLICT
+ * =================== */
+
+ $.fn.tooltip.noConflict = function () {
+ $.fn.tooltip = old
+ return this
+ }
+
+}(window.jQuery);/* ===========================================================
+ * bootstrap-popover.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#popovers
+ * ===========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * =========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* POPOVER PUBLIC CLASS DEFINITION
+ * =============================== */
+
+ var Popover = function (element, options) {
+ this.init('popover', element, options)
+ }
+
+
+ /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
+ ========================================== */
+
+ Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
+
+ constructor: Popover
+
+ , setContent: function () {
+ var $tip = this.tip()
+ , title = this.getTitle()
+ , content = this.getContent()
+
+ $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
+ $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
+
+ $tip.removeClass('fade top bottom left right in')
+ }
+
+ , hasContent: function () {
+ return this.getTitle() || this.getContent()
+ }
+
+ , getContent: function () {
+ var content
+ , $e = this.$element
+ , o = this.options
+
+ content = $e.attr('data-content')
+ || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
+
+ return content
+ }
+
+ , tip: function () {
+ if (!this.$tip) {
+ this.$tip = $(this.options.template)
+ }
+ return this.$tip
+ }
+
+ , destroy: function () {
+ this.hide().$element.off('.' + this.type).removeData(this.type)
+ }
+
+ })
+
+
+ /* POPOVER PLUGIN DEFINITION
+ * ======================= */
+
+ var old = $.fn.popover
+
+ $.fn.popover = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('popover')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('popover', (data = new Popover(this, options)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.popover.Constructor = Popover
+
+ $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
+ placement: 'right'
+ , trigger: 'click'
+ , content: ''
+ , template: ''
+ })
+
+
+ /* POPOVER NO CONFLICT
+ * =================== */
+
+ $.fn.popover.noConflict = function () {
+ $.fn.popover = old
+ return this
+ }
+
+}(window.jQuery);/* =============================================================
+ * bootstrap-scrollspy.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#scrollspy
+ * =============================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* SCROLLSPY CLASS DEFINITION
+ * ========================== */
+
+ function ScrollSpy(element, options) {
+ var process = $.proxy(this.process, this)
+ , $element = $(element).is('body') ? $(window) : $(element)
+ , href
+ this.options = $.extend({}, $.fn.scrollspy.defaults, options)
+ this.$scrollElement = $element.on('scroll.scroll-spy.data-api', process)
+ this.selector = (this.options.target
+ || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
+ || '') + ' .nav li > a'
+ this.$body = $('body')
+ this.refresh()
+ this.process()
+ }
+
+ ScrollSpy.prototype = {
+
+ constructor: ScrollSpy
+
+ , refresh: function () {
+ var self = this
+ , $targets
+
+ this.offsets = $([])
+ this.targets = $([])
+
+ $targets = this.$body
+ .find(this.selector)
+ .map(function () {
+ var $el = $(this)
+ , href = $el.data('target') || $el.attr('href')
+ , $href = /^#\w/.test(href) && $(href)
+ return ( $href
+ && $href.length
+ && [[ $href.position().top + self.$scrollElement.scrollTop(), href ]] ) || null
+ })
+ .sort(function (a, b) { return a[0] - b[0] })
+ .each(function () {
+ self.offsets.push(this[0])
+ self.targets.push(this[1])
+ })
+ }
+
+ , process: function () {
+ var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
+ , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
+ , maxScroll = scrollHeight - this.$scrollElement.height()
+ , offsets = this.offsets
+ , targets = this.targets
+ , activeTarget = this.activeTarget
+ , i
+
+ if (scrollTop >= maxScroll) {
+ return activeTarget != (i = targets.last()[0])
+ && this.activate ( i )
+ }
+
+ for (i = offsets.length; i--;) {
+ activeTarget != targets[i]
+ && scrollTop >= offsets[i]
+ && (!offsets[i + 1] || scrollTop <= offsets[i + 1])
+ && this.activate( targets[i] )
+ }
+ }
+
+ , activate: function (target) {
+ var active
+ , selector
+
+ this.activeTarget = target
+
+ $(this.selector)
+ .parent('.active')
+ .removeClass('active')
+
+ selector = this.selector
+ + '[data-target="' + target + '"],'
+ + this.selector + '[href="' + target + '"]'
+
+ active = $(selector)
+ .parent('li')
+ .addClass('active')
+
+ if (active.parent('.dropdown-menu').length) {
+ active = active.closest('li.dropdown').addClass('active')
+ }
+
+ active.trigger('activate')
+ }
+
+ }
+
+
+ /* SCROLLSPY PLUGIN DEFINITION
+ * =========================== */
+
+ var old = $.fn.scrollspy
+
+ $.fn.scrollspy = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('scrollspy')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.scrollspy.Constructor = ScrollSpy
+
+ $.fn.scrollspy.defaults = {
+ offset: 10
+ }
+
+
+ /* SCROLLSPY NO CONFLICT
+ * ===================== */
+
+ $.fn.scrollspy.noConflict = function () {
+ $.fn.scrollspy = old
+ return this
+ }
+
+
+ /* SCROLLSPY DATA-API
+ * ================== */
+
+ $(window).on('load', function () {
+ $('[data-spy="scroll"]').each(function () {
+ var $spy = $(this)
+ $spy.scrollspy($spy.data())
+ })
+ })
+
+}(window.jQuery);/* ========================================================
+ * bootstrap-tab.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#tabs
+ * ========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ======================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* TAB CLASS DEFINITION
+ * ==================== */
+
+ var Tab = function (element) {
+ this.element = $(element)
+ }
+
+ Tab.prototype = {
+
+ constructor: Tab
+
+ , show: function () {
+ var $this = this.element
+ , $ul = $this.closest('ul:not(.dropdown-menu)')
+ , selector = $this.attr('data-target')
+ , previous
+ , $target
+ , e
+
+ if (!selector) {
+ selector = $this.attr('href')
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
+ }
+
+ if ( $this.parent('li').hasClass('active') ) return
+
+ previous = $ul.find('.active:last a')[0]
+
+ e = $.Event('show', {
+ relatedTarget: previous
+ })
+
+ $this.trigger(e)
+
+ if (e.isDefaultPrevented()) return
+
+ $target = $(selector)
+
+ this.activate($this.parent('li'), $ul)
+ this.activate($target, $target.parent(), function () {
+ $this.trigger({
+ type: 'shown'
+ , relatedTarget: previous
+ })
+ })
+ }
+
+ , activate: function ( element, container, callback) {
+ var $active = container.find('> .active')
+ , transition = callback
+ && $.support.transition
+ && $active.hasClass('fade')
+
+ function next() {
+ $active
+ .removeClass('active')
+ .find('> .dropdown-menu > .active')
+ .removeClass('active')
+
+ element.addClass('active')
+
+ if (transition) {
+ element[0].offsetWidth // reflow for transition
+ element.addClass('in')
+ } else {
+ element.removeClass('fade')
+ }
+
+ if ( element.parent('.dropdown-menu') ) {
+ element.closest('li.dropdown').addClass('active')
+ }
+
+ callback && callback()
+ }
+
+ transition ?
+ $active.one($.support.transition.end, next) :
+ next()
+
+ $active.removeClass('in')
+ }
+ }
+
+
+ /* TAB PLUGIN DEFINITION
+ * ===================== */
+
+ var old = $.fn.tab
+
+ $.fn.tab = function ( option ) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('tab')
+ if (!data) $this.data('tab', (data = new Tab(this)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.tab.Constructor = Tab
+
+
+ /* TAB NO CONFLICT
+ * =============== */
+
+ $.fn.tab.noConflict = function () {
+ $.fn.tab = old
+ return this
+ }
+
+
+ /* TAB DATA-API
+ * ============ */
+
+ $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
+ e.preventDefault()
+ $(this).tab('show')
+ })
+
+}(window.jQuery);/* =============================================================
+ * bootstrap-typeahead.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#typeahead
+ * =============================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============================================================ */
+
+
+!function($){
+
+ "use strict"; // jshint ;_;
+
+
+ /* TYPEAHEAD PUBLIC CLASS DEFINITION
+ * ================================= */
+
+ var Typeahead = function (element, options) {
+ this.$element = $(element)
+ this.options = $.extend({}, $.fn.typeahead.defaults, options)
+ this.matcher = this.options.matcher || this.matcher
+ this.sorter = this.options.sorter || this.sorter
+ this.highlighter = this.options.highlighter || this.highlighter
+ this.updater = this.options.updater || this.updater
+ this.source = this.options.source
+ this.$menu = $(this.options.menu)
+ this.shown = false
+ this.listen()
+ }
+
+ Typeahead.prototype = {
+
+ constructor: Typeahead
+
+ , select: function () {
+ var val = this.$menu.find('.active').attr('data-value')
+ this.$element
+ .val(this.updater(val))
+ .change()
+ return this.hide()
+ }
+
+ , updater: function (item) {
+ return item
+ }
+
+ , show: function () {
+ var pos = $.extend({}, this.$element.position(), {
+ height: this.$element[0].offsetHeight
+ })
+
+ this.$menu
+ .insertAfter(this.$element)
+ .css({
+ top: pos.top + pos.height
+ , left: pos.left
+ })
+ .show()
+
+ this.shown = true
+ return this
+ }
+
+ , hide: function () {
+ this.$menu.hide()
+ this.shown = false
+ return this
+ }
+
+ , lookup: function (event) {
+ var items
+
+ this.query = this.$element.val()
+
+ if (!this.query || this.query.length < this.options.minLength) {
+ return this.shown ? this.hide() : this
+ }
+
+ items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source
+
+ return items ? this.process(items) : this
+ }
+
+ , process: function (items) {
+ var that = this
+
+ items = $.grep(items, function (item) {
+ return that.matcher(item)
+ })
+
+ items = this.sorter(items)
+
+ if (!items.length) {
+ return this.shown ? this.hide() : this
+ }
+
+ return this.render(items.slice(0, this.options.items)).show()
+ }
+
+ , matcher: function (item) {
+ return ~item.toLowerCase().indexOf(this.query.toLowerCase())
+ }
+
+ , sorter: function (items) {
+ var beginswith = []
+ , caseSensitive = []
+ , caseInsensitive = []
+ , item
+
+ while (item = items.shift()) {
+ if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
+ else if (~item.indexOf(this.query)) caseSensitive.push(item)
+ else caseInsensitive.push(item)
+ }
+
+ return beginswith.concat(caseSensitive, caseInsensitive)
+ }
+
+ , highlighter: function (item) {
+ var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
+ return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
+ return '' + match + ''
+ })
+ }
+
+ , render: function (items) {
+ var that = this
+
+ items = $(items).map(function (i, item) {
+ i = $(that.options.item).attr('data-value', item)
+ i.find('a').html(that.highlighter(item))
+ return i[0]
+ })
+
+ items.first().addClass('active')
+ this.$menu.html(items)
+ return this
+ }
+
+ , next: function (event) {
+ var active = this.$menu.find('.active').removeClass('active')
+ , 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')
+ , 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('keypress', $.proxy(this.keypress, this))
+ .on('keyup', $.proxy(this.keyup, this))
+
+ if (this.eventSupported('keydown')) {
+ this.$element.on('keydown', $.proxy(this.keydown, this))
+ }
+
+ this.$menu
+ .on('click', $.proxy(this.click, this))
+ .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
+ }
+
+ , eventSupported: function(eventName) {
+ var isSupported = eventName in this.$element
+ if (!isSupported) {
+ this.$element.setAttribute(eventName, 'return;')
+ isSupported = typeof this.$element[eventName] === 'function'
+ }
+ return isSupported
+ }
+
+ , move: function (e) {
+ if (!this.shown) return
+
+ switch(e.keyCode) {
+ case 9: // tab
+ case 13: // enter
+ case 27: // escape
+ e.preventDefault()
+ break
+
+ case 38: // up arrow
+ e.preventDefault()
+ this.prev()
+ break
+
+ case 40: // down arrow
+ e.preventDefault()
+ this.next()
+ break
+ }
+
+ e.stopPropagation()
+ }
+
+ , keydown: function (e) {
+ this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27])
+ this.move(e)
+ }
+
+ , keypress: function (e) {
+ if (this.suppressKeyPressRepeat) return
+ this.move(e)
+ }
+
+ , keyup: function (e) {
+ switch(e.keyCode) {
+ case 40: // down arrow
+ case 38: // up arrow
+ case 16: // shift
+ case 17: // ctrl
+ case 18: // alt
+ break
+
+ case 9: // tab
+ case 13: // enter
+ if (!this.shown) return
+ this.select()
+ break
+
+ case 27: // escape
+ if (!this.shown) return
+ this.hide()
+ break
+
+ default:
+ this.lookup()
+ }
+
+ e.stopPropagation()
+ e.preventDefault()
+ }
+
+ , blur: function (e) {
+ var that = this
+ setTimeout(function () { 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')
+ }
+
+ }
+
+
+ /* TYPEAHEAD PLUGIN DEFINITION
+ * =========================== */
+
+ var old = $.fn.typeahead
+
+ $.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 = {
+ source: []
+ , items: 8
+ , menu: ''
+ , item: ''
+ , minLength: 1
+ }
+
+ $.fn.typeahead.Constructor = Typeahead
+
+
+ /* TYPEAHEAD NO CONFLICT
+ * =================== */
+
+ $.fn.typeahead.noConflict = function () {
+ $.fn.typeahead = old
+ return this
+ }
+
+
+ /* TYPEAHEAD DATA-API
+ * ================== */
+
+ $(document).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);
+/* ==========================================================
+ * bootstrap-affix.js v2.2.2
+ * http://twitter.github.com/bootstrap/javascript.html#affix
+ * ==========================================================
+ * Copyright 2012 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ========================================================== */
+
+
+!function ($) {
+
+ "use strict"; // jshint ;_;
+
+
+ /* AFFIX CLASS DEFINITION
+ * ====================== */
+
+ var Affix = function (element, options) {
+ this.options = $.extend({}, $.fn.affix.defaults, options)
+ this.$window = $(window)
+ .on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
+ .on('click.affix.data-api', $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this))
+ this.$element = $(element)
+ this.checkPosition()
+ }
+
+ Affix.prototype.checkPosition = function () {
+ if (!this.$element.is(':visible')) return
+
+ var scrollHeight = $(document).height()
+ , scrollTop = this.$window.scrollTop()
+ , position = this.$element.offset()
+ , offset = this.options.offset
+ , offsetBottom = offset.bottom
+ , offsetTop = offset.top
+ , reset = 'affix affix-top affix-bottom'
+ , affix
+
+ if (typeof offset != 'object') offsetBottom = offsetTop = offset
+ if (typeof offsetTop == 'function') offsetTop = offset.top()
+ if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
+
+ affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ?
+ false : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ?
+ 'bottom' : offsetTop != null && scrollTop <= offsetTop ?
+ 'top' : false
+
+ if (this.affixed === affix) return
+
+ this.affixed = affix
+ this.unpin = affix == 'bottom' ? position.top - scrollTop : null
+
+ this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
+ }
+
+
+ /* AFFIX PLUGIN DEFINITION
+ * ======================= */
+
+ var old = $.fn.affix
+
+ $.fn.affix = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('affix')
+ , options = typeof option == 'object' && option
+ if (!data) $this.data('affix', (data = new Affix(this, options)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.affix.Constructor = Affix
+
+ $.fn.affix.defaults = {
+ offset: 0
+ }
+
+
+ /* AFFIX NO CONFLICT
+ * ================= */
+
+ $.fn.affix.noConflict = function () {
+ $.fn.affix = old
+ return this
+ }
+
+
+ /* AFFIX DATA-API
+ * ============== */
+
+ $(window).on('load', function () {
+ $('[data-spy="affix"]').each(function () {
+ var $spy = $(this)
+ , data = $spy.data()
+
+ data.offset = data.offset || {}
+
+ data.offsetBottom && (data.offset.bottom = data.offsetBottom)
+ data.offsetTop && (data.offset.top = data.offsetTop)
+
+ $spy.affix(data)
+ })
+ })
+
+
+}(window.jQuery);
\ No newline at end of file
diff --git a/app/assets/javascripts/desktop/desktop.js b/app/assets/javascripts/desktop/desktop.js
new file mode 100644
index 00000000..2566a05e
--- /dev/null
+++ b/app/assets/javascripts/desktop/desktop.js
@@ -0,0 +1,20 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require jquery-ui
+//= require desktop/jquery.form
+//= require desktop/jquery.tinyscrollbar
+//= require desktop/jquery.miniColors.min
+//= require desktop/bootstrap
+//= require desktop/orbitdesktopAPI
+//= require desktop/orbitTimeline
+//= require desktop/orbitdesktop
+//= require desktop/jquery.gridster
+//= require desktop/books_pages
+//= require select2
+//= require orbit_js_1.0.1-front-end
diff --git a/app/assets/javascripts/desktop/jquery.form.js b/app/assets/javascripts/desktop/jquery.form.js
new file mode 100644
index 00000000..7f11d05c
--- /dev/null
+++ b/app/assets/javascripts/desktop/jquery.form.js
@@ -0,0 +1,980 @@
+/*!
+ * jQuery Form Plugin
+ * version: 2.94 (13-DEC-2011)
+ * @requires jQuery v1.3.2 or later
+ *
+ * Examples and documentation at: http://malsup.com/jquery/form/
+ * Dual licensed under the MIT and GPL licenses:
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.gnu.org/licenses/gpl.html
+ */
+;(function($) {
+
+/*
+ Usage Note:
+ -----------
+ Do not use both ajaxSubmit and ajaxForm on the same form. These
+ functions are intended to be exclusive. Use ajaxSubmit if you want
+ to bind your own submit handler to the form. For example,
+
+ $(document).ready(function() {
+ $('#myForm').bind('submit', function(e) {
+ e.preventDefault(); // <-- important
+ $(this).ajaxSubmit({
+ target: '#output'
+ });
+ });
+ });
+
+ Use ajaxForm when you want the plugin to manage all the event binding
+ for you. For example,
+
+ $(document).ready(function() {
+ $('#myForm').ajaxForm({
+ target: '#output'
+ });
+ });
+
+ When using ajaxForm, the ajaxSubmit function will be invoked for you
+ at the appropriate time.
+*/
+
+/**
+ * ajaxSubmit() provides a mechanism for immediately submitting
+ * an HTML form using AJAX.
+ */
+$.fn.ajaxSubmit = function(options) {
+ // fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
+ if (!this.length) {
+ log('ajaxSubmit: skipping submit process - no element selected');
+ return this;
+ }
+
+ var method, action, url, $form = this;
+
+ if (typeof options == 'function') {
+ options = { success: options };
+ }
+
+ method = this.attr('method');
+ action = this.attr('action');
+ url = (typeof action === 'string') ? $.trim(action) : '';
+ url = url || window.location.href || '';
+ if (url) {
+ // clean url (don't include hash vaue)
+ url = (url.match(/^([^#]+)/)||[])[1];
+ }
+
+ options = $.extend(true, {
+ url: url,
+ success: $.ajaxSettings.success,
+ type: method || 'GET',
+ iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
+ }, options);
+
+ // hook for manipulating the form data before it is extracted;
+ // convenient for use with rich editors like tinyMCE or FCKEditor
+ var veto = {};
+ this.trigger('form-pre-serialize', [this, options, veto]);
+ if (veto.veto) {
+ log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
+ return this;
+ }
+
+ // provide opportunity to alter form data before it is serialized
+ if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
+ log('ajaxSubmit: submit aborted via beforeSerialize callback');
+ return this;
+ }
+
+ var traditional = options.traditional;
+ if ( traditional === undefined ) {
+ traditional = $.ajaxSettings.traditional;
+ }
+
+ var qx,n,v,a = this.formToArray(options.semantic);
+ if (options.data) {
+ options.extraData = options.data;
+ qx = $.param(options.data, traditional);
+ }
+
+ // give pre-submit callback an opportunity to abort the submit
+ if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
+ log('ajaxSubmit: submit aborted via beforeSubmit callback');
+ return this;
+ }
+
+ // fire vetoable 'validate' event
+ this.trigger('form-submit-validate', [a, this, options, veto]);
+ if (veto.veto) {
+ log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
+ return this;
+ }
+
+ var q = $.param(a, traditional);
+ if (qx) {
+ q = ( q ? (q + '&' + qx) : qx );
+ }
+ if (options.type.toUpperCase() == 'GET') {
+ options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
+ options.data = null; // data is null for 'get'
+ }
+ else {
+ options.data = q; // data is the query string for 'post'
+ }
+
+ var callbacks = [];
+ if (options.resetForm) {
+ callbacks.push(function() { $form.resetForm(); });
+ }
+ if (options.clearForm) {
+ callbacks.push(function() { $form.clearForm(options.includeHidden); });
+ }
+
+ // perform a load on the target only if dataType is not provided
+ if (!options.dataType && options.target) {
+ var oldSuccess = options.success || function(){};
+ callbacks.push(function(data) {
+ var fn = options.replaceTarget ? 'replaceWith' : 'html';
+ $(options.target)[fn](data).each(oldSuccess, arguments);
+ });
+ }
+ else if (options.success) {
+ callbacks.push(options.success);
+ }
+
+ options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
+ var context = options.context || options; // jQuery 1.4+ supports scope context
+ for (var i=0, max=callbacks.length; i < max; i++) {
+ callbacks[i].apply(context, [data, status, xhr || $form, $form]);
+ }
+ };
+
+ // are there files to upload?
+ var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
+ var hasFileInputs = fileInputs.length > 0;
+ var mp = 'multipart/form-data';
+ var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
+
+ var fileAPI = !!(hasFileInputs && fileInputs.get(0).files && window.FormData);
+ log("fileAPI :" + fileAPI);
+ var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
+
+ // options.iframe allows user to force iframe mode
+ // 06-NOV-09: now defaulting to iframe mode if file input is detected
+ if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
+ // hack to fix Safari hang (thanks to Tim Molendijk for this)
+ // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
+ if (options.closeKeepAlive) {
+ $.get(options.closeKeepAlive, function() {
+ fileUploadIframe(a);
+ });
+ }
+ else {
+ fileUploadIframe(a);
+ }
+ }
+ else if ((hasFileInputs || multipart) && fileAPI) {
+ options.progress = options.progress || $.noop;
+ fileUploadXhr(a);
+ }
+ else {
+ $.ajax(options);
+ }
+
+ // fire 'notify' event
+ this.trigger('form-submit-notify', [this, options]);
+ return this;
+
+ // XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
+ function fileUploadXhr(a) {
+ var formdata = new FormData();
+
+ for (var i=0; i < a.length; i++) {
+ if (a[i].type == 'file')
+ continue;
+ formdata.append(a[i].name, a[i].value);
+ }
+
+ $form.find('input:file:enabled').each(function(){
+ var name = $(this).attr('name'), files = this.files;
+ if (name) {
+ for (var i=0; i < files.length; i++)
+ formdata.append(name, files[i]);
+ }
+ });
+
+ if (options.extraData) {
+ for (var k in options.extraData)
+ formdata.append(k, options.extraData[k])
+ }
+
+ options.data = null;
+
+ var s = $.extend(true, {}, $.ajaxSettings, options, {
+ contentType: false,
+ processData: false,
+ cache: false,
+ type: 'POST'
+ });
+
+ s.context = s.context || s;
+
+ s.data = null;
+ var beforeSend = s.beforeSend;
+ s.beforeSend = function(xhr, o) {
+ o.data = formdata;
+ if(xhr.upload) { // unfortunately, jQuery doesn't expose this prop (http://bugs.jquery.com/ticket/10190)
+ xhr.upload.onprogress = function(event) {
+ o.progress(event.position, event.total);
+ };
+ }
+ if(beforeSend)
+ beforeSend.call(o, xhr, options);
+ };
+ $.ajax(s);
+ }
+
+ // private function for handling file uploads (hat tip to YAHOO!)
+ function fileUploadIframe(a) {
+ var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
+ var useProp = !!$.fn.prop;
+
+ if (a) {
+ if ( useProp ) {
+ // ensure that every serialized input is still enabled
+ for (i=0; i < a.length; i++) {
+ el = $(form[a[i].name]);
+ el.prop('disabled', false);
+ }
+ } else {
+ for (i=0; i < a.length; i++) {
+ el = $(form[a[i].name]);
+ el.removeAttr('disabled');
+ }
+ };
+ }
+
+ if ($(':input[name=submit],:input[id=submit]', form).length) {
+ // if there is an input with a name or id of 'submit' then we won't be
+ // able to invoke the submit fn on the form (at least not x-browser)
+ alert('Error: Form elements must not have name or id of "submit".');
+ return;
+ }
+
+ s = $.extend(true, {}, $.ajaxSettings, options);
+ s.context = s.context || s;
+ id = 'jqFormIO' + (new Date().getTime());
+ if (s.iframeTarget) {
+ $io = $(s.iframeTarget);
+ n = $io.attr('name');
+ if (n == null)
+ $io.attr('name', id);
+ else
+ id = n;
+ }
+ else {
+ $io = $('');
+ $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
+ }
+ io = $io[0];
+
+
+ xhr = { // mock object
+ aborted: 0,
+ responseText: null,
+ responseXML: null,
+ status: 0,
+ statusText: 'n/a',
+ getAllResponseHeaders: function() {},
+ getResponseHeader: function() {},
+ setRequestHeader: function() {},
+ abort: function(status) {
+ var e = (status === 'timeout' ? 'timeout' : 'aborted');
+ log('aborting upload... ' + e);
+ this.aborted = 1;
+ $io.attr('src', s.iframeSrc); // abort op in progress
+ xhr.error = e;
+ s.error && s.error.call(s.context, xhr, e, status);
+ g && $.event.trigger("ajaxError", [xhr, s, e]);
+ s.complete && s.complete.call(s.context, xhr, e);
+ }
+ };
+
+ g = s.global;
+ // trigger ajax global events so that activity/block indicators work like normal
+ if (g && ! $.active++) {
+ $.event.trigger("ajaxStart");
+ }
+ if (g) {
+ $.event.trigger("ajaxSend", [xhr, s]);
+ }
+
+ if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
+ if (s.global) {
+ $.active--;
+ }
+ return;
+ }
+ if (xhr.aborted) {
+ return;
+ }
+
+ // add submitting element to data if we know it
+ sub = form.clk;
+ if (sub) {
+ n = sub.name;
+ if (n && !sub.disabled) {
+ s.extraData = s.extraData || {};
+ s.extraData[n] = sub.value;
+ if (sub.type == "image") {
+ s.extraData[n+'.x'] = form.clk_x;
+ s.extraData[n+'.y'] = form.clk_y;
+ }
+ }
+ }
+
+ var CLIENT_TIMEOUT_ABORT = 1;
+ var SERVER_ABORT = 2;
+
+ function getDoc(frame) {
+ var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document;
+ return doc;
+ }
+
+ // Rails CSRF hack (thanks to Yvan Barthelemy)
+ var csrf_token = $('meta[name=csrf-token]').attr('content');
+ var csrf_param = $('meta[name=csrf-param]').attr('content');
+ if (csrf_param && csrf_token) {
+ s.extraData = s.extraData || {};
+ s.extraData[csrf_param] = csrf_token;
+ }
+
+ // take a breath so that pending repaints get some cpu time before the upload starts
+ function doSubmit() {
+ // make sure form attrs are set
+ var t = $form.attr('target'), a = $form.attr('action');
+
+ // update form attrs in IE friendly way
+ form.setAttribute('target',id);
+ if (!method) {
+ form.setAttribute('method', 'POST');
+ }
+ if (a != s.url) {
+ form.setAttribute('action', s.url);
+ }
+
+ // ie borks in some cases when setting encoding
+ if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
+ $form.attr({
+ encoding: 'multipart/form-data',
+ enctype: 'multipart/form-data'
+ });
+ }
+
+ // support timout
+ if (s.timeout) {
+ timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
+ }
+
+ // look for server aborts
+ function checkState() {
+ try {
+ var state = getDoc(io).readyState;
+ log('state = ' + state);
+ if (state.toLowerCase() == 'uninitialized')
+ setTimeout(checkState,50);
+ }
+ catch(e) {
+ log('Server abort: ' , e, ' (', e.name, ')');
+ cb(SERVER_ABORT);
+ timeoutHandle && clearTimeout(timeoutHandle);
+ timeoutHandle = undefined;
+ }
+ }
+
+ // add "extra" data to form if provided in options
+ var extraInputs = [];
+ try {
+ if (s.extraData) {
+ for (var n in s.extraData) {
+ extraInputs.push(
+ $('').attr('value',s.extraData[n])
+ .appendTo(form)[0]);
+ }
+ }
+
+ if (!s.iframeTarget) {
+ // add iframe to doc and submit the form
+ $io.appendTo('body');
+ io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
+ }
+ setTimeout(checkState,15);
+ form.submit();
+ }
+ finally {
+ // reset attrs and remove "extra" input elements
+ form.setAttribute('action',a);
+ if(t) {
+ form.setAttribute('target', t);
+ } else {
+ $form.removeAttr('target');
+ }
+ $(extraInputs).remove();
+ }
+ }
+
+ if (s.forceSync) {
+ doSubmit();
+ }
+ else {
+ setTimeout(doSubmit, 10); // this lets dom updates render
+ }
+
+ var data, doc, domCheckCount = 50, callbackProcessed;
+
+ function cb(e) {
+ if (xhr.aborted || callbackProcessed) {
+ return;
+ }
+ try {
+ doc = getDoc(io);
+ }
+ catch(ex) {
+ log('cannot access response document: ', ex);
+ e = SERVER_ABORT;
+ }
+ if (e === CLIENT_TIMEOUT_ABORT && xhr) {
+ xhr.abort('timeout');
+ return;
+ }
+ else if (e == SERVER_ABORT && xhr) {
+ xhr.abort('server abort');
+ return;
+ }
+
+ if (!doc || doc.location.href == s.iframeSrc) {
+ // response not received yet
+ if (!timedOut)
+ return;
+ }
+ io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
+
+ var status = 'success', errMsg;
+ try {
+ if (timedOut) {
+ throw 'timeout';
+ }
+
+ var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
+ log('isXml='+isXml);
+ if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
+ if (--domCheckCount) {
+ // in some browsers (Opera) the iframe DOM is not always traversable when
+ // the onload callback fires, so we loop a bit to accommodate
+ log('requeing onLoad callback, DOM not available');
+ setTimeout(cb, 250);
+ return;
+ }
+ // let this fall through because server response could be an empty document
+ //log('Could not access iframe DOM after mutiple tries.');
+ //throw 'DOMException: not available';
+ }
+
+ //log('response detected');
+ var docRoot = doc.body ? doc.body : doc.documentElement;
+ xhr.responseText = docRoot ? docRoot.innerHTML : null;
+ xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
+ if (isXml)
+ s.dataType = 'xml';
+ xhr.getResponseHeader = function(header){
+ var headers = {'content-type': s.dataType};
+ return headers[header];
+ };
+ // support for XHR 'status' & 'statusText' emulation :
+ if (docRoot) {
+ xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
+ xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
+ }
+
+ var dt = (s.dataType || '').toLowerCase();
+ var scr = /(json|script|text)/.test(dt);
+ if (scr || s.textarea) {
+ // see if user embedded response in textarea
+ var ta = doc.getElementsByTagName('textarea')[0];
+ if (ta) {
+ xhr.responseText = ta.value;
+ // support for XHR 'status' & 'statusText' emulation :
+ xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
+ xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
+ }
+ else if (scr) {
+ // account for browsers injecting pre around json response
+ var pre = doc.getElementsByTagName('pre')[0];
+ var b = doc.getElementsByTagName('body')[0];
+ if (pre) {
+ xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
+ }
+ else if (b) {
+ xhr.responseText = b.textContent ? b.textContent : b.innerText;
+ }
+ }
+ }
+ else if (dt == 'xml' && !xhr.responseXML && xhr.responseText != null) {
+ xhr.responseXML = toXml(xhr.responseText);
+ }
+
+ try {
+ data = httpData(xhr, dt, s);
+ }
+ catch (e) {
+ status = 'parsererror';
+ xhr.error = errMsg = (e || status);
+ }
+ }
+ catch (e) {
+ log('error caught: ',e);
+ status = 'error';
+ xhr.error = errMsg = (e || status);
+ }
+
+ if (xhr.aborted) {
+ log('upload aborted');
+ status = null;
+ }
+
+ if (xhr.status) { // we've set xhr.status
+ status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
+ }
+
+ // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
+ if (status === 'success') {
+ s.success && s.success.call(s.context, data, 'success', xhr);
+ g && $.event.trigger("ajaxSuccess", [xhr, s]);
+ }
+ else if (status) {
+ if (errMsg == undefined)
+ errMsg = xhr.statusText;
+ s.error && s.error.call(s.context, xhr, status, errMsg);
+ g && $.event.trigger("ajaxError", [xhr, s, errMsg]);
+ }
+
+ g && $.event.trigger("ajaxComplete", [xhr, s]);
+
+ if (g && ! --$.active) {
+ $.event.trigger("ajaxStop");
+ }
+
+ s.complete && s.complete.call(s.context, xhr, status);
+
+ callbackProcessed = true;
+ if (s.timeout)
+ clearTimeout(timeoutHandle);
+
+ // clean up
+ setTimeout(function() {
+ if (!s.iframeTarget)
+ $io.remove();
+ xhr.responseXML = null;
+ }, 100);
+ }
+
+ var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
+ if (window.ActiveXObject) {
+ doc = new ActiveXObject('Microsoft.XMLDOM');
+ doc.async = 'false';
+ doc.loadXML(s);
+ }
+ else {
+ doc = (new DOMParser()).parseFromString(s, 'text/xml');
+ }
+ return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
+ };
+ var parseJSON = $.parseJSON || function(s) {
+ return window['eval']('(' + s + ')');
+ };
+
+ var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
+
+ var ct = xhr.getResponseHeader('content-type') || '',
+ xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
+ data = xml ? xhr.responseXML : xhr.responseText;
+
+ if (xml && data.documentElement.nodeName === 'parsererror') {
+ $.error && $.error('parsererror');
+ }
+ if (s && s.dataFilter) {
+ data = s.dataFilter(data, type);
+ }
+ if (typeof data === 'string') {
+ if (type === 'json' || !type && ct.indexOf('json') >= 0) {
+ data = parseJSON(data);
+ } else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
+ $.globalEval(data);
+ }
+ }
+ return data;
+ };
+ }
+};
+
+/**
+ * ajaxForm() provides a mechanism for fully automating form submission.
+ *
+ * The advantages of using this method instead of ajaxSubmit() are:
+ *
+ * 1: This method will include coordinates for elements (if the element
+ * is used to submit the form).
+ * 2. This method will include the submit element's name/value data (for the element that was
+ * used to submit the form).
+ * 3. This method binds the submit() method to the form for you.
+ *
+ * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
+ * passes the options argument along after properly binding events for submit elements and
+ * the form itself.
+ */
+$.fn.ajaxForm = function(options) {
+ // in jQuery 1.3+ we can fix mistakes with the ready state
+ if (this.length === 0) {
+ var o = { s: this.selector, c: this.context };
+ if (!$.isReady && o.s) {
+ log('DOM not ready, queuing ajaxForm');
+ $(function() {
+ $(o.s,o.c).ajaxForm(options);
+ });
+ return this;
+ }
+ // is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
+ log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
+ return this;
+ }
+
+ return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
+ if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
+ e.preventDefault();
+ $(this).ajaxSubmit(options);
+ }
+ }).bind('click.form-plugin', function(e) {
+ var target = e.target;
+ var $el = $(target);
+ if (!($el.is(":submit,input:image"))) {
+ // is this a child element of the submit el? (ex: a span within a button)
+ var t = $el.closest(':submit');
+ if (t.length == 0) {
+ return;
+ }
+ target = t[0];
+ }
+ var form = this;
+ form.clk = target;
+ if (target.type == 'image') {
+ if (e.offsetX != undefined) {
+ form.clk_x = e.offsetX;
+ form.clk_y = e.offsetY;
+ } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
+ var offset = $el.offset();
+ form.clk_x = e.pageX - offset.left;
+ form.clk_y = e.pageY - offset.top;
+ } else {
+ form.clk_x = e.pageX - target.offsetLeft;
+ form.clk_y = e.pageY - target.offsetTop;
+ }
+ }
+ // clear form vars
+ setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
+ });
+};
+
+// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
+$.fn.ajaxFormUnbind = function() {
+ return this.unbind('submit.form-plugin click.form-plugin');
+};
+
+/**
+ * formToArray() gathers form element data into an array of objects that can
+ * be passed to any of the following ajax functions: $.get, $.post, or load.
+ * Each object in the array has both a 'name' and 'value' property. An example of
+ * an array for a simple login form might be:
+ *
+ * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
+ *
+ * It is this array that is passed to pre-submit callback functions provided to the
+ * ajaxSubmit() and ajaxForm() methods.
+ */
+$.fn.formToArray = function(semantic) {
+ var a = [];
+ if (this.length === 0) {
+ return a;
+ }
+
+ var form = this[0];
+ var els = semantic ? form.getElementsByTagName('*') : form.elements;
+ if (!els) {
+ return a;
+ }
+
+ var i,j,n,v,el,max,jmax;
+ for(i=0, max=els.length; i < max; i++) {
+ el = els[i];
+ n = el.name;
+ if (!n) {
+ continue;
+ }
+
+ if (semantic && form.clk && el.type == "image") {
+ // handle image inputs on the fly when semantic == true
+ if(!el.disabled && form.clk == el) {
+ a.push({name: n, value: $(el).val(), type: el.type });
+ a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
+ }
+ continue;
+ }
+
+ v = $.fieldValue(el, true);
+ if (v && v.constructor == Array) {
+ for(j=0, jmax=v.length; j < jmax; j++) {
+ a.push({name: n, value: v[j]});
+ }
+ }
+ else if (v !== null && typeof v != 'undefined') {
+ a.push({name: n, value: v, type: el.type});
+ }
+ }
+
+ if (!semantic && form.clk) {
+ // input type=='image' are not found in elements array! handle it here
+ var $input = $(form.clk), input = $input[0];
+ n = input.name;
+ if (n && !input.disabled && input.type == 'image') {
+ a.push({name: n, value: $input.val()});
+ a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
+ }
+ }
+ return a;
+};
+
+/**
+ * Serializes form data into a 'submittable' string. This method will return a string
+ * in the format: name1=value1&name2=value2
+ */
+$.fn.formSerialize = function(semantic) {
+ //hand off to jQuery.param for proper encoding
+ return $.param(this.formToArray(semantic));
+};
+
+/**
+ * Serializes all field elements in the jQuery object into a query string.
+ * This method will return a string in the format: name1=value1&name2=value2
+ */
+$.fn.fieldSerialize = function(successful) {
+ var a = [];
+ this.each(function() {
+ var n = this.name;
+ if (!n) {
+ return;
+ }
+ var v = $.fieldValue(this, successful);
+ if (v && v.constructor == Array) {
+ for (var i=0,max=v.length; i < max; i++) {
+ a.push({name: n, value: v[i]});
+ }
+ }
+ else if (v !== null && typeof v != 'undefined') {
+ a.push({name: this.name, value: v});
+ }
+ });
+ //hand off to jQuery.param for proper encoding
+ return $.param(a);
+};
+
+/**
+ * Returns the value(s) of the element in the matched set. For example, consider the following form:
+ *
+ *
+ *
+ * var v = $(':text').fieldValue();
+ * // if no values are entered into the text inputs
+ * v == ['','']
+ * // if values entered into the text inputs are 'foo' and 'bar'
+ * v == ['foo','bar']
+ *
+ * var v = $(':checkbox').fieldValue();
+ * // if neither checkbox is checked
+ * v === undefined
+ * // if both checkboxes are checked
+ * v == ['B1', 'B2']
+ *
+ * var v = $(':radio').fieldValue();
+ * // if neither radio is checked
+ * v === undefined
+ * // if first radio is checked
+ * v == ['C1']
+ *
+ * The successful argument controls whether or not the field element must be 'successful'
+ * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
+ * The default value of the successful argument is true. If this value is false the value(s)
+ * for each element is returned.
+ *
+ * Note: This method *always* returns an array. If no valid value can be determined the
+ * array will be empty, otherwise it will contain one or more values.
+ */
+$.fn.fieldValue = function(successful) {
+ for (var val=[], i=0, max=this.length; i < max; i++) {
+ var el = this[i];
+ var v = $.fieldValue(el, successful);
+ if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
+ continue;
+ }
+ v.constructor == Array ? $.merge(val, v) : val.push(v);
+ }
+ return val;
+};
+
+/**
+ * Returns the value of the field element.
+ */
+$.fieldValue = function(el, successful) {
+ var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
+ if (successful === undefined) {
+ successful = true;
+ }
+
+ if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
+ (t == 'checkbox' || t == 'radio') && !el.checked ||
+ (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
+ tag == 'select' && el.selectedIndex == -1)) {
+ return null;
+ }
+
+ if (tag == 'select') {
+ var index = el.selectedIndex;
+ if (index < 0) {
+ return null;
+ }
+ var a = [], ops = el.options;
+ var one = (t == 'select-one');
+ var max = (one ? index+1 : ops.length);
+ for(var i=(one ? index : 0); i < max; i++) {
+ var op = ops[i];
+ if (op.selected) {
+ var v = op.value;
+ if (!v) { // extra pain for IE...
+ v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
+ }
+ if (one) {
+ return v;
+ }
+ a.push(v);
+ }
+ }
+ return a;
+ }
+ return $(el).val();
+};
+
+/**
+ * Clears the form data. Takes the following actions on the form's input fields:
+ * - input text fields will have their 'value' property set to the empty string
+ * - select elements will have their 'selectedIndex' property set to -1
+ * - checkbox and radio inputs will have their 'checked' property set to false
+ * - inputs of type submit, button, reset, and hidden will *not* be effected
+ * - button elements will *not* be effected
+ */
+$.fn.clearForm = function(includeHidden) {
+ return this.each(function() {
+ $('input,select,textarea', this).clearFields(includeHidden);
+ });
+};
+
+/**
+ * Clears the selected form elements.
+ */
+$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
+ var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
+ return this.each(function() {
+ var t = this.type, tag = this.tagName.toLowerCase();
+ if (re.test(t) || tag == 'textarea' || (includeHidden && /hidden/.test(t)) ) {
+ this.value = '';
+ }
+ else if (t == 'checkbox' || t == 'radio') {
+ this.checked = false;
+ }
+ else if (tag == 'select') {
+ this.selectedIndex = -1;
+ }
+ });
+};
+
+/**
+ * Resets the form data. Causes all form elements to be reset to their original value.
+ */
+$.fn.resetForm = function() {
+ return this.each(function() {
+ // guard against an input with the name of 'reset'
+ // note that IE reports the reset function as an 'object'
+ if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
+ this.reset();
+ }
+ });
+};
+
+/**
+ * Enables or disables any matching elements.
+ */
+$.fn.enable = function(b) {
+ if (b === undefined) {
+ b = true;
+ }
+ return this.each(function() {
+ this.disabled = !b;
+ });
+};
+
+/**
+ * Checks/unchecks any matching checkboxes or radio buttons and
+ * selects/deselects and matching option elements.
+ */
+$.fn.selected = function(select) {
+ if (select === undefined) {
+ select = true;
+ }
+ return this.each(function() {
+ var t = this.type;
+ if (t == 'checkbox' || t == 'radio') {
+ this.checked = select;
+ }
+ else if (this.tagName.toLowerCase() == 'option') {
+ var $sel = $(this).parent('select');
+ if (select && $sel[0] && $sel[0].type == 'select-one') {
+ // deselect all other options
+ $sel.find('option').selected(false);
+ }
+ this.selected = select;
+ }
+ });
+};
+
+// expose debug var
+$.fn.ajaxSubmit.debug = false;
+
+// helper fn for console logging
+function log() {
+ if (!$.fn.ajaxSubmit.debug)
+ return;
+ var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
+ if (window.console && window.console.log) {
+ window.console.log(msg);
+ }
+ else if (window.opera && window.opera.postError) {
+ window.opera.postError(msg);
+ }
+};
+
+})(jQuery);
diff --git a/app/assets/javascripts/desktop/jquery.gridster.js b/app/assets/javascripts/desktop/jquery.gridster.js
new file mode 100755
index 00000000..e8998514
--- /dev/null
+++ b/app/assets/javascripts/desktop/jquery.gridster.js
@@ -0,0 +1,3234 @@
+/*! gridster.js - v0.1.0 - 2012-10-20
+* http://gridster.net/
+* Copyright (c) 2012 ducksboard; Licensed MIT */
+
+;(function($, window, document, undefined){
+ /**
+ * Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)
+ * to simulate DOM elements on the screen.
+ * Coords is used by Gridster to create a faux grid with any DOM element can
+ * collide.
+ *
+ * @class Coords
+ * @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left,
+ * top, width and height properties.
+ * @return {Object} Coords instance.
+ * @constructor
+ */
+ function Coords(obj) {
+ if (obj[0] && $.isPlainObject(obj[0])) {
+ this.data = obj[0];
+ }else {
+ this.el = obj;
+ }
+
+ this.isCoords = true;
+ this.coords = {};
+ this.init();
+ return this;
+ }
+
+
+ var fn = Coords.prototype;
+
+
+ fn.init = function(){
+ this.set();
+ this.original_coords = this.get();
+ };
+
+
+ fn.set = function(update, not_update_offsets) {
+ var el = this.el;
+
+ if (el && !update) {
+ this.data = el.offset();
+ this.data.width = el.width();
+ this.data.height = el.height();
+ }
+
+ if (el && update && !not_update_offsets) {
+ var offset = el.offset();
+ this.data.top = offset.top;
+ this.data.left = offset.left;
+ }
+
+ var d = this.data;
+
+ this.coords.x1 = d.left;
+ this.coords.y1 = d.top;
+ this.coords.x2 = d.left + d.width;
+ this.coords.y2 = d.top + d.height;
+ this.coords.cx = d.left + (d.width / 2);
+ this.coords.cy = d.top + (d.height / 2);
+ this.coords.width = d.width;
+ this.coords.height = d.height;
+ this.coords.el = el || false ;
+
+ return this;
+ };
+
+
+ fn.update = function(data){
+ if (!data && !this.el) {
+ return this;
+ }
+
+ if (data) {
+ var new_data = $.extend({}, this.data, data);
+ this.data = new_data;
+ return this.set(true, true);
+ }
+
+ this.set(true);
+ return this;
+ };
+
+
+ fn.get = function(){
+ return this.coords;
+ };
+
+
+ //jQuery adapter
+ $.fn.coords = function() {
+ if (this.data('coords') ) {
+ return this.data('coords');
+ }
+
+ var ins = new Coords(this, arguments[0]);
+ this.data('coords', ins);
+ return ins;
+ };
+
+}(jQuery, window, document));
+
+;(function($, window, document, undefined){
+
+ var defaults = {
+ colliders_context: document.body
+ // ,on_overlap: function(collider_data){},
+ // on_overlap_start : function(collider_data){},
+ // on_overlap_stop : function(collider_data){}
+ };
+
+
+ /**
+ * Detects collisions between a DOM element against other DOM elements or
+ * Coords objects.
+ *
+ * @class Collision
+ * @uses Coords
+ * @param {HTMLElement} el The jQuery wrapped HTMLElement.
+ * @param {HTMLElement|Array} colliders Can be a jQuery collection
+ * of HTMLElements or an Array of Coords instances.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {Function} [options.on_overlap_start] Executes a function the first
+ * time each `collider ` is overlapped.
+ * @param {Function} [options.on_overlap_stop] Executes a function when a
+ * `collider` is no longer collided.
+ * @param {Function} [options.on_overlap] Executes a function when the
+ * mouse is moved during the collision.
+ * @return {Object} Collision instance.
+ * @constructor
+ */
+ function Collision(el, colliders, options) {
+ this.options = $.extend(defaults, options);
+ this.$element = el;
+ this.last_colliders = [];
+ this.last_colliders_coords = [];
+ if (typeof colliders === 'string' || colliders instanceof jQuery) {
+ this.$colliders = $(colliders,
+ this.options.colliders_context).not(this.$element);
+ }else{
+ this.colliders = $(colliders);
+ }
+
+ this.init();
+ }
+
+
+ var fn = Collision.prototype;
+
+
+ fn.init = function() {
+ this.find_collisions();
+ };
+
+
+ fn.overlaps = function(a, b) {
+ var x = false;
+ var y = false;
+
+ if ((b.x1 >= a.x1 && b.x1 <= a.x2) ||
+ (b.x2 >= a.x1 && b.x2 <= a.x2) ||
+ (a.x1 >= b.x1 && a.x2 <= b.x2)
+ ) { x = true; }
+
+ if ((b.y1 >= a.y1 && b.y1 <= a.y2) ||
+ (b.y2 >= a.y1 && b.y2 <= a.y2) ||
+ (a.y1 >= b.y1 && a.y2 <= b.y2)
+ ) { y = true; }
+
+ return (x && y);
+ };
+
+
+ fn.detect_overlapping_region = function(a, b){
+ var regionX = '';
+ var regionY = '';
+
+ if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; }
+ if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; }
+ if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; }
+ if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; }
+
+ return (regionX + regionY) || 'C';
+ };
+
+
+ fn.calculate_overlapped_area_coords = function(a, b){
+ var x1 = Math.max(a.x1, b.x1);
+ var y1 = Math.max(a.y1, b.y1);
+ var x2 = Math.min(a.x2, b.x2);
+ var y2 = Math.min(a.y2, b.y2);
+
+ return $({
+ left: x1,
+ top: y1,
+ width : (x2 - x1),
+ height: (y2 - y1)
+ }).coords().get();
+ };
+
+
+ fn.calculate_overlapped_area = function(coords){
+ return (coords.width * coords.height);
+ };
+
+
+ fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){
+ var last = this.last_colliders_coords;
+
+ for (var i = 0, il = last.length; i < il; i++) {
+ if ($.inArray(last[i], new_colliders_coords) === -1) {
+ start_callback.call(this, last[i]);
+ }
+ }
+
+ for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) {
+ if ($.inArray(new_colliders_coords[j], last) === -1) {
+ stop_callback.call(this, new_colliders_coords[j]);
+ }
+
+ }
+ };
+
+
+ fn.find_collisions = function(player_data_coords){
+ var self = this;
+ var colliders_coords = [];
+ var colliders_data = [];
+ var $colliders = (this.colliders || this.$colliders);
+ var count = $colliders.length;
+ var player_coords = self.$element.coords()
+ .update(player_data_coords || false).get();
+
+ while(count--){
+ var $collider = self.$colliders ?
+ $($colliders[count]) : $colliders[count];
+ var $collider_coords_ins = ($collider.isCoords) ?
+ $collider : $collider.coords();
+ var collider_coords = $collider_coords_ins.get();
+ var overlaps = self.overlaps(player_coords, collider_coords);
+
+ if (!overlaps) {
+ continue;
+ }
+
+ var region = self.detect_overlapping_region(
+ player_coords, collider_coords);
+
+ //todo: make this an option
+ if (region === 'C'){
+ var area_coords = self.calculate_overlapped_area_coords(
+ player_coords, collider_coords);
+ var area = self.calculate_overlapped_area(area_coords);
+ var collider_data = {
+ area: area,
+ area_coords : area_coords,
+ region: region,
+ coords: collider_coords,
+ player_coords: player_coords,
+ el: $collider
+ };
+
+ if (self.options.on_overlap) {
+ self.options.on_overlap.call(this, collider_data);
+ }
+ colliders_coords.push($collider_coords_ins);
+ colliders_data.push(collider_data);
+ }
+ }
+
+ if (self.options.on_overlap_stop || self.options.on_overlap_start) {
+ this.manage_colliders_start_stop(colliders_coords,
+ self.options.on_overlap_stop, self.options.on_overlap_start);
+ }
+
+ this.last_colliders_coords = colliders_coords;
+
+ return colliders_data;
+ };
+
+
+ fn.get_closest_colliders = function(player_data_coords){
+ var colliders = this.find_collisions(player_data_coords);
+
+ colliders.sort(function(a, b) {
+ /* if colliders are being overlapped by the "C" (center) region,
+ * we have to set a lower index in the array to which they are placed
+ * above in the grid. */
+ if (a.region === 'C' && b.region === 'C') {
+ if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) {
+ return - 1;
+ }else{
+ return 1;
+ }
+ }
+
+ if (a.area < b.area) {
+ return 1;
+ }
+
+ return 1;
+ });
+ return colliders;
+ };
+
+
+ //jQuery adapter
+ $.fn.collision = function(collider, options) {
+ return new Collision( this, collider, options );
+ };
+
+
+}(jQuery, window, document));
+
+;(function(window, undefined) {
+ /* Debounce and throttle functions taken from underscore.js */
+ window.debounce = function(func, wait, immediate) {
+ var timeout;
+ return function() {
+ var context = this, args = arguments;
+ var later = function() {
+ timeout = null;
+ if (!immediate) func.apply(context, args);
+ };
+ if (immediate && !timeout) func.apply(context, args);
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+ };
+ };
+
+
+ window.throttle = function(func, wait) {
+ var context, args, timeout, throttling, more, result;
+ var whenDone = debounce(
+ function(){ more = throttling = false; }, wait);
+ return function() {
+ context = this; args = arguments;
+ var later = function() {
+ timeout = null;
+ if (more) func.apply(context, args);
+ whenDone();
+ };
+ if (!timeout) timeout = setTimeout(later, wait);
+ if (throttling) {
+ more = true;
+ } else {
+ result = func.apply(context, args);
+ }
+ whenDone();
+ throttling = true;
+ return result;
+ };
+ };
+
+})(window);
+
+;(function($, window, document, undefined){
+
+ var defaults = {
+ items: '.gs_w',
+ distance: 1,
+ limit: true,
+ offset_left: 0,
+ autoscroll: true,
+ ignore_dragging: ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'],
+ handle: null
+ // ,drag: function(e){},
+ // start : function(e, ui){},
+ // stop : function(e){}
+ };
+
+ var $window = $(window);
+ var isTouch = !!('ontouchstart' in window);
+ var pointer_events = {
+ start: isTouch ? 'touchstart' : 'mousedown.draggable',
+ move: isTouch ? 'touchmove' : 'mousemove.draggable',
+ end: isTouch ? 'touchend' : 'mouseup.draggable'
+ };
+
+ /**
+ * Basic drag implementation for DOM elements inside a container.
+ * Provide start/stop/drag callbacks.
+ *
+ * @class Draggable
+ * @param {HTMLElement} el The HTMLelement that contains all the widgets
+ * to be dragged.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {HTMLElement|String} [options.items] Define who will
+ * be the draggable items. Can be a CSS Selector String or a
+ * collection of HTMLElements.
+ * @param {Number} [options.distance] Distance in pixels after mousedown
+ * the mouse must move before dragging should start.
+ * @param {Boolean} [options.limit] Constrains dragging to the width of
+ * the container
+ * @param {offset_left} [options.offset_left] Offset added to the item
+ * that is being dragged.
+ * @param {Number} [options.drag] Executes a callback when the mouse is
+ * moved during the dragging.
+ * @param {Number} [options.start] Executes a callback when the drag
+ * starts.
+ * @param {Number} [options.stop] Executes a callback when the drag stops.
+ * @return {Object} Returns `el`.
+ * @constructor
+ */
+ function Draggable(el, options) {
+ this.options = $.extend({}, defaults, options);
+ this.$body = $(document.body);
+ this.$container = $(el);
+ this.$dragitems = $(this.options.items, this.$container);
+ this.is_dragging = false;
+ this.player_min_left = 0 + this.options.offset_left;
+ this.init();
+ }
+
+ var fn = Draggable.prototype;
+
+ fn.init = function() {
+ this.calculate_positions();
+ this.$container.css('position', 'relative');
+ this.disabled = false;
+ this.events();
+
+ $(window).bind('resize',
+ throttle($.proxy(this.calculate_positions, this), 200));
+ };
+
+ fn.events = function() {
+ this.$container.on('selectstart', $.proxy(this.on_select_start, this));
+
+ this.$container.on(pointer_events.start, this.options.items, $.proxy(
+ this.drag_handler, this));
+
+ this.$body.on(pointer_events.end, $.proxy(function(e) {
+ this.is_dragging = false;
+ if (this.disabled) { return; }
+ this.$body.off(pointer_events.move);
+ if (this.drag_start) {
+ this.on_dragstop(e);
+ }
+ }, this));
+ };
+
+ fn.get_actual_pos = function($el) {
+ var pos = $el.position();
+ return pos;
+ };
+
+
+ fn.get_mouse_pos = function(e) {
+ if (isTouch) {
+ var oe = e.originalEvent;
+ e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
+ }
+
+ return {
+ left: e.clientX,
+ top: e.clientY
+ };
+ };
+
+
+ fn.get_offset = function(e) {
+ e.preventDefault();
+ var mouse_actual_pos = this.get_mouse_pos(e);
+ var diff_x = Math.round(
+ mouse_actual_pos.left - this.mouse_init_pos.left);
+ var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
+
+ var left = Math.round(this.el_init_offset.left + diff_x - this.baseX);
+ var top = Math.round(
+ this.el_init_offset.top + diff_y - this.baseY + this.scrollOffset);
+
+ if (this.options.limit) {
+ if (left > this.player_max_left) {
+ left = this.player_max_left;
+ }else if(left < this.player_min_left) {
+ left = this.player_min_left;
+ }
+ }
+
+ return {
+ left: left,
+ top: top,
+ mouse_left: mouse_actual_pos.left,
+ mouse_top: mouse_actual_pos.top
+ };
+ };
+
+
+ fn.manage_scroll = function(offset) {
+ /* scroll document */
+ var nextScrollTop;
+ var scrollTop = $window.scrollTop();
+ var min_window_y = scrollTop;
+ var max_window_y = min_window_y + this.window_height;
+
+ var mouse_down_zone = max_window_y - 50;
+ var mouse_up_zone = min_window_y + 50;
+
+ var abs_mouse_left = offset.mouse_left;
+ var abs_mouse_top = min_window_y + offset.mouse_top;
+
+ var max_player_y = (this.doc_height - this.window_height +
+ this.player_height);
+
+ if (abs_mouse_top >= mouse_down_zone) {
+ nextScrollTop = scrollTop + 30;
+ if (nextScrollTop < max_player_y) {
+ $window.scrollTop(nextScrollTop);
+ this.scrollOffset = this.scrollOffset + 30;
+ }
+ }
+
+ if (abs_mouse_top <= mouse_up_zone) {
+ nextScrollTop = scrollTop - 30;
+ if (nextScrollTop > 0) {
+ $window.scrollTop(nextScrollTop);
+ this.scrollOffset = this.scrollOffset - 30;
+ }
+ }
+ };
+
+
+ fn.calculate_positions = function(e) {
+ this.window_height = $window.height();
+ };
+
+
+ fn.drag_handler = function(e) {
+ var node = e.target.nodeName;
+ if (this.disabled || e.which !== 1 && !isTouch) {
+ return;
+ }
+
+ if (this.ignore_drag(e)) {
+ return;
+ }
+
+ var self = this;
+ var first = true;
+ this.$player = $(e.currentTarget);
+
+ this.el_init_pos = this.get_actual_pos(this.$player);
+ this.mouse_init_pos = this.get_mouse_pos(e);
+ this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
+
+ this.$body.on(pointer_events.move, function(mme){
+ var mouse_actual_pos = self.get_mouse_pos(mme);
+ var diff_x = Math.abs(
+ mouse_actual_pos.left - self.mouse_init_pos.left);
+ var diff_y = Math.abs(
+ mouse_actual_pos.top - self.mouse_init_pos.top);
+ if (!(diff_x > self.options.distance ||
+ diff_y > self.options.distance)
+ ) {
+ return false;
+ }
+
+ if (first) {
+ first = false;
+ self.on_dragstart.call(self, mme);
+ return false;
+ }
+
+ if (self.is_dragging === true) {
+ self.on_dragmove.call(self, mme);
+ }
+
+ return false;
+ });
+
+ return false;
+ };
+
+
+ fn.on_dragstart = function(e) {
+ e.preventDefault();
+ this.drag_start = true;
+ this.is_dragging = true;
+ var offset = this.$container.offset();
+ this.baseX = Math.round(offset.left);
+ this.baseY = Math.round(offset.top);
+ this.doc_height = $(document).height();
+
+ if (this.options.helper === 'clone') {
+ this.$helper = this.$player.clone()
+ .appendTo(this.$container).addClass('helper');
+ this.helper = true;
+ }else{
+ this.helper = false;
+ }
+ this.scrollOffset = 0;
+ this.el_init_offset = this.$player.offset();
+ this.player_width = this.$player.width();
+ this.player_height = this.$player.height();
+ this.player_max_left = (this.$container.width() - this.player_width +
+ this.options.offset_left);
+
+ if (this.options.start) {
+ this.options.start.call(this.$player, e, {
+ helper: this.helper ? this.$helper : this.$player
+ });
+ }
+ return false;
+ };
+
+
+ fn.on_dragmove = function(e) {
+ var offset = this.get_offset(e);
+
+ this.options.autoscroll && this.manage_scroll(offset);
+
+ (this.helper ? this.$helper : this.$player).css({
+ 'position': 'absolute',
+ 'left' : offset.left,
+ 'top' : offset.top
+ });
+
+ var ui = {
+ 'position': {
+ 'left': offset.left,
+ 'top': offset.top
+ }
+ };
+
+ if (this.options.drag) {
+ this.options.drag.call(this.$player, e, ui);
+ }
+ return false;
+ };
+
+
+ fn.on_dragstop = function(e) {
+ var offset = this.get_offset(e);
+ this.drag_start = false;
+
+ var ui = {
+ 'position': {
+ 'left': offset.left,
+ 'top': offset.top
+ }
+ };
+
+ if (this.options.stop) {
+ this.options.stop.call(this.$player, e, ui);
+ }
+
+ if (this.helper) {
+ this.$helper.remove();
+ }
+
+ return false;
+ };
+
+ fn.on_select_start = function(e) {
+ if (this.disabled) { return; }
+
+ if (this.ignore_drag(e)) {
+ return;
+ }
+
+ return false;
+ };
+
+ fn.enable = function() {
+ this.disabled = false;
+ };
+
+ fn.disable = function() {
+ this.disabled = true;
+ };
+
+
+ fn.destroy = function(){
+ this.disable();
+ $.removeData(this.$container, 'drag');
+ };
+
+ fn.ignore_drag = function(event) {
+ if (this.options.handle) {
+ return !$(event.target).is(this.options.handle);
+ }
+
+ return $.inArray(event.target.nodeName, this.options.ignore_dragging) >= 0;
+ };
+
+ //jQuery adapter
+ $.fn.drag = function ( options ) {
+ return this.each(function () {
+ if (!$.data(this, 'drag')) {
+ $.data(this, 'drag', new Draggable( this, options ));
+ }
+ });
+ };
+
+
+}(jQuery, window, document));
+
+;(function($, window, document, undefined) {
+
+ var defaults = {
+ namespace: '',
+ widget_selector: 'li',
+ widget_margins: [10, 10],
+ widget_base_dimensions: [400, 225],
+ extra_rows: 0,
+ extra_cols: 0,
+ min_cols: 1,
+ min_rows: 15,
+ max_size_x: 6,
+ autogenerate_stylesheet: true,
+ avoid_overlapped_widgets: true,
+ serialize_params: function($w, wgd) {
+ return {
+ col: wgd.col,
+ row: wgd.row,
+ size_x: wgd.size_x,
+ size_y: wgd.size_y
+ };
+ },
+ collision: {},
+ draggable: {
+ distance: 4
+ }
+ };
+
+
+ /**
+ * @class Gridster
+ * @uses Draggable
+ * @uses Collision
+ * @param {HTMLElement} el The HTMLelement that contains all the widgets.
+ * @param {Object} [options] An Object with all options you want to
+ * overwrite:
+ * @param {HTMLElement|String} [options.widget_selector] Define who will
+ * be the draggable widgets. Can be a CSS Selector String or a
+ * collection of HTMLElements
+ * @param {Array} [options.widget_margins] Margin between widgets.
+ * The first index for the horizontal margin (left, right) and
+ * the second for the vertical margin (top, bottom).
+ * @param {Array} [options.widget_base_dimensions] Base widget dimensions
+ * in pixels. The first index for the width and the second for the
+ * height.
+ * @param {Number} [options.extra_cols] Add more columns in addition to
+ * those that have been calculated.
+ * @param {Number} [options.extra_rows] Add more rows in addition to
+ * those that have been calculated.
+ * @param {Number} [options.min_cols] The minimum required columns.
+ * @param {Number} [options.min_rows] The minimum required rows.
+ * @param {Number} [options.max_size_x] The maximum number of columns
+ * that a widget can span.
+ * @param {Boolean} [options.autogenerate_stylesheet] If true, all the
+ * CSS required to position all widgets in their respective columns
+ * and rows will be generated automatically and injected to the
+ * `` of the document. You can set this to false, and write
+ * your own CSS targeting rows and cols via data-attributes like so:
+ * `[data-col="1"] { left: 10px; }`
+ * @param {Boolean} [options.avoid_overlapped_widgets] Avoid that widgets loaded
+ * from the DOM can be overlapped. It is helpful if the positions were
+ * bad stored in the database or if there was any conflict.
+ * @param {Function} [options.serialize_params] Return the data you want
+ * for each widget in the serialization. Two arguments are passed:
+ * `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid
+ * coords object (`col`, `row`, `size_x`, `size_y`).
+ * @param {Object} [options.collision] An Object with all options for
+ * Collision class you want to overwrite. See Collision docs for
+ * more info.
+ * @param {Object} [options.draggable] An Object with all options for
+ * Draggable class you want to overwrite. See Draggable docs for more
+ * info.
+ *
+ * @constructor
+ */
+ function Gridster(el, options) {
+ this.options = $.extend(true, defaults, options);
+ this.$el = $(el);
+ this.$wrapper = this.$el.parent();
+ this.$widgets = this.$el.children(this.options.widget_selector).addClass('gs_w');
+ this.widgets = [];
+ this.$changed = $([]);
+ this.wrapper_width = this.$wrapper.width();
+ this.min_widget_width = (this.options.widget_margins[0] * 2) +
+ this.options.widget_base_dimensions[0];
+ this.min_widget_height = (this.options.widget_margins[1] * 2) +
+ this.options.widget_base_dimensions[1];
+ this.init();
+ }
+
+ Gridster.generated_stylesheets = [];
+
+ var fn = Gridster.prototype;
+
+ fn.init = function() {
+ this.generate_grid_and_stylesheet();
+ this.get_widgets_from_DOM();
+ this.set_dom_grid_height();
+ this.$wrapper.addClass('ready');
+ this.draggable();
+
+ $(window).bind(
+ 'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200));
+ };
+
+
+ /**
+ * Disables dragging.
+ *
+ * @method disable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.disable = function() {
+ this.$wrapper.find('.player-revert').removeClass('player-revert');
+ this.drag_api.disable();
+ return this;
+ };
+
+
+ /**
+ * Enables dragging.
+ *
+ * @method enable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.enable = function() {
+ this.drag_api.enable();
+ return this;
+ };
+
+
+ /**
+ * Add a new widget to the grid.
+ *
+ * @method add_widget
+ * @param {String|HTMLElement} html The string representing the HTML of the widget
+ * or the HTMLElement.
+ * @param {Number} [size_x] The nº of rows the widget occupies horizontally.
+ * @param {Number} [size_y] The nº of columns the widget occupies vertically.
+ * @param {Number} [col] The column the widget should start in.
+ * @param {Number} [row] The row the widget should start in.
+ * @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
+ * the widget that was just created.
+ */
+ fn.add_widget = function(html, size_x, size_y, col, row) {
+ var pos;
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+
+ if (!col & !row) {
+ pos = this.next_position(size_x, size_y);
+ }else{
+ pos = {
+ col: col,
+ row: row
+ };
+
+ this.empty_cells(col, row, size_x, size_y);
+ }
+
+ var $w = $(html).attr({
+ 'data-col': pos.col,
+ 'data-row': pos.row,
+ 'data-sizex' : size_x,
+ 'data-sizey' : size_y
+ }).addClass('gs_w').appendTo(this.$el).hide();
+
+ this.$widgets = this.$widgets.add($w);
+
+ this.register_widget($w);
+
+ this.add_faux_rows(pos.size_y);
+ //this.add_faux_cols(pos.size_x);
+
+ this.set_dom_grid_height();
+
+ return $w.fadeIn();
+ };
+
+
+
+ /**
+ * Change the size of a widget.
+ *
+ * @method resize_widget
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement
+ * representing the widget.
+ * @param {Number} size_x The number of columns that will occupy the widget.
+ * @param {Number} size_y The number of rows that will occupy the widget.
+ * @return {HTMLElement} Returns $widget.
+ */
+ fn.resize_widget = function($widget, size_x, size_y) {
+ var wgd = $widget.coords().grid;
+ size_x || (size_x = wgd.size_x);
+ size_y || (size_y = wgd.size_y);
+
+ if (size_x > this.cols) {
+ size_x = this.cols;
+ }
+
+ var old_cells_occupied = this.get_cells_occupied(wgd);
+ var old_size_x = wgd.size_x;
+ var old_size_y = wgd.size_y;
+ var old_col = wgd.col;
+ var new_col = old_col;
+ var wider = size_x > old_size_x;
+ var taller = size_y > old_size_y;
+
+ if (old_col + size_x - 1 > this.cols) {
+ var diff = old_col + (size_x - 1) - this.cols;
+ var c = old_col - diff;
+ new_col = Math.max(1, c);
+ }
+
+ var new_grid_data = {
+ col: new_col,
+ row: wgd.row,
+ size_x: size_x,
+ size_y: size_y
+ };
+
+ var new_cells_occupied = this.get_cells_occupied(new_grid_data);
+
+ var empty_cols = [];
+ $.each(old_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, new_cells_occupied.cols) === -1) {
+ empty_cols.push(col);
+ }
+ });
+
+ var occupied_cols = [];
+ $.each(new_cells_occupied.cols, function(i, col) {
+ if ($.inArray(col, old_cells_occupied.cols) === -1) {
+ occupied_cols.push(col);
+ }
+ });
+
+ var empty_rows = [];
+ $.each(old_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, new_cells_occupied.rows) === -1) {
+ empty_rows.push(row);
+ }
+ });
+
+ var occupied_rows = [];
+ $.each(new_cells_occupied.rows, function(i, row) {
+ if ($.inArray(row, old_cells_occupied.rows) === -1) {
+ occupied_rows.push(row);
+ }
+ });
+
+ this.remove_from_gridmap(wgd);
+
+ if (occupied_cols.length) {
+ var cols_to_empty = [
+ new_col, wgd.row, size_x, Math.min(old_size_y, size_y), $widget
+ ];
+ this.empty_cells.apply(this, cols_to_empty);
+ }
+
+ if (occupied_rows.length) {
+ var rows_to_empty = [new_col, wgd.row, size_x, size_y, $widget];
+ this.empty_cells.apply(this, rows_to_empty);
+ }
+
+ wgd.col = new_col;
+ wgd.size_x = size_x;
+ wgd.size_y = size_y;
+ this.add_to_gridmap(new_grid_data, $widget);
+
+ //update coords instance attributes
+ $widget.data('coords').update({
+ width: (size_x * this.options.widget_base_dimensions[0] +
+ ((size_x - 1) * this.options.widget_margins[0]) * 2),
+ height: (size_y * this.options.widget_base_dimensions[1] +
+ ((size_y - 1) * this.options.widget_margins[1]) * 2)
+ });
+
+ if (size_y > old_size_y) {
+ this.add_faux_rows(size_y - old_size_y);
+ }
+
+ if (size_x > old_size_x) {
+ this.add_faux_cols(size_x - old_size_x);
+ }
+
+ $widget.attr({
+ 'data-col': new_col,
+ 'data-sizex': size_x,
+ 'data-sizey': size_y
+ });
+
+ if (empty_cols.length) {
+ var cols_to_remove_holes = [
+ empty_cols[0], wgd.row,
+ empty_cols.length,
+ Math.min(old_size_y, size_y),
+ $widget
+ ];
+
+ this.remove_empty_cells.apply(this, cols_to_remove_holes);
+ }
+
+ if (empty_rows.length) {
+ var rows_to_remove_holes = [
+ new_col, wgd.row, size_x, size_y, $widget
+ ];
+ this.remove_empty_cells.apply(this, rows_to_remove_holes);
+ }
+
+ return $widget;
+ };
+
+ /**
+ * Move down widgets in cells represented by the arguments col, row, size_x,
+ * size_y
+ *
+ * @method empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} $exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.empty_cells = function(col, row, size_x, size_y, $exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row - size_y,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not($exclude).each($.proxy(function(i, w) {
+ var wgd = $(w).coords().grid;
+ if (!(wgd.row <= (row + size_y - 1))) { return; }
+ var diff = (row + size_y) - wgd.row;
+ this.move_widget_down($(w), diff);
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Move up widgets below cells represented by the arguments col, row, size_x,
+ * size_y.
+ *
+ * @method remove_empty_cells
+ * @param {Number} col The column where the group of cells begin.
+ * @param {Number} row The row where the group of cells begin.
+ * @param {Number} size_x The number of columns that the group of cells
+ * occupy.
+ * @param {Number} size_y The number of rows that the group of cells
+ * occupy.
+ * @param {HTMLElement} $exclude Exclude widgets from being moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_empty_cells = function(col, row, size_x, size_y, exclude) {
+ var $nexts = this.widgets_below({
+ col: col,
+ row: row,
+ size_x: size_x,
+ size_y: size_y
+ });
+
+ $nexts.not(exclude).each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), size_y );
+ }, this));
+
+ this.set_dom_grid_height();
+
+ return this;
+ };
+
+
+ /**
+ * Get the most left column below to add a new widget.
+ *
+ * @method next_position
+ * @param {Number} size_x The nº of rows the widget occupies horizontally.
+ * @param {Number} size_y The nº of columns the widget occupies vertically.
+ * @return {Object} Returns a grid coords object representing the future
+ * widget coords.
+ */
+ fn.next_position = function(size_x, size_y) {
+ size_x || (size_x = 1);
+ size_y || (size_y = 1);
+ var ga = this.gridmap;
+ var cols_l = ga.length;
+ var valid_pos = [];
+ var rows_l;
+
+ for (var c = 1; c < cols_l; c++) {
+ rows_l = ga[c].length;
+ for (var r = 1; r <= rows_l; r++) {
+ var can_move_to = this.can_move_to({
+ size_x: size_x,
+ size_y: size_y
+ }, c, r);
+
+ if (can_move_to) {
+ valid_pos.push({
+ col: c,
+ row: r,
+ size_y: size_y,
+ size_x: size_x
+ });
+ }
+ }
+ }
+
+ if (valid_pos.length) {
+ return this.sort_by_row_and_col_asc(valid_pos)[0];
+ }
+ return false;
+ };
+
+
+ /**
+ * Remove a widget from the grid.
+ *
+ * @method remove_widget
+ * @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
+ * @param {Boolean|Function} silent If true, widgets below the removed one
+ * will not move up. If a Function is passed it will be used as callback.
+ * @param {Function} callback Function executed when the widget is removed.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_widget = function(el, silent, callback) {
+ var $el = el instanceof jQuery ? el : $(el);
+ var wgd = $el.coords().grid;
+
+ // if silent is a function assume it's a callback
+ if ($.isFunction(silent)) {
+ callback = silent;
+ silent = false;
+ }
+
+ this.cells_occupied_by_placeholder = {};
+ this.$widgets = this.$widgets.not($el);
+
+ var $nexts = this.widgets_below($el);
+
+ this.remove_from_gridmap(wgd);
+
+ $el.fadeOut($.proxy(function() {
+ $el.remove();
+
+ if (!silent) {
+ $nexts.each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget), wgd.size_y );
+ }, this));
+ }
+
+ this.set_dom_grid_height();
+
+ if (callback) {
+ callback.call(this, el);
+ }
+ }, this));
+ };
+
+
+ /**
+ * Remove all widgets from the grid.
+ *
+ * @method remove_all_widgets
+ * @param {Function} callback Function executed for each widget removed.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_all_widgets = function(callback) {
+ this.$widgets.each($.proxy(function(i, el){
+ this.remove_widget(el, true, callback);
+ }, this));
+
+ return this;
+ };
+
+
+ /**
+ * Returns a serialized array of the widgets in the grid.
+ *
+ * @method serialize
+ * @param {HTMLElement} [$widgets] The collection of jQuery wrapped
+ * HTMLElements you want to serialize. If no argument is passed all widgets
+ * will be serialized.
+ * @return {Array} Returns an Array of Objects with the data specified in
+ * the serialize_params option.
+ */
+ fn.serialize = function($widgets) {
+ $widgets || ($widgets = this.$widgets);
+ var result = [];
+ $widgets.each($.proxy(function(i, widget) {
+ result.push(this.options.serialize_params(
+ $(widget), $(widget).coords().grid ) );
+ }, this));
+
+ return result;
+ };
+
+
+ /**
+ * Returns a serialized array of the widgets that have changed their
+ * position.
+ *
+ * @method serialize_changed
+ * @return {Array} Returns an Array of Objects with the data specified in
+ * the serialize_params option.
+ */
+ fn.serialize_changed = function() {
+ return this.serialize(this.$changed);
+ };
+
+
+ /**
+ * Creates the grid coords object representing the widget a add it to the
+ * mapped array of positions.
+ *
+ * @method register_widget
+ * @return {Array} Returns the instance of the Gridster class.
+ */
+ fn.register_widget = function($el) {
+
+ var wgd = {
+ 'col': parseInt($el.attr('data-col'), 10),
+ 'row': parseInt($el.attr('data-row'), 10),
+ 'size_x': parseInt($el.attr('data-sizex'), 10),
+ 'size_y': parseInt($el.attr('data-sizey'), 10),
+ 'el': $el
+ };
+
+ if (this.options.avoid_overlapped_widgets &&
+ !this.can_move_to(
+ {size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
+ ) {
+ wgd = this.next_position(wgd.size_x, wgd.size_y);
+ wgd.el = $el;
+ $el.attr({
+ 'data-col': wgd.col,
+ 'data-row': wgd.row,
+ 'data-sizex': wgd.size_x,
+ 'data-sizey': wgd.size_y
+ });
+ }
+
+ // attach Coord object to player data-coord attribute
+ $el.data('coords', $el.coords());
+
+ // Extend Coord object with grid position info
+ $el.data('coords').grid = wgd;
+
+ this.add_to_gridmap(wgd, $el);
+
+ return this;
+ };
+
+
+ /**
+ * Update in the mapped array of positions the value of cells represented by
+ * the grid coords object passed in the `grid_data` param.
+ *
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @param {HTMLElement|Boolean} value Pass `false` or the jQuery wrapped
+ * HTMLElement, depends if you want to delete an existing position or add
+ * a new one.
+ * @method update_widget_position
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.update_widget_position = function(grid_data, value) {
+ this.for_each_cell_occupied(grid_data, function(col, row) {
+ if (!this.gridmap[col]) { return this; }
+ this.gridmap[col][row] = value;
+ });
+ return this;
+ };
+
+
+ /**
+ * Remove a widget from the mapped array of positions.
+ *
+ * @method remove_from_gridmap
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.remove_from_gridmap = function(grid_data) {
+ return this.update_widget_position(grid_data, false);
+ };
+
+
+ /**
+ * Add a widget to the mapped array of positions.
+ *
+ * @method add_to_gridmap
+ * @param {Object} grid_data The grid coords object representing the cells
+ * to update in the mapped array.
+ * @param {HTMLElement|Boolean} value The value to set in the specified
+ * position .
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.add_to_gridmap = function(grid_data, value) {
+ this.update_widget_position(grid_data, value || grid_data.el);
+
+ if (grid_data.el) {
+ var $widgets = this.widgets_below(grid_data.el);
+ $widgets.each($.proxy(function(i, widget) {
+ this.move_widget_up( $(widget));
+ }, this));
+ }
+ };
+
+
+ /**
+ * Make widgets draggable.
+ *
+ * @uses Draggable
+ * @method draggable
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.draggable = function() {
+ var self = this;
+
+ var draggable_options = $.extend(true, {}, this.options.draggable, {
+ offset_left: this.options.widget_margins[0],
+ start: function(event, ui) {
+ self.$widgets.filter('.player-revert')
+ .removeClass('player-revert');
+
+ self.$player = $(this);
+ self.$helper = self.options.draggable.helper === 'clone' ?
+ $(ui.helper) : self.$player;
+ self.helper = !self.$helper.is(self.$player);
+
+ self.on_start_drag.call(self, event, ui);
+ self.$el.trigger('gridster:dragstart');
+ },
+ stop: function(event, ui) {
+ self.on_stop_drag.call(self, event, ui);
+ self.$el.trigger('gridster:dragstop');
+ },
+ drag: throttle(function(event, ui) {
+ self.on_drag.call(self, event, ui);
+ self.$el.trigger('gridster:drag');
+ }, 60)
+ });
+
+ this.drag_api = this.$el.drag(draggable_options).data('drag');
+ return this;
+ };
+
+
+ /**
+ * This function is executed when the player begins to be dragged.
+ *
+ * @method on_start_drag
+ * @param {Event} The original browser event
+ * @param {Object} A prepared ui object.
+ */
+ fn.on_start_drag = function(event, ui) {
+
+ this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
+
+ this.$player.addClass('player');
+ this.player_grid_data = this.$player.coords().grid;
+ this.placeholder_grid_data = $.extend({}, this.player_grid_data);
+
+ //set new grid height along the dragging period
+ this.$el.css('height', this.$el.height() +
+ (this.player_grid_data.size_y * this.min_widget_height));
+
+ var colliders = this.faux_grid;
+ var coords = this.$player.data('coords').coords;
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.player_grid_data);
+ this.cells_occupied_by_placeholder = this.get_cells_occupied(
+ this.placeholder_grid_data);
+
+ this.last_cols = [];
+ this.last_rows = [];
+
+
+ // see jquery.collision.js
+ this.collision_api = this.$helper.collision(
+ colliders, this.options.collision);
+
+ this.$preview_holder = $('', {
+ 'class': 'preview-holder',
+ 'data-row': this.$player.attr('data-row'),
+ 'data-col': this.$player.attr('data-col'),
+ css: {
+ width: coords.width,
+ height: coords.height
+ }
+ }).appendTo(this.$el);
+
+ if (this.options.draggable.start) {
+ this.options.draggable.start.call(this, event, ui);
+ }
+ };
+
+
+ /**
+ * This function is executed when the player is being dragged.
+ *
+ * @method on_drag
+ * @param {Event} The original browser event
+ * @param {Object} A prepared ui object.
+ */
+ fn.on_drag = function(event, ui) {
+ //break if dragstop has been fired
+ if (this.$player === null) {
+ return false;
+ }
+
+ var abs_offset = {
+ left: ui.position.left + this.baseX,
+ top: ui.position.top + this.baseY
+ };
+
+ this.colliders_data = this.collision_api.get_closest_colliders(
+ abs_offset);
+
+ this.on_overlapped_column_change(
+ this.on_start_overlapping_column,
+ this.on_stop_overlapping_column
+ );
+
+ this.on_overlapped_row_change(
+ this.on_start_overlapping_row,
+ this.on_stop_overlapping_row
+ );
+
+ if (this.helper && this.$player) {
+ this.$player.css({
+ 'left': ui.position.left,
+ 'top': ui.position.top
+ });
+ }
+
+ if (this.options.draggable.drag) {
+ this.options.draggable.drag.call(this, event, ui);
+ }
+ };
+
+ /**
+ * This function is executed when the player stops being dragged.
+ *
+ * @method on_stop_drag
+ * @param {Event} The original browser event
+ * @param {Object} A prepared ui object.
+ */
+ fn.on_stop_drag = function(event, ui) {
+ this.$helper.add(this.$player).add(this.$wrapper)
+ .removeClass('dragging');
+
+ ui.position.left = ui.position.left + this.baseX;
+ ui.position.top = ui.position.top + this.baseY;
+ this.colliders_data = this.collision_api.get_closest_colliders(ui.position);
+
+ this.on_overlapped_column_change(
+ this.on_start_overlapping_column,
+ this.on_stop_overlapping_column
+ );
+
+ this.on_overlapped_row_change(
+ this.on_start_overlapping_row,
+ this.on_stop_overlapping_row
+ );
+
+ this.$player.addClass('player-revert').removeClass('player')
+ .attr({
+ 'data-col': this.placeholder_grid_data.col,
+ 'data-row': this.placeholder_grid_data.row
+ }).css({
+ 'left': '',
+ 'top': ''
+ });
+
+ this.$changed = this.$changed.add(this.$player);
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.placeholder_grid_data);
+ this.set_cells_player_occupies(
+ this.placeholder_grid_data.col, this.placeholder_grid_data.row);
+
+ this.$player.coords().grid.row = this.placeholder_grid_data.row;
+ this.$player.coords().grid.col = this.placeholder_grid_data.col;
+
+ if (this.options.draggable.stop) {
+ this.options.draggable.stop.call(this, event, ui);
+ }
+
+ this.$preview_holder.remove();
+
+ this.$player = null;
+ this.$helper = null;
+ this.placeholder_grid_data = {};
+ this.player_grid_data = {};
+ this.cells_occupied_by_placeholder = {};
+ this.cells_occupied_by_player = {};
+
+ this.set_dom_grid_height();
+ };
+
+
+ /**
+ * Executes the callbacks passed as arguments when a column begins to be
+ * overlapped or stops being overlapped.
+ *
+ * @param {Function} start_callback Function executed when a new column
+ * begins to be overlapped. The column is passed as first argument.
+ * @param {Function} stop_callback Function executed when a column stops
+ * being overlapped. The column is passed as first argument.
+ * @method on_overlapped_column_change
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.on_overlapped_column_change = function(start_callback, stop_callback) {
+ if (!this.colliders_data.length) {
+ return;
+ }
+ var cols = this.get_targeted_columns(
+ this.colliders_data[0].el.data.col);
+
+ var last_n_cols = this.last_cols.length;
+ var n_cols = cols.length;
+ var i;
+
+ for (i = 0; i < n_cols; i++) {
+ if ($.inArray(cols[i], this.last_cols) === -1) {
+ (start_callback || $.noop).call(this, cols[i]);
+ }
+ }
+
+ for (i = 0; i< last_n_cols; i++) {
+ if ($.inArray(this.last_cols[i], cols) === -1) {
+ (stop_callback || $.noop).call(this, this.last_cols[i]);
+ }
+ }
+
+ this.last_cols = cols;
+
+ return this;
+ };
+
+
+ /**
+ * Executes the callbacks passed as arguments when a row starts to be
+ * overlapped or stops being overlapped.
+ *
+ * @param {Function} start_callback Function executed when a new row begins
+ * to be overlapped. The row is passed as first argument.
+ * @param {Function} stop_callback Function executed when a row stops being
+ * overlapped. The row is passed as first argument.
+ * @method on_overlapped_row_change
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.on_overlapped_row_change = function(start_callback, end_callback) {
+ if (!this.colliders_data.length) {
+ return;
+ }
+ var rows = this.get_targeted_rows(this.colliders_data[0].el.data.row);
+ var last_n_rows = this.last_rows.length;
+ var n_rows = rows.length;
+ var i;
+
+ for (i = 0; i < n_rows; i++) {
+ if ($.inArray(rows[i], this.last_rows) === -1) {
+ (start_callback || $.noop).call(this, rows[i]);
+ }
+ }
+
+ for (i = 0; i < last_n_rows; i++) {
+ if ($.inArray(this.last_rows[i], rows) === -1) {
+ (end_callback || $.noop).call(this, this.last_rows[i]);
+ }
+ }
+
+ this.last_rows = rows;
+ };
+
+
+ /**
+ * Sets the current position of the player
+ *
+ * @param {Function} start_callback Function executed when a new row begins
+ * to be overlapped. The row is passed as first argument.
+ * @param {Function} stop_callback Function executed when a row stops being
+ * overlapped. The row is passed as first argument.
+ * @method set_player
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.set_player = function(col, row, no_player) {
+ var self = this;
+ if (!no_player) {
+ this.empty_cells_player_occupies();
+ }
+ var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
+ var to_col = cell.col;
+ var to_row = row || cell.row;
+
+ this.player_grid_data = {
+ col: to_col,
+ row: to_row,
+ size_y : this.player_grid_data.size_y,
+ size_x : this.player_grid_data.size_x
+ };
+
+ this.cells_occupied_by_player = this.get_cells_occupied(
+ this.player_grid_data);
+
+ var $overlapped_widgets = this.get_widgets_overlapped(
+ this.player_grid_data);
+
+ var constraints = this.widgets_constraints($overlapped_widgets);
+
+ this.manage_movements(constraints.can_go_up, to_col, to_row);
+ this.manage_movements(constraints.can_not_go_up, to_col, to_row);
+
+ /* if there is not widgets overlapping in the new player position,
+ * update the new placeholder position. */
+ if (!$overlapped_widgets.length) {
+ var pp = this.can_go_player_up(this.player_grid_data);
+ if (pp !== false) {
+ to_row = pp;
+ }
+ this.set_placeholder(to_col, to_row);
+ }
+
+ return {
+ col: to_col,
+ row: to_row
+ };
+ };
+
+
+ /**
+ * See which of the widgets in the $widgets param collection can go to
+ * a upper row and which not.
+ *
+ * @method widgets_contraints
+ * @param {HTMLElements} $widgets A jQuery wrapped collection of
+ * HTMLElements.
+ * @return {Array} Returns a literal Object with two keys: `can_go_up` &
+ * `can_not_go_up`. Each contains a set of HTMLElements.
+ */
+ fn.widgets_constraints = function($widgets) {
+ var $widgets_can_go_up = $([]);
+ var $widgets_can_not_go_up;
+ var wgd_can_go_up = [];
+ var wgd_can_not_go_up = [];
+
+ $widgets.each($.proxy(function(i, w) {
+ var $w = $(w);
+ var wgd = $w.coords().grid;
+ if (this.can_go_widget_up(wgd)) {
+ $widgets_can_go_up = $widgets_can_go_up.add($w);
+ wgd_can_go_up.push(wgd);
+ }else{
+ wgd_can_not_go_up.push(wgd);
+ }
+ }, this));
+
+ $widgets_can_not_go_up = $widgets.not($widgets_can_go_up);
+
+ return {
+ can_go_up: this.sort_by_row_asc(wgd_can_go_up),
+ can_not_go_up: this.sort_by_row_desc(wgd_can_not_go_up)
+ };
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in ascending way.
+ *
+ * @method sort_by_row_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ fn.sort_by_row_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (!a.row) {
+ a = $(a).coords().grid;
+ b = $(b).coords().grid;
+ }
+
+ if (a.row > b.row) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) placing first the empty cells upper left.
+ *
+ * @method sort_by_row_and_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ fn.sort_by_row_and_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row > b.row || a.row === b.row && a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects by column (representing the grid
+ * coords of each widget) in ascending way.
+ *
+ * @method sort_by_col_asc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ fn.sort_by_col_asc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.col > b.col) {
+ return 1;
+ }
+ return -1;
+ });
+
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in descending way.
+ *
+ * @method sort_by_row_desc
+ * @param {Array} widgets Array of grid coords objects
+ * @return {Array} Returns the array sorted.
+ */
+ fn.sort_by_row_desc = function(widgets) {
+ widgets = widgets.sort(function(a, b) {
+ if (a.row + a.size_y < b.row + b.size_y) {
+ return 1;
+ }
+ return -1;
+ });
+ return widgets;
+ };
+
+
+ /**
+ * Sorts an Array of grid coords objects (representing the grid coords of
+ * each widget) in descending way.
+ *
+ * @method manage_movements
+ * @param {HTMLElements} $widgets A jQuery collection of HTMLElements
+ * representing the widgets you want to move.
+ * @param {Number} to_col The column to which we want to move the widgets.
+ * @param {Number} to_row The row to which we want to move the widgets.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.manage_movements = function($widgets, to_col, to_row) {
+ $.each($widgets, $.proxy(function(i, w) {
+ var wgd = w;
+ var $w = wgd.el;
+
+ var can_go_widget_up = this.can_go_widget_up(wgd);
+
+ if (can_go_widget_up) {
+ //target CAN go up
+ //so move widget up
+ this.move_widget_to($w, can_go_widget_up);
+ this.set_placeholder(to_col, can_go_widget_up + wgd.size_y);
+
+ } else {
+ //target can't go up
+ var can_go_player_up = this.can_go_player_up(
+ this.player_grid_data);
+
+ if (!can_go_player_up) {
+ // target can't go up
+ // player cant't go up
+ // so we need to move widget down to a position that dont
+ // overlaps player
+ var y = (to_row + this.player_grid_data.size_y) - wgd.row;
+
+ this.move_widget_down($w, y);
+ this.set_placeholder(to_col, to_row);
+ }
+ }
+ }, this));
+
+ return this;
+ };
+
+ /**
+ * Determines if there is a widget in the row and col given. Or if the
+ * HTMLElement passed as first argument is the player.
+ *
+ * @method is_player
+ * @param {Number|HTMLElement} col_or_el A jQuery wrapped collection of
+ * HTMLElements.
+ * @param {Number} [row] The column to which we want to move the widgets.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_player = function(col_or_el, row) {
+ if (row && !this.gridmap[col_or_el]) { return false; }
+ var $w = row ? this.gridmap[col_or_el][row] : col_or_el;
+ return $w && ($w.is(this.$player) || $w.is(this.$helper));
+ };
+
+
+ /**
+ * Determines if the widget that is being dragged is currently over the row
+ * and col given.
+ *
+ * @method is_player_in
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_player_in = function(col, row) {
+ var c = this.cells_occupied_by_player || {};
+ return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0;
+ };
+
+
+ /**
+ * Determines if the placeholder is currently over the row and col given.
+ *
+ * @method is_placeholder_in
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_placeholder_in = function(col, row) {
+ var c = this.cells_occupied_by_placeholder || {};
+ return this.is_placeholder_in_col(col) && $.inArray(row, c.rows) >= 0;
+ };
+
+
+ /**
+ * Determines if the placeholder is currently over the column given.
+ *
+ * @method is_placeholder_in_col
+ * @param {Number} col The column to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_placeholder_in_col = function(col) {
+ var c = this.cells_occupied_by_placeholder || [];
+ return $.inArray(col, c.cols) >= 0;
+ };
+
+
+ /**
+ * Determines if the cell represented by col and row params is empty.
+ *
+ * @method is_empty
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_empty = function(col, row) {
+ if (typeof this.gridmap[col] !== 'undefined' &&
+ typeof this.gridmap[col][row] !== 'undefined' &&
+ this.gridmap[col][row] === false
+ ) {
+ return true;
+ }
+ return false;
+ };
+
+
+ /**
+ * Determines if the cell represented by col and row params is occupied.
+ *
+ * @method is_occupied
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_occupied = function(col, row) {
+ if (!this.gridmap[col]) {
+ return false;
+ }
+
+ if (this.gridmap[col][row]) {
+ return true;
+ }
+ return false;
+ };
+
+
+ /**
+ * Determines if there is a widget in the cell represented by col/row params.
+ *
+ * @method is_widget
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean|HTMLElement} Returns false if there is no widget,
+ * else returns the jQuery HTMLElement
+ */
+ fn.is_widget = function(col, row) {
+ var cell = this.gridmap[col];
+ if (!cell) {
+ return false;
+ }
+
+ cell = cell[row];
+
+ if (cell) {
+ return cell;
+ }
+
+ return false;
+ };
+
+
+ /**
+ * Determines if there is a widget in the cell represented by col/row
+ * params and if this is under the widget that is being dragged.
+ *
+ * @method is_widget_under_player
+ * @param {Number} col The column to check.
+ * @param {Number} row The row to check.
+ * @return {Boolean} Returns true or false.
+ */
+ fn.is_widget_under_player = function(col, row) {
+ if (this.is_widget(col, row)) {
+ return this.is_player_in(col, row);
+ }
+ return false;
+ };
+
+
+ /**
+ * Get widgets overlapping with the player or with the object passed
+ * representing the grid cells.
+ *
+ * @method get_widgets_under_player
+ * @return {HTMLElement} Returns a jQuery collection of HTMLElements
+ */
+ fn.get_widgets_under_player = function(cells) {
+ cells || (cells = this.cells_occupied_by_player || {cols: [], rows: []});
+ var $widgets = $([]);
+
+ $.each(cells.cols, $.proxy(function(i, col) {
+ $.each(cells.rows, $.proxy(function(i, row) {
+ if(this.is_widget(col, row)) {
+ $widgets = $widgets.add(this.gridmap[col][row]);
+ }
+ }, this));
+ }, this));
+
+ return $widgets;
+ };
+
+
+ /**
+ * Put placeholder at the row and column specified.
+ *
+ * @method set_placeholder
+ * @param {Number} col The column to which we want to move the
+ * placeholder.
+ * @param {Number} row The row to which we want to move the
+ * placeholder.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.set_placeholder = function(col, row) {
+ var phgd = $.extend({}, this.placeholder_grid_data);
+ var $nexts = this.widgets_below({
+ col: phgd.col,
+ row: phgd.row,
+ size_y: phgd.size_y,
+ size_x: phgd.size_x
+ });
+
+ // Prevents widgets go out of the grid
+ var right_col = (col + phgd.size_x - 1);
+ if (right_col > this.cols) {
+ col = col - (right_col - col);
+ }
+
+ var moved_down = this.placeholder_grid_data.row < row;
+ var changed_column = this.placeholder_grid_data.col !== col;
+
+ this.placeholder_grid_data.col = col;
+ this.placeholder_grid_data.row = row;
+
+ this.cells_occupied_by_placeholder = this.get_cells_occupied(
+ this.placeholder_grid_data);
+
+ this.$preview_holder.attr({
+ 'data-row' : row,
+ 'data-col' : col
+ });
+
+ if (moved_down || changed_column) {
+ $nexts.each($.proxy(function(i, widget) {
+ this.move_widget_up(
+ $(widget), this.placeholder_grid_data.col - col + phgd.size_y);
+ }, this));
+ }
+
+
+ var $widgets_under_ph = this.get_widgets_under_player(this.cells_occupied_by_placeholder);
+ if ($widgets_under_ph.length) {
+ $widgets_under_ph.each($.proxy(function(i, widget) {
+ var $w = $(widget);
+ this.move_widget_down(
+ $w, row + phgd.size_y - $w.data('coords').grid.row);
+ }, this));
+ }
+
+ };
+
+
+ /**
+ * Determines whether the player can move to a position above.
+ *
+ * @method can_go_player_up
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * player.
+ * @return {Number|Boolean} If the player can be moved to an upper row
+ * returns the row number, else returns false.
+ */
+ fn.can_go_player_up = function(widget_grid_data) {
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var result = true;
+ var upper_rows = [];
+ var min_row = 10000;
+ var $widgets_under_player = this.get_widgets_under_player();
+
+ /* generate an array with columns as index and array with upper rows
+ * empty as value */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = this.gridmap[tcol];
+ var r = p_bottom_row + 1;
+ upper_rows[tcol] = [];
+
+ while (--r > 0) {
+ if (this.is_empty(tcol, r) || this.is_player(tcol, r) ||
+ this.is_widget(tcol, r) &&
+ grid_col[r].is($widgets_under_player)
+ ) {
+ upper_rows[tcol].push(r);
+ min_row = r < min_row ? r : min_row;
+ }else{
+ break;
+ }
+ }
+
+ if (upper_rows[tcol].length === 0) {
+ result = false;
+ return true; //break
+ }
+
+ upper_rows[tcol].sort();
+ });
+
+ if (!result) { return false; }
+
+ return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
+ };
+
+
+ /**
+ * Determines whether a widget can move to a position above.
+ *
+ * @method can_go_widget_up
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * widget we want to check.
+ * @return {Number|Boolean} If the widget can be moved to an upper row
+ * returns the row number, else returns false.
+ */
+ fn.can_go_widget_up = function(widget_grid_data) {
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var result = true;
+ var upper_rows = [];
+ var min_row = 10000;
+
+ /* generate an array with columns as index and array with topmost rows
+ * empty as value */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = this.gridmap[tcol];
+ upper_rows[tcol] = [];
+
+ var r = p_bottom_row + 1;
+ // iterate over each row
+ while (--r > 0) {
+ if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
+ if (!grid_col[r].is(widget_grid_data.el)) {
+ break;
+ }
+ }
+
+ if (!this.is_player(tcol, r) &&
+ !this.is_placeholder_in(tcol, r) &&
+ !this.is_player_in(tcol, r)) {
+ upper_rows[tcol].push(r);
+ }
+
+ if (r < min_row) {
+ min_row = r;
+ }
+ }
+
+ if (upper_rows[tcol].length === 0) {
+ result = false;
+ return true; //break
+ }
+
+ upper_rows[tcol].sort();
+ });
+
+ if (!result) { return false; }
+
+ return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
+ };
+
+
+ /**
+ * Search a valid row for the widget represented by `widget_grid_data' in
+ * the `upper_rows` array. Iteration starts from row specified in `min_row`.
+ *
+ * @method get_valid_rows
+ * @param {Object} widget_grid_data The actual grid coords object of the
+ * player.
+ * @param {Array} upper_rows An array with columns as index and arrays
+ * of valid rows as values.
+ * @param {Number} min_row The upper row from which the iteration will start.
+ * @return {Number|Boolean} Returns the upper row valid from the `upper_rows`
+ * for the widget in question.
+ */
+ fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row) {
+ var p_top_row = widget_grid_data.row;
+ var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
+ var size_y = widget_grid_data.size_y;
+ var r = min_row - 1;
+ var valid_rows = [];
+
+ while (++r <= p_bottom_row ) {
+ var common = true;
+ $.each(upper_rows, function(col, rows) {
+ if ($.isArray(rows) && $.inArray(r, rows) === -1) {
+ common = false;
+ }
+ });
+
+ if (common === true) {
+ valid_rows.push(r);
+ if (valid_rows.length === size_y) {
+ break;
+ }
+ }
+ }
+
+ var new_row = false;
+ if (size_y === 1) {
+ if (valid_rows[0] !== p_top_row) {
+ new_row = valid_rows[0] || false;
+ }
+ }else{
+ if (valid_rows[0] !== p_top_row) {
+ new_row = this.get_consecutive_numbers_index(
+ valid_rows, size_y);
+ }
+ }
+
+ return new_row;
+ };
+
+
+ fn.get_consecutive_numbers_index = function(arr, size_y) {
+ var max = arr.length;
+ var result = [];
+ var first = true;
+ var prev = -1; // or null?
+
+ for (var i=0; i < max; i++) {
+ if (first || arr[i] === prev + 1) {
+ result.push(i);
+ if (result.length === size_y) {
+ break;
+ }
+ first = false;
+ }else{
+ result = [];
+ first = true;
+ }
+
+ prev = arr[i];
+ }
+
+ return result.length >= size_y ? arr[result[0]] : false;
+ };
+
+
+ /**
+ * Get widgets overlapping with the player.
+ *
+ * @method get_widgets_overlapped
+ * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ */
+ fn.get_widgets_overlapped = function() {
+ var $w;
+ var $widgets = $([]);
+ var used = [];
+ var rows_from_bottom = this.cells_occupied_by_player.rows.slice(0);
+ rows_from_bottom.reverse();
+
+ $.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col) {
+ $.each(rows_from_bottom, $.proxy(function(i, row) {
+ // if there is a widget in the player position
+ if (!this.gridmap[col]) { return true; } //next iteration
+ var $w = this.gridmap[col][row];
+ if (this.is_occupied(col, row) && !this.is_player($w) &&
+ $.inArray($w, used) === -1
+ ) {
+ $widgets = $widgets.add($w);
+ used.push($w);
+ }
+
+ }, this));
+ }, this));
+
+ return $widgets;
+ };
+
+
+ /**
+ * This callback is executed when the player begins to collide with a column.
+ *
+ * @method on_start_overlapping_column
+ * @param {Number} col The collided column.
+ * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_start_overlapping_column = function(col) {
+ this.set_player(col, false);
+ };
+
+
+ /**
+ * A callback executed when the player begins to collide with a row.
+ *
+ * @method on_start_overlapping_row
+ * @param {Number} col The collided row.
+ * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_start_overlapping_row = function(row) {
+ this.set_player(false, row);
+ };
+
+
+ /**
+ * A callback executed when the the player ends to collide with a column.
+ *
+ * @method on_stop_overlapping_column
+ * @param {Number} col The collided row.
+ * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_stop_overlapping_column = function(col) {
+ this.set_player(col, false);
+
+ var self = this;
+ this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
+ function(tcol, trow) {
+ self.move_widget_up(this, self.player_grid_data.size_y);
+ });
+ };
+
+
+ /**
+ * This callback is executed when the player ends to collide with a row.
+ *
+ * @method on_stop_overlapping_row
+ * @param {Number} row The collided row.
+ * @return {HTMLElements} Returns a jQuery collection of HTMLElements.
+ */
+ fn.on_stop_overlapping_row = function(row) {
+ this.set_player(false, row);
+
+ var self = this;
+ var cols = this.cells_occupied_by_player.cols;
+ for (var c = 0, cl = cols.length; c < cl; c++) {
+ this.for_each_widget_below(cols[c], row, function(tcol, trow) {
+ self.move_widget_up(this, self.player_grid_data.size_y);
+ });
+ }
+ };
+
+
+ /**
+ * Move a widget to a specific row. The cell or cells must be empty.
+ * If the widget has widgets below, all of these widgets will be moved also
+ * if they can.
+ *
+ * @method move_widget_to
+ * @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the
+ * widget is going to be moved.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_to = function($widget, row) {
+ var self = this;
+ var widget_grid_data = $widget.coords().grid;
+ var diff = row - widget_grid_data.row;
+ var $next_widgets = this.widgets_below($widget);
+
+ var can_move_to_new_cell = this.can_move_to(
+ widget_grid_data, widget_grid_data.col, row, $widget);
+
+ if (can_move_to_new_cell === false) {
+ return false;
+ }
+
+ this.remove_from_gridmap(widget_grid_data);
+ widget_grid_data.row = row;
+ this.add_to_gridmap(widget_grid_data);
+ $widget.attr('data-row', row);
+ this.$changed = this.$changed.add($widget);
+
+
+ $next_widgets.each(function(i, widget) {
+ var $w = $(widget);
+ var wgd = $w.coords().grid;
+ var can_go_up = self.can_go_widget_up(wgd);
+ if (can_go_up && can_go_up !== wgd.row) {
+ self.move_widget_to($w, can_go_up);
+ }
+ });
+
+ return this;
+ };
+
+
+ /**
+ * Move up the specified widget and all below it.
+ *
+ * @method move_widget_up
+ * @param {HTMLElement} $widget The widget you want to move.
+ * @param {Number} [y_units] The number of cells that the widget has to move.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_up = function($widget, y_units) {
+ var el_grid_data = $widget.coords().grid;
+ var actual_row = el_grid_data.row;
+ var moved = [];
+ var can_go_up = true;
+ y_units || (y_units = 1);
+
+ if (!this.can_go_up($widget)) { return false; } //break;
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ // can_go_up
+ if ($.inArray($widget, moved) === -1) {
+ var widget_grid_data = $widget.coords().grid;
+ var next_row = actual_row - y_units;
+ next_row = this.can_go_up_to_row(
+ widget_grid_data, col, next_row);
+
+ if (!next_row) {
+ return true;
+ }
+
+ var $next_widgets = this.widgets_below($widget);
+
+ this.remove_from_gridmap(widget_grid_data);
+ widget_grid_data.row = next_row;
+ this.add_to_gridmap(widget_grid_data);
+ $widget.attr('data-row', widget_grid_data.row);
+ this.$changed = this.$changed.add($widget);
+
+ moved.push($widget);
+
+ $next_widgets.each($.proxy(function(i, widget) {
+ this.move_widget_up($(widget), y_units);
+ }, this));
+ }
+ });
+
+ };
+
+
+ /**
+ * Move down the specified widget and all below it.
+ *
+ * @method move_widget_down
+ * @param {HTMLElement} $widget The jQuery object representing the widget
+ * you want to move.
+ * @param {Number} The number of cells that the widget has to move.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.move_widget_down = function($widget, y_units) {
+ var el_grid_data = $widget.coords().grid;
+ var actual_row = el_grid_data.row;
+ var moved = [];
+ var y_diff = y_units;
+
+ if (!$widget) { return false; }
+
+ if ($.inArray($widget, moved) === -1) {
+
+ var widget_grid_data = $widget.coords().grid;
+ var next_row = actual_row + y_units;
+ var $next_widgets = this.widgets_below($widget);
+
+ this.remove_from_gridmap(widget_grid_data);
+
+ $next_widgets.each($.proxy(function(i, widget) {
+ var $w = $(widget);
+ var wd = $w.coords().grid;
+ var tmp_y = this.displacement_diff(
+ wd, widget_grid_data, y_diff);
+
+ if (tmp_y > 0) {
+ this.move_widget_down($w, tmp_y);
+ }
+ }, this));
+
+ widget_grid_data.row = next_row;
+ this.update_widget_position(widget_grid_data, $widget);
+ $widget.attr('data-row', widget_grid_data.row);
+ this.$changed = this.$changed.add($widget);
+
+ moved.push($widget);
+ }
+ };
+
+
+ /**
+ * Check if the widget can move to the specified row, else returns the
+ * upper row possible.
+ *
+ * @method can_go_up_to_row
+ * @param {Number} widget_grid_data The current grid coords object of the
+ * widget.
+ * @param {Number} col The target column.
+ * @param {Number} row The target row.
+ * @return {Boolean|Number} Returns the row number if the widget can move
+ * to the target position, else returns false.
+ */
+ fn.can_go_up_to_row = function(widget_grid_data, col, row) {
+ var ga = this.gridmap;
+ var result = true;
+ var urc = []; // upper_rows_in_columns
+ var actual_row = widget_grid_data.row;
+ var r;
+
+ /* generate an array with columns as index and array with
+ * upper rows empty in the column */
+ this.for_each_column_occupied(widget_grid_data, function(tcol) {
+ var grid_col = ga[tcol];
+ urc[tcol] = [];
+
+ r = actual_row;
+ while (r--) {
+ if (this.is_empty(tcol, r) &&
+ !this.is_placeholder_in(tcol, r)
+ ) {
+ urc[tcol].push(r);
+ }else{
+ break;
+ }
+ }
+
+ if (!urc[tcol].length) {
+ result = false;
+ return true;
+ }
+
+ });
+
+ if (!result) { return false; }
+
+ /* get common rows starting from upper position in all the columns
+ * that widget occupies */
+ r = row;
+ for (r = 1; r < actual_row; r++) {
+ var common = true;
+
+ for (var uc = 0, ucl = urc.length; uc < ucl; uc++) {
+ if (urc[uc] && $.inArray(r, urc[uc]) === -1) {
+ common = false;
+ }
+ }
+
+ if (common === true) {
+ result = r;
+ break;
+ }
+ }
+
+ return result;
+ };
+
+
+ fn.displacement_diff = function(widget_grid_data, parent_bgd, y_units) {
+ var actual_row = widget_grid_data.row;
+ var diffs = [];
+ var parent_max_y = parent_bgd.row + parent_bgd.size_y;
+
+ this.for_each_column_occupied(widget_grid_data, function(col) {
+ var temp_y_units = 0;
+
+ for (var r = parent_max_y; r < actual_row; r++) {
+ if (this.is_empty(col, r)) {
+ temp_y_units = temp_y_units + 1;
+ }
+ }
+
+ diffs.push(temp_y_units);
+ });
+
+ var max_diff = Math.max.apply(Math, diffs);
+ y_units = (y_units - max_diff);
+
+ return y_units > 0 ? y_units : 0;
+ };
+
+
+ /**
+ * Get widgets below a widget.
+ *
+ * @method widgets_below
+ * @param {HTMLElement} $el The jQuery wrapped HTMLElement.
+ * @return {HTMLElements} A jQuery collection of HTMLElements.
+ */
+ fn.widgets_below = function($el) {
+ var el_grid_data = $.isPlainObject($el) ? $el : $el.coords().grid;
+ var self = this;
+ var ga = this.gridmap;
+ var next_row = el_grid_data.row + el_grid_data.size_y - 1;
+ var $nexts = $([]);
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ self.for_each_widget_below(col, next_row, function(tcol, trow) {
+ if (!self.is_player(this) && $.inArray(this, $nexts) === -1) {
+ $nexts = $nexts.add(this);
+ return true; // break
+ }
+ });
+ });
+
+ return this.sort_by_row_asc($nexts);
+ };
+
+
+ /**
+ * Update the array of mapped positions with the new player position.
+ *
+ * @method set_cells_player_occupies
+ * @param {Number} col The new player col.
+ * @param {Number} col The new player row.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.set_cells_player_occupies = function(col, row) {
+ this.remove_from_gridmap(this.placeholder_grid_data);
+ this.placeholder_grid_data.col = col;
+ this.placeholder_grid_data.row = row;
+ this.add_to_gridmap(this.placeholder_grid_data, this.$player);
+ return this;
+ };
+
+
+ /**
+ * Remove from the array of mapped positions the reference to the player.
+ *
+ * @method empty_cells_player_occupies
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.empty_cells_player_occupies = function() {
+ this.remove_from_gridmap(this.placeholder_grid_data);
+ return this;
+ };
+
+
+ fn.can_go_up = function($el) {
+ var el_grid_data = $el.coords().grid;
+ var initial_row = el_grid_data.row;
+ var prev_row = initial_row - 1;
+ var ga = this.gridmap;
+ var upper_rows_by_column = [];
+
+ var result = true;
+ if (initial_row === 1) { return false; }
+
+ this.for_each_column_occupied(el_grid_data, function(col) {
+ var $w = this.is_widget(col, prev_row);
+
+ if (this.is_occupied(col, prev_row) ||
+ this.is_player(col, prev_row) ||
+ this.is_placeholder_in(col, prev_row) ||
+ this.is_player_in(col, prev_row)
+ ) {
+ result = false;
+ return true; //break
+ }
+ });
+
+ return result;
+ };
+
+
+
+ /**
+ * Check if it's possible to move a widget to a specific col/row. It takes
+ * into account the dimensions (`size_y` and `size_x` attrs. of the grid
+ * coords object) the widget occupies.
+ *
+ * @method can_move_to
+ * @param {Object} widget_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Object} col The col to check.
+ * @param {Object} row The row to check.
+ * @param {Number} [max_row] The max row allowed.
+ * @return {Boolean} Returns true if all cells are empty, else return false.
+ */
+ fn.can_move_to = function(widget_grid_data, col, row, max_row) {
+ var ga = this.gridmap;
+ var $w = widget_grid_data.el;
+ var future_wd = {
+ size_y: widget_grid_data.size_y,
+ size_x: widget_grid_data.size_x,
+ col: col,
+ row: row
+ };
+ var result = true;
+
+ //Prevents widgets go out of the grid
+ var right_col = col + widget_grid_data.size_x - 1;
+ if (right_col > this.cols) {
+ return false;
+ }
+
+ if (max_row && max_row < row + widget_grid_data.size_y - 1) {
+ return false;
+ }
+
+ this.for_each_cell_occupied(future_wd, function(tcol, trow) {
+ var $tw = this.is_widget(tcol, trow);
+ if ($tw && (!widget_grid_data.el || $tw.is($w))) {
+ result = false;
+ }
+ });
+
+ return result;
+ };
+
+
+ /**
+ * Given the leftmost column returns all columns that are overlapping
+ * with the player.
+ *
+ * @method get_targeted_columns
+ * @param {Number} [from_col] The leftmost column.
+ * @return {Array} Returns an array with column numbers.
+ */
+ fn.get_targeted_columns = function(from_col) {
+ var max = (from_col || this.player_grid_data.col) +
+ (this.player_grid_data.size_x - 1);
+ var cols = [];
+ for (var col = from_col; col <= max; col++) {
+ cols.push(col);
+ }
+ return cols;
+ };
+
+
+ /**
+ * Given the upper row returns all rows that are overlapping with the player.
+ *
+ * @method get_targeted_rows
+ * @param {Number} [from_row] The upper row.
+ * @return {Array} Returns an array with row numbers.
+ */
+ fn.get_targeted_rows = function(from_row) {
+ var max = (from_row || this.player_grid_data.row) +
+ (this.player_grid_data.size_y - 1);
+ var rows = [];
+ for (var row = from_row; row <= max; row++) {
+ rows.push(row);
+ }
+ return rows;
+ };
+
+ /**
+ * Get all columns and rows that a widget occupies.
+ *
+ * @method get_cells_occupied
+ * @param {Object} el_grid_data The grid coords object of the widget.
+ * @return {Object} Returns an object like `{ cols: [], rows: []}`.
+ */
+ fn.get_cells_occupied = function(el_grid_data) {
+ var cells = { cols: [], rows: []};
+ var i;
+ if (arguments[1] instanceof jQuery) {
+ el_grid_data = arguments[1].coords().grid;
+ }
+
+ for (i = 0; i < el_grid_data.size_x; i++) {
+ var col = el_grid_data.col + i;
+ cells.cols.push(col);
+ }
+
+ for (i = 0; i < el_grid_data.size_y; i++) {
+ var row = el_grid_data.row + i;
+ cells.rows.push(row);
+ }
+
+ return cells;
+ };
+
+
+ /**
+ * Iterate over the cells occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_cell_occupied
+ * @param {Object} el_grid_data The grid coords object that represents the
+ * widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. Column and row are passed as arguments.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_cell_occupied = function(grid_data, callback) {
+ this.for_each_column_occupied(grid_data, function(col) {
+ this.for_each_row_occupied(grid_data, function(row) {
+ callback.call(this, col, row);
+ });
+ });
+ return this;
+ };
+
+
+ /**
+ * Iterate over the columns occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_column_occupied
+ * @param {Object} el_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. The column number is passed as first argument.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_column_occupied = function(el_grid_data, callback) {
+ for (var i = 0; i < el_grid_data.size_x; i++) {
+ var col = el_grid_data.col + i;
+ callback.call(this, col, el_grid_data);
+ }
+ };
+
+
+ /**
+ * Iterate over the rows occupied by a widget executing a function for
+ * each one.
+ *
+ * @method for_each_row_occupied
+ * @param {Object} el_grid_data The grid coords object that represents
+ * the widget.
+ * @param {Function} callback The function to execute on each column
+ * iteration. The row number is passed as first argument.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_row_occupied = function(el_grid_data, callback) {
+ for (var i = 0; i < el_grid_data.size_y; i++) {
+ var row = el_grid_data.row + i;
+ callback.call(this, row, el_grid_data);
+ }
+ };
+
+
+
+ fn._traversing_widgets = function(type, direction, col, row, callback) {
+ var ga = this.gridmap;
+ if (!ga[col]) { return; }
+
+ var cr, max;
+ var action = type + '/' + direction;
+ if (arguments[2] instanceof jQuery) {
+ var el_grid_data = arguments[2].coords().grid;
+ col = el_grid_data.col;
+ row = el_grid_data.row;
+ callback = arguments[3];
+ }
+ var matched = [];
+ var trow = row;
+
+
+ var methods = {
+ 'for_each/above': function() {
+ while (trow--) {
+ if (trow > 0 && this.is_widget(col, trow) &&
+ $.inArray(ga[col][trow], matched) === -1
+ ) {
+ cr = callback.call(ga[col][trow], col, trow);
+ matched.push(ga[col][trow]);
+ if (cr) { break; }
+ }
+ }
+ },
+ 'for_each/below': function() {
+ for (trow = row + 1, max = ga[col].length; trow < max; trow++) {
+ if (this.is_widget(col, trow) &&
+ $.inArray(ga[col][trow], matched) === -1
+ ) {
+ cr = callback.call(ga[col][trow], col, trow);
+ matched.push(ga[col][trow]);
+ if (cr) { break; }
+ }
+ }
+ }
+ };
+
+ if (methods[action]) {
+ methods[action].call(this);
+ }
+ };
+
+
+ /**
+ * Iterate over each widget above the column and row specified.
+ *
+ * @method for_each_widget_above
+ * @param {Number} col The column to start iterating.
+ * @param {Number} row The row to start iterating.
+ * @param {Function} callback The function to execute on each widget
+ * iteration. The value of `this` inside the function is the jQuery
+ * wrapped HTMLElement.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_widget_above = function(col, row, callback) {
+ this._traversing_widgets('for_each', 'above', col, row, callback);
+ return this;
+ };
+
+
+ /**
+ * Iterate over each widget below the column and row specified.
+ *
+ * @method for_each_widget_below
+ * @param {Number} col The column to start iterating.
+ * @param {Number} row The row to start iterating.
+ * @param {Function} callback The function to execute on each widget
+ * iteration. The value of `this` inside the function is the jQuery wrapped
+ * HTMLElement.
+ * @return {Class} Returns the instance of the Gridster Class.
+ */
+ fn.for_each_widget_below = function(col, row, callback) {
+ this._traversing_widgets('for_each', 'below', col, row, callback);
+ return this;
+ };
+
+
+ /**
+ * Returns the highest occupied cell in the grid.
+ *
+ * @method get_highest_occupied_cell
+ * @return {Object} Returns an object with `col` and `row` numbers.
+ */
+ fn.get_highest_occupied_cell = function() {
+ var r;
+ var gm = this.gridmap;
+ var rows = [];
+ var row_in_col = [];
+ for (var c = gm.length - 1; c >= 1; c--) {
+ for (r = gm[c].length - 1; r >= 1; r--) {
+ if (this.is_widget(c, r)) {
+ rows.push(r);
+ row_in_col[r] = c;
+ break;
+ }
+ }
+ }
+
+ var highest_row = Math.max.apply(Math, rows);
+
+ this.highest_occupied_cell = {
+ col: row_in_col[highest_row],
+ row: highest_row
+ };
+
+ return this.highest_occupied_cell;
+ };
+
+
+ fn.get_widgets_from = function(col, row) {
+ var ga = this.gridmap;
+ var $widgets = $();
+
+ if (col) {
+ $widgets = $widgets.add(
+ this.$widgets.filter(function() {
+ var tcol = $(this).attr('data-col');
+ return (tcol === col || tcol > col);
+ })
+ );
+ }
+
+ if (row) {
+ $widgets = $widgets.add(
+ this.$widgets.filter(function() {
+ var trow = $(this).attr('data-row');
+ return (trow === row || trow > row);
+ })
+ );
+ }
+
+ return $widgets;
+ };
+
+
+ /**
+ * Set the current height of the parent grid.
+ *
+ * @method set_dom_grid_height
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.set_dom_grid_height = function() {
+ var r = this.get_highest_occupied_cell().row;
+ this.$el.css('height', r * this.min_widget_height);
+ return this;
+ };
+
+
+ /**
+ * It generates the neccessary styles to position the widgets.
+ *
+ * @method generate_stylesheet
+ * @param {Number} rows Number of columns.
+ * @param {Number} cols Number of rows.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_stylesheet = function(opts) {
+ var styles = '';
+ var max_size_x = this.options.max_size_x;
+ var max_rows = 0;
+ var max_cols = 0;
+ var i;
+ var rules;
+
+ opts || (opts = {});
+ opts.cols || (opts.cols = this.cols);
+ opts.rows || (opts.rows = this.rows);
+ opts.namespace || (opts.namespace = this.options.namespace);
+ opts.widget_base_dimensions ||
+ (opts.widget_base_dimensions = this.options.widget_base_dimensions);
+ opts.widget_margins ||
+ (opts.widget_margins = this.options.widget_margins);
+ opts.min_widget_width = (opts.widget_margins[0] * 2) +
+ opts.widget_base_dimensions[0];
+ opts.min_widget_height = (opts.widget_margins[1] * 2) +
+ opts.widget_base_dimensions[1];
+
+ // don't duplicate stylesheets for the same configuration
+ var serialized_opts = $.param(opts);
+ if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
+ return false;
+ }
+
+ Gridster.generated_stylesheets.push(serialized_opts);
+
+ /* generate CSS styles for cols */
+ for (i = opts.cols; i >= 0; i--) {
+ styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
+ ((i * opts.widget_base_dimensions[0]) +
+ (i * opts.widget_margins[0]) +
+ ((i + 1) * opts.widget_margins[0])) + 'px;} ');
+ }
+
+ /* generate CSS styles for rows */
+ for (i = opts.rows; i >= 0; i--) {
+ styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
+ ((i * opts.widget_base_dimensions[1]) +
+ (i * opts.widget_margins[1]) +
+ ((i + 1) * opts.widget_margins[1]) ) + 'px;} ');
+ }
+
+ for (var y = 1; y <= opts.rows; y++) {
+ styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
+ (y * opts.widget_base_dimensions[1] +
+ (y - 1) * (opts.widget_margins[1] * 2)) + 'px;}');
+ }
+
+ for (var x = 1; x <= max_size_x; x++) {
+ styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
+ (x * opts.widget_base_dimensions[0] +
+ (x - 1) * (opts.widget_margins[0] * 2)) + 'px;}');
+ }
+
+ return this.add_style_tag(styles);
+ };
+
+
+ /**
+ * Injects the given CSS as string to the head of the document.
+ *
+ * @method add_style_tag
+ * @param {String} css The styles to apply.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_style_tag = function(css) {
+ var d = document;
+ var tag = d.createElement('style');
+
+ d.getElementsByTagName('head')[0].appendChild(tag);
+ tag.setAttribute('type', 'text/css');
+
+ if (tag.styleSheet) {
+ tag.styleSheet.cssText = css;
+ }else{
+ tag.appendChild(document.createTextNode(css));
+ }
+ return this;
+ };
+
+
+ /**
+ * Generates a faux grid to collide with it when a widget is dragged and
+ * detect row or column that we want to go.
+ *
+ * @method generate_faux_grid
+ * @param {Number} rows Number of columns.
+ * @param {Number} cols Number of rows.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_faux_grid = function(rows, cols) {
+ this.faux_grid = [];
+ this.gridmap = [];
+ var col;
+ var row;
+ for (col = cols; col > 0; col--) {
+ this.gridmap[col] = [];
+ for (row = rows; row > 0; row--) {
+ this.add_faux_cell(row, col);
+ }
+ }
+ return this;
+ };
+
+
+ /**
+ * Add cell to the faux grid.
+ *
+ * @method add_faux_cell
+ * @param {Number} row The row for the new faux cell.
+ * @param {Number} col The col for the new faux cell.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cell = function(row, col) {
+ var coords = $({
+ left: this.baseX + ((col - 1) * this.min_widget_width),
+ top: this.baseY + (row -1) * this.min_widget_height,
+ width: this.min_widget_width,
+ height: this.min_widget_height,
+ col: col,
+ row: row,
+ original_col: col,
+ original_row: row
+ }).coords();
+
+ if (!$.isArray(this.gridmap[col])) {
+ this.gridmap[col] = [];
+ }
+
+ this.gridmap[col][row] = false;
+ this.faux_grid.push(coords);
+
+ return this;
+ };
+
+
+ /**
+ * Add rows to the faux grid.
+ *
+ * @method add_faux_rows
+ * @param {Number} rows The number of rows you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_rows = function(rows) {
+ var actual_rows = this.rows;
+ var max_rows = actual_rows + (rows || 1);
+
+ for (var r = max_rows; r > actual_rows; r--) {
+ for (var c = this.cols; c >= 1; c--) {
+ this.add_faux_cell(r, c);
+ }
+ }
+
+ this.rows = max_rows;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this;
+ };
+
+ /**
+ * Add cols to the faux grid.
+ *
+ * @method add_faux_cols
+ * @param {Number} cols The number of cols you want to add to the faux grid.
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.add_faux_cols = function(cols) {
+ var actual_cols = this.cols;
+ var max_cols = actual_cols + (cols || 1);
+
+ for (var c = actual_cols; c < max_cols; c++) {
+ for (var r = this.rows; r >= 1; r--) {
+ this.add_faux_cell(r, c);
+ }
+ }
+
+ this.cols = max_cols;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this;
+ };
+
+
+ /**
+ * Recalculates the offsets for the faux grid. You need to use it when
+ * the browser is resized.
+ *
+ * @method recalculate_faux_grid
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.recalculate_faux_grid = function() {
+ var aw = this.$wrapper.width();
+ this.baseX = ($(window).width() - aw) / 2;
+ this.baseY = this.$wrapper.offset().top;
+
+ $.each(this.faux_grid, $.proxy(function(i, coords) {
+ this.faux_grid[i] = coords.update({
+ left: this.baseX + (coords.data.col -1) * this.min_widget_width,
+ top: this.baseY + (coords.data.row -1) * this.min_widget_height
+ });
+
+ }, this));
+
+ return this;
+ };
+
+
+ /**
+ * Get all widgets in the DOM and register them.
+ *
+ * @method get_widgets_from_DOM
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.get_widgets_from_DOM = function() {
+ this.$widgets.each($.proxy(function(i, widget) {
+ this.register_widget($(widget));
+ }, this));
+ return this;
+ };
+
+
+ /**
+ * Calculate columns and rows to be set based on the configuration
+ * parameters, grid dimensions, etc ...
+ *
+ * @method generate_grid_and_stylesheet
+ * @return {Object} Returns the instance of the Gridster class.
+ */
+ fn.generate_grid_and_stylesheet = function() {
+ var aw = this.$wrapper.width();
+ var ah = this.$wrapper.height();
+
+ var cols = Math.floor(aw / this.min_widget_width) +
+ this.options.extra_cols;
+
+ var actual_cols = this.$widgets.map(function() {
+ return $(this).attr('data-col');
+ });
+ actual_cols = Array.prototype.slice.call(actual_cols, 0);
+ //needed to pass tests with phantomjs
+ actual_cols.length || (actual_cols = [0]);
+
+ var min_cols = Math.max.apply(Math, actual_cols);
+
+ // get all rows that could be occupied by the current widgets
+ var max_rows = this.options.extra_rows;
+ this.$widgets.each(function(i, w) {
+ max_rows += (+$(w).attr('data-sizey'));
+ });
+
+
+ this.cols = Math.max(min_cols, cols, this.options.min_cols);
+ this.rows = Math.max(max_rows, this.options.min_rows);
+
+ this.baseX = ($(window).width() - aw) / 2;
+ this.baseY = this.$wrapper.offset().top;
+
+ if (this.options.autogenerate_stylesheet) {
+ this.generate_stylesheet();
+ }
+
+ return this.generate_faux_grid(this.rows, this.cols);
+ };
+
+
+ //jQuery adapter
+ $.fn.gridster = function(options) {
+ return this.each(function() {
+ if (!$(this).data('gridster')) {
+ $(this).data('gridster', new Gridster( this, options ));
+ }
+ });
+ };
+
+ $.Gridster = fn;
+
+}(jQuery, window, document));
diff --git a/app/assets/javascripts/desktop/jquery.miniColors.min.js b/app/assets/javascripts/desktop/jquery.miniColors.min.js
new file mode 100755
index 00000000..25dcfa0e
--- /dev/null
+++ b/app/assets/javascripts/desktop/jquery.miniColors.min.js
@@ -0,0 +1,9 @@
+/*
+ * jQuery miniColors: A small color selector
+ *
+ * Copyright 2011 Cory LaViska for A Beautiful Site, LLC. (http://abeautifulsite.net/)
+ *
+ * Dual licensed under the MIT or GPL Version 2 licenses
+ *
+*/
+if(jQuery)(function($){$.extend($.fn,{miniColors:function(o,data){var create=function(input,o,data){var color=expandHex(input.val());if(!color)color='ffffff';var hsb=hex2hsb(color);var trigger=$('');trigger.insertAfter(input);input.addClass('miniColors').data('original-maxlength',input.attr('maxlength')||null).data('original-autocomplete',input.attr('autocomplete')||null).data('letterCase','uppercase').data('trigger',trigger).data('hsb',hsb).data('change',o.change?o.change:null).attr('maxlength',7).attr('autocomplete','off').val('#'+convertCase(color,o.letterCase));if(o.readonly)input.prop('readonly',true);if(o.disabled)disable(input);trigger.bind('click.miniColors',function(event){event.preventDefault();if(input.val()==='')input.val('#');show(input)});input.bind('focus.miniColors',function(event){if(input.val()==='')input.val('#');show(input)});input.bind('blur.miniColors',function(event){var hex=expandHex(input.val());input.val(hex?'#'+convertCase(hex,input.data('letterCase')):'')});input.bind('keydown.miniColors',function(event){if(event.keyCode===9)hide(input)});input.bind('keyup.miniColors',function(event){setColorFromInput(input)});input.bind('paste.miniColors',function(event){setTimeout(function(){setColorFromInput(input)},5)})};var destroy=function(input){hide();input=$(input);input.data('trigger').remove();input.attr('autocomplete',input.data('original-autocomplete')).attr('maxlength',input.data('original-maxlength')).removeData().removeClass('miniColors').unbind('.miniColors');$(document).unbind('.miniColors')};var enable=function(input){input.prop('disabled',false).data('trigger').css('opacity',1)};var disable=function(input){hide(input);input.prop('disabled',true).data('trigger').css('opacity',0.5)};var show=function(input){if(input.prop('disabled'))return false;hide();var selector=$('');selector.append('').append('').css({top:input.is(':visible')?input.offset().top+input.outerHeight():input.data('trigger').offset().top+input.data('trigger').outerHeight(),left:input.is(':visible')?input.offset().left:input.data('trigger').offset().left,display:'none'}).addClass(input.attr('class'));var hsb=input.data('hsb');selector.find('.miniColors-colors').css('backgroundColor','#'+hsb2hex({h:hsb.h,s:100,b:100}));var colorPosition=input.data('colorPosition');if(!colorPosition)colorPosition=getColorPositionFromHSB(hsb);selector.find('.miniColors-colorPicker').css('top',colorPosition.y+'px').css('left',colorPosition.x+'px');var huePosition=input.data('huePosition');if(!huePosition)huePosition=getHuePositionFromHSB(hsb);selector.find('.miniColors-huePicker').css('top',huePosition.y+'px');input.data('selector',selector).data('huePicker',selector.find('.miniColors-huePicker')).data('colorPicker',selector.find('.miniColors-colorPicker')).data('mousebutton',0);$('BODY').append(selector);selector.fadeIn(100);selector.bind('selectstart',function(){return false});$(document).bind('mousedown.miniColors touchstart.miniColors',function(event){input.data('mousebutton',1);if($(event.target).parents().andSelf().hasClass('miniColors-colors')){event.preventDefault();input.data('moving','colors');moveColor(input,event)}if($(event.target).parents().andSelf().hasClass('miniColors-hues')){event.preventDefault();input.data('moving','hues');moveHue(input,event)}if($(event.target).parents().andSelf().hasClass('miniColors-selector')){event.preventDefault();return}if($(event.target).parents().andSelf().hasClass('miniColors'))return;hide(input)});$(document).bind('mouseup.miniColors touchend.miniColors',function(event){event.preventDefault();input.data('mousebutton',0).removeData('moving')}).bind('mousemove.miniColors touchmove.miniColors',function(event){event.preventDefault();if(input.data('mousebutton')===1){if(input.data('moving')==='colors')moveColor(input,event);if(input.data('moving')==='hues')moveHue(input,event)}})};var hide=function(input){if(!input)input='.miniColors';$(input).each(function(){var selector=$(this).data('selector');$(this).removeData('selector');$(selector).fadeOut(100,function(){$(this).remove()})});$(document).unbind('.miniColors')};var moveColor=function(input,event){var colorPicker=input.data('colorPicker');colorPicker.hide();var position={x:event.pageX,y:event.pageY};if(event.originalEvent.changedTouches){position.x=event.originalEvent.changedTouches[0].pageX;position.y=event.originalEvent.changedTouches[0].pageY}position.x=position.x-input.data('selector').find('.miniColors-colors').offset().left-5;position.y=position.y-input.data('selector').find('.miniColors-colors').offset().top-5;if(position.x<=-5)position.x=-5;if(position.x>=144)position.x=144;if(position.y<=-5)position.y=-5;if(position.y>=144)position.y=144;input.data('colorPosition',position);colorPicker.css('left',position.x).css('top',position.y).show();var s=Math.round((position.x+5)*0.67);if(s<0)s=0;if(s>100)s=100;var b=100-Math.round((position.y+5)*0.67);if(b<0)b=0;if(b>100)b=100;var hsb=input.data('hsb');hsb.s=s;hsb.b=b;setColor(input,hsb,true)};var moveHue=function(input,event){var huePicker=input.data('huePicker');huePicker.hide();var position={y:event.pageY};if(event.originalEvent.changedTouches){position.y=event.originalEvent.changedTouches[0].pageY}position.y=position.y-input.data('selector').find('.miniColors-colors').offset().top-1;if(position.y<=-1)position.y=-1;if(position.y>=149)position.y=149;input.data('huePosition',position);huePicker.css('top',position.y).show();var h=Math.round((150-position.y-1)*2.4);if(h<0)h=0;if(h>360)h=360;var hsb=input.data('hsb');hsb.h=h;setColor(input,hsb,true)};var setColor=function(input,hsb,updateInput){input.data('hsb',hsb);var hex=hsb2hex(hsb);if(updateInput)input.val('#'+convertCase(hex,input.data('letterCase')));input.data('trigger').css('backgroundColor','#'+hex);if(input.data('selector'))input.data('selector').find('.miniColors-colors').css('backgroundColor','#'+hsb2hex({h:hsb.h,s:100,b:100}));if(input.data('change')){if(hex===input.data('lastChange'))return;input.data('change').call(input.get(0),'#'+hex,hsb2rgb(hsb));input.data('lastChange',hex)}};var setColorFromInput=function(input){input.val('#'+cleanHex(input.val()));var hex=expandHex(input.val());if(!hex)return false;var hsb=hex2hsb(hex);var currentHSB=input.data('hsb');if(hsb.h===currentHSB.h&&hsb.s===currentHSB.s&&hsb.b===currentHSB.b)return true;var colorPosition=getColorPositionFromHSB(hsb);var colorPicker=$(input.data('colorPicker'));colorPicker.css('top',colorPosition.y+'px').css('left',colorPosition.x+'px');input.data('colorPosition',colorPosition);var huePosition=getHuePositionFromHSB(hsb);var huePicker=$(input.data('huePicker'));huePicker.css('top',huePosition.y+'px');input.data('huePosition',huePosition);setColor(input,hsb);return true};var convertCase=function(string,letterCase){if(letterCase==='lowercase')return string.toLowerCase();if(letterCase==='uppercase')return string.toUpperCase();return string};var getColorPositionFromHSB=function(hsb){var x=Math.ceil(hsb.s/0.67);if(x<0)x=0;if(x>150)x=150;var y=150-Math.ceil(hsb.b/0.67);if(y<0)y=0;if(y>150)y=150;return{x:x-5,y:y-5}};var getHuePositionFromHSB=function(hsb){var y=150-(hsb.h/2.4);if(y<0)h=0;if(y>150)h=150;return{y:y-1}};var cleanHex=function(hex){return hex.replace(/[^A-F0-9]/ig,'')};var expandHex=function(hex){hex=cleanHex(hex);if(!hex)return null;if(hex.length===3)hex=hex[0]+hex[0]+hex[1]+hex[1]+hex[2]+hex[2];return hex.length===6?hex:null};var hsb2rgb=function(hsb){var rgb={};var h=Math.round(hsb.h);var s=Math.round(hsb.s*255/100);var v=Math.round(hsb.b*255/100);if(s===0){rgb.r=rgb.g=rgb.b=v}else{var t1=v;var t2=(255-s)*v/255;var t3=(t1-t2)*(h%60)/60;if(h===360)h=0;if(h<60){rgb.r=t1;rgb.b=t2;rgb.g=t2+t3}else if(h<120){rgb.g=t1;rgb.b=t2;rgb.r=t1-t3}else if(h<180){rgb.g=t1;rgb.r=t2;rgb.b=t2+t3}else if(h<240){rgb.b=t1;rgb.r=t2;rgb.g=t1-t3}else if(h<300){rgb.b=t1;rgb.g=t2;rgb.r=t2+t3}else if(h<360){rgb.r=t1;rgb.g=t2;rgb.b=t1-t3}else{rgb.r=0;rgb.g=0;rgb.b=0}}return{r:Math.round(rgb.r),g:Math.round(rgb.g),b:Math.round(rgb.b)}};var rgb2hex=function(rgb){var hex=[rgb.r.toString(16),rgb.g.toString(16),rgb.b.toString(16)];$.each(hex,function(nr,val){if(val.length===1)hex[nr]='0'+val});return hex.join('')};var hex2rgb=function(hex){hex=parseInt(((hex.indexOf('#')>-1)?hex.substring(1):hex),16);return{r:hex>>16,g:(hex&0x00FF00)>>8,b:(hex&0x0000FF)}};var rgb2hsb=function(rgb){var hsb={h:0,s:0,b:0};var min=Math.min(rgb.r,rgb.g,rgb.b);var max=Math.max(rgb.r,rgb.g,rgb.b);var delta=max-min;hsb.b=max;hsb.s=max!==0?255*delta/max:0;if(hsb.s!==0){if(rgb.r===max){hsb.h=(rgb.g-rgb.b)/delta}else if(rgb.g===max){hsb.h=2+(rgb.b-rgb.r)/delta}else{hsb.h=4+(rgb.r-rgb.g)/delta}}else{hsb.h=-1}hsb.h*=60;if(hsb.h<0){hsb.h+=360}hsb.s*=100/255;hsb.b*=100/255;return hsb};var hex2hsb=function(hex){var hsb=rgb2hsb(hex2rgb(hex));if(hsb.s===0)hsb.h=360;return hsb};var hsb2hex=function(hsb){return rgb2hex(hsb2rgb(hsb))};switch(o){case'readonly':$(this).each(function(){if(!$(this).hasClass('miniColors'))return;$(this).prop('readonly',data)});return $(this);case'disabled':$(this).each(function(){if(!$(this).hasClass('miniColors'))return;if(data){disable($(this))}else{enable($(this))}});return $(this);case'value':if(data===undefined){if(!$(this).hasClass('miniColors'))return;var input=$(this),hex=expandHex(input.val());return hex?'#'+convertCase(hex,input.data('letterCase')):null}$(this).each(function(){if(!$(this).hasClass('miniColors'))return;$(this).val(data);setColorFromInput($(this))});return $(this);case'destroy':$(this).each(function(){if(!$(this).hasClass('miniColors'))return;destroy($(this))});return $(this);default:if(!o)o={};$(this).each(function(){if($(this)[0].tagName.toLowerCase()!=='input')return;if($(this).data('trigger'))return;create($(this),o,data)});return $(this)}}})})(jQuery);
\ No newline at end of file
diff --git a/app/assets/javascripts/desktop/jquery.tinyscrollbar.js b/app/assets/javascripts/desktop/jquery.tinyscrollbar.js
new file mode 100644
index 00000000..125c89d4
--- /dev/null
+++ b/app/assets/javascripts/desktop/jquery.tinyscrollbar.js
@@ -0,0 +1,240 @@
+/*
+ * Tiny Scrollbar 1.8
+ * http://www.baijs.nl/tinyscrollbar/
+ *
+ * Copyright 2012, Maarten Baijs
+ * Dual licensed under the MIT or GPL Version 2 licenses.
+ * http://www.opensource.org/licenses/mit-license.php
+ * http://www.opensource.org/licenses/gpl-2.0.php
+ *
+ * Date: 26 / 07 / 2012
+ * Depends on library: jQuery
+ *
+ */
+;( function( $ )
+{
+ $.tiny = $.tiny || { };
+
+ $.tiny.scrollbar = {
+ options: {
+ axis : 'y' // vertical or horizontal scrollbar? ( x || y ).
+ , wheel : 40 // how many pixels must the mouswheel scroll at a time.
+ , scroll : true // enable or disable the mousewheel.
+ , lockscroll : true // return scrollwheel to browser if there is no more content.
+ , size : 'auto' // set the size of the scrollbar to auto or a fixed number.
+ , sizethumb : 'auto' // set the size of the thumb to auto or a fixed number.
+ , invertscroll : false // Enable mobile invert style scrolling
+ , onMove : function(){}
+ }
+ };
+
+ $.fn.tinyscrollbar = function( params )
+ {
+ var options = $.extend( {}, $.tiny.scrollbar.options, params );
+ this.each( function()
+ {
+
+ $( this ).data('tsb', new Scrollbar( $( this ), options ) );
+ });
+
+ return this;
+ };
+
+ $.fn.tinyscrollbar_update = function(sScroll)
+ {
+
+ return $( this ).data( 'tsb' ).update( sScroll );
+ };
+
+ function Scrollbar( root, options )
+ {
+ var oSelf = this
+ , oWrapper = root
+ , oViewport = { obj: $( '.viewport', root ) }
+ , oContent = { obj: $( '.overview', root ) }
+ , oScrollbar = { obj: $( '.scrollbar', root ) }
+ , oTrack = { obj: $( '.track', oScrollbar.obj ) }
+ , oThumb = { obj: $( '.thumb', oScrollbar.obj ) }
+ , sAxis = options.axis === 'x'
+ , sDirection = sAxis ? 'left' : 'top'
+ , sSize = sAxis ? 'Width' : 'Height'
+ , iScroll = 0
+ , iPosition = { start: 0, now: 0 }
+ , iMouse = {}
+ , touchEvents = 'ontouchstart' in document.documentElement
+ , UA = $.browser
+ ;
+
+ function initialize()
+ {
+ oSelf.update();
+ setEvents();
+
+ return oSelf;
+ }
+
+ this.update = function( sScroll )
+ {
+ oViewport[ options.axis ] = oViewport.obj[0][ 'offset'+ sSize ];
+ oContent[ options.axis ] = oContent.obj[0][ 'scroll'+ sSize ];
+ oContent.ratio = oViewport[ options.axis ] / oContent[ options.axis ];
+
+ oScrollbar.obj.toggleClass( 'disable', oContent.ratio >= 1 );
+
+ oTrack[ options.axis ] = options.size === 'auto' ? oViewport[ options.axis ] : options.size;
+ oThumb[ options.axis ] = Math.min( oTrack[ options.axis ], Math.max( 0, ( options.sizethumb === 'auto' ? ( oTrack[ options.axis ] * oContent.ratio ) : options.sizethumb ) ) );
+
+ oScrollbar.ratio = options.sizethumb === 'auto' ? ( oContent[ options.axis ] / oTrack[ options.axis ] ) : ( oContent[ options.axis ] - oViewport[ options.axis ] ) / ( oTrack[ options.axis ] - oThumb[ options.axis ] );
+
+ iScroll = ( sScroll === 'relative' && oContent.ratio <= 1 ) ? Math.min( ( oContent[ options.axis ] - oViewport[ options.axis ] ), Math.max( 0, iScroll )) : 0;
+ iScroll = ( sScroll === 'bottom' && oContent.ratio <= 1 ) ? ( oContent[ options.axis ] - oViewport[ options.axis ] ) : isNaN( parseInt( sScroll, 10 ) ) ? iScroll : parseInt( sScroll, 10 );
+
+ setSize();
+ };
+
+ function setSize()
+ {
+ var sCssSize = sSize.toLowerCase();
+
+ oThumb.obj.css( sDirection, iScroll / oScrollbar.ratio );
+ oContent.obj.css( sDirection, -iScroll );
+ iMouse.start = oThumb.obj.offset()[ sDirection ];
+
+ oScrollbar.obj.css( sCssSize, oTrack[ options.axis ] );
+ oTrack.obj.css( sCssSize, oTrack[ options.axis ] );
+ oThumb.obj.css( sCssSize, oThumb[ options.axis ] );
+ }
+
+ function setEvents()
+ {
+ if( ! touchEvents )
+ {
+ oThumb.obj.bind( 'mousedown', start );
+ oTrack.obj.bind( 'mouseup', drag );
+ }
+ else
+ {
+ oViewport.obj[0].ontouchstart = function( event )
+ {
+ if( 1 === event.touches.length )
+ {
+ start( event.touches[ 0 ] );
+ event.stopPropagation();
+ }
+ };
+ }
+
+ if( options.scroll && window.addEventListener )
+ {
+ oWrapper[0].addEventListener( 'DOMMouseScroll', wheel, false );
+ oWrapper[0].addEventListener( 'mousewheel', wheel, false );
+ oWrapper[0].addEventListener( 'MozMousePixelScroll', function( event ){
+ event.preventDefault();
+ }, false);
+ }
+ else if( options.scroll )
+ {
+ oWrapper[0].onmousewheel = wheel;
+ }
+ }
+
+ function start( event )
+ {
+ $( "body" ).addClass( "noSelect" );
+ // Disable select text under IE10
+ if ( UA.msie < 10 ){
+ $( "body" ).attr({
+ "onselectstart": "return false",
+ "ondragstart": "return false"
+ });
+ }
+ oScrollbar.obj.addClass( "dragging" );
+
+ var oThumbDir = parseInt( oThumb.obj.css( sDirection ), 10 );
+ iMouse.start = sAxis ? event.pageX : event.pageY;
+ iPosition.start = oThumbDir == 'auto' ? 0 : oThumbDir;
+
+ if( ! touchEvents )
+ {
+ $( document ).bind( 'mousemove', drag );
+ $( document ).bind( 'mouseup', end );
+ oThumb.obj.bind( 'mouseup', end );
+ }
+ else
+ {
+ document.ontouchmove = function( event )
+ {
+ event.preventDefault();
+ drag( event.touches[ 0 ] );
+ };
+ document.ontouchend = end;
+ }
+ }
+
+ function wheel( event )
+ {
+ if( oContent.ratio < 1 )
+ {
+ var oEvent = event || window.event
+ , iDelta = oEvent.wheelDelta ? oEvent.wheelDelta / 120 : -oEvent.detail / 3
+ ;
+
+ iScroll -= iDelta * options.wheel;
+ iScroll = Math.min( ( oContent[ options.axis ] - oViewport[ options.axis ] ), Math.max( 0, iScroll ));
+
+ oThumb.obj.css( sDirection, iScroll / oScrollbar.ratio );
+ oContent.obj.css( sDirection, -iScroll );
+
+ if( options.lockscroll || ( iScroll !== ( oContent[ options.axis ] - oViewport[ options.axis ] ) && iScroll !== 0 ) )
+ {
+ oEvent = $.event.fix( oEvent );
+ oEvent.preventDefault();
+ }
+ }
+
+ options.onMove.call(this,get_destance_from_end());
+ }
+
+ function get_destance_from_end(){
+ var distance_to_end = (oContent.obj.width() - oScrollbar.obj.width()) - iScroll;
+ return distance_to_end;
+ }
+
+ function drag( event )
+ {
+ if( oContent.ratio < 1 )
+ {
+ if( options.invertscroll && touchEvents )
+ {
+ iPosition.now = Math.min( ( oTrack[ options.axis ] - oThumb[ options.axis ] ), Math.max( 0, ( iPosition.start + ( iMouse.start - ( sAxis ? event.pageX : event.pageY ) ))));
+ }
+ else
+ {
+ iPosition.now = Math.min( ( oTrack[ options.axis ] - oThumb[ options.axis ] ), Math.max( 0, ( iPosition.start + ( ( sAxis ? event.pageX : event.pageY ) - iMouse.start))));
+ }
+
+ iScroll = iPosition.now * oScrollbar.ratio;
+ oContent.obj.css( sDirection, -iScroll );
+ oThumb.obj.css( sDirection, iPosition.now );
+ }
+ options.onMove.call(this,get_destance_from_end());
+ }
+
+ function end()
+ {
+ $( "body" ).removeClass( "noSelect" );
+ // Enable select text under IE10
+ if ( UA.msie < 10 ){
+ $( "body" ).removeAttr( "onselectstart", "ondragstart" );
+ }
+ oScrollbar.obj.removeClass( "dragging" );
+ $( document ).unbind( 'mousemove', drag );
+ $( document ).unbind( 'mouseup', end );
+ oThumb.obj.unbind( 'mouseup', end );
+ document.ontouchmove = document.ontouchend = null;
+ }
+
+ return initialize();
+ }
+
+}(jQuery));
\ No newline at end of file
diff --git a/app/assets/javascripts/desktop/orbitTimeline.js b/app/assets/javascripts/desktop/orbitTimeline.js
new file mode 100644
index 00000000..bdde5a24
--- /dev/null
+++ b/app/assets/javascripts/desktop/orbitTimeline.js
@@ -0,0 +1,243 @@
+//for timeline parent library, will be accessable by main library and API library for other people to use.. default inherits orbitDesktopAPI
+// Harry Bomrah
+
+var orbitTimeline = function(dom){
+ t = this;
+ this.dom = $(dom);
+ this.timelineHtml = $("");
+ //this.marker = t.timelineHtml.find("#timline_marker");
+ this.scale = "";
+ //this.container = t.timelineHtml.find("#t_container");
+ this.events = new Array;
+ this.monthList = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
+ this.dt = new Date();
+ this.fromdate = [t.dt.getFullYear(),t.dt.getMonth()+1];
+ this.ajaxload = true;
+ this.halfline = $(window).width()/2 + 200;
+ this.initialize = function(){
+ t.dom.html(t.timelineHtml);
+ $("div.scrollbar").hide();
+ t.constructTimeScale(function(timelineScale){
+ $("#timeline_scale").html(timelineScale);
+ var totalyearwidth =timelineScale.find(".year").length * timelineScale.find(".year").outerWidth();
+ var totalul = 0;
+ $(".t_scale").css({"min-width":$(".tinycanvas .viewport").width()+500 + "px"})
+ for(eve in t.events){
+ t.makeBubble(t.events[eve]);
+ totalul = $("#scale_wrapper ul").length
+ $(".t_scale").width((totalul*350) + totalyearwidth);
+ }
+ t.bubble_fx();
+ var scrollvalue = 0;
+ $('.tinycanvas').tinyscrollbar({
+ axis: 'x',
+ onMove: function(x){
+ if(x > scrollvalue)
+ t.timeScaleForward();
+ // else
+ // t.timeScaleBackward();
+ scrollvalue = x;
+ var limit = $("#timeline_scale").outerWidth() - $(".tinycanvas .scrollbar").outerWidth();
+ if(t.ajaxload){
+ if((limit - x) < 10){
+ t.eventAjaxLoad(function(){
+ var totalul = 0;
+ for(eve in t.events){
+ t.makeBubble(t.events[eve]);
+ totalul = $("#scale_wrapper ul").length
+ $(".t_scale").width((totalul*360) + totalyearwidth + 314);
+ }
+ $('.tinycanvas').tinyscrollbar_update(x);
+ t.bubble_fx();
+ });
+ }
+ }
+ }
+ });
+ });
+ }
+ this.constructTimeScale = function(callbackFn){
+ var mon ="",year="",formname;
+ var scale = $("");
+ $.getJSON("/desktop_orbit/gettimelinespan",{"get":"papers"},function(years){
+ var $ul = $("");
+ var startyear = years.startyear, endyear = years.endyear,year = years.startyear;
+ $ul.append(''+startyear+'');
+ while(year > endyear){
+ year--;
+ $ul.append(''+year+'');
+ }
+ $("div#orbit div#year_navigation").html($ul);
+ })
+ $.getJSON("/desktop_orbit/eventajaxload",{"event":"papers","from":t.fromdate},function(papersArray){
+ $.each(papersArray,function(i,pa){
+ $.each(pa.papers,function(i,paper){
+ var dt = new Date(paper.created_at);
+ var cur_mon = paper.created_at.substr(5,2);
+ var cur_year = dt.getFullYear();
+ var cdt = paper.created_at.substr(0,7).replace("-","");
+ formname = (cur_mon.charAt(0) == "0"?cur_mon.charAt(1) : cur_mon)
+ var bubbleData = {"fulldate" : t.monthList[parseInt(formname)] +", " + dt.getDate() + ", " + cur_year,"title":paper.title,"jtitle":"Harry","coauthors":paper.coauthors,"abstract":paper.abstract,"timestamp":cdt}
+ t.events.push(bubbleData);
+ if(cur_year != year){
+ year = cur_year;
+ scale.append($(""+year+"
"));
+ }
+ if(cur_mon != mon){
+ mon = cur_mon;
+ var yr = scale.find("div[data-content="+year+"]");
+ yr.append($(""+t.monthList[parseInt(formname)]+"
"))
+ }
+ });
+ });
+ //scale.append($(""+year+"
"));
+ t.fromdate = [year,formname-1];
+ if(typeof callbackFn == "function"){
+ callbackFn.call(this,scale);
+ }
+ })
+
+ }
+ this.makeBubble = function(bubbleData){
+ var totalul = $("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] ul").length;
+ var targetul = $("#scale_wrapper div[data-content="+bubbleData.timestamp+"] div.bubble_list ul").eq(totalul-1);
+ if(totalul == 0){
+ var ul = $("");
+ $("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
+ targetul = ul;
+ }else{
+ var totalli = targetul.find("li").length;
+ if(totalli >= 5){
+ var ul = $("");
+ $("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
+ targetul = ul;
+ }
+ }
+ var bt = (bubbleData.title.length > 70? bubbleData.title.substr(0,70) + "..." : bubbleData.title);
+ var bubble = $(""+bt+""+bubbleData.fulldate+"");
+ targetul.prepend(bubble);
+ bubble.show();
+ bubble.click(function(){
+ var thisbubble = $(this);
+ $(this).parents(dom)
+ .find('.bubble, .date')
+ .removeClass('thmc1 thmtxt');
+
+ o.toolPopup({
+ parent: $(this).parent(),
+ html : ""+bubbleData.jtitle+"
Co-Authors
"+bubbleData.coauthors+"Abstract
"+bubbleData.abstract+"",
+ height: "392px",
+ width:"310px",
+ beforeClose : function(){
+ $("div.bubble_arrow").remove();
+ thisbubble.parents(dom)
+ .find('.bubble, .date')
+ .removeClass('thmc1 thmtxt');
+ },
+ onOpen : function(){
+ thisbubble.append('');
+ },
+ beforeOpen : function(){
+ thisbubble.addClass('thmc1 thmtxt');
+ thisbubble.find('.date').addClass('thmtxt');
+ }
+ });
+ })
+ }
+ this.eventAjaxLoad = function(callbackFn){
+ t.events = [];
+ var mon ="",year="",formname;
+ var scale = $("#scale_wrapper");
+
+ t.ajaxload = false;
+ $.getJSON("/desktop_orbit/eventajaxload",{"from":t.fromdate},function(papersArray){
+ $.each(papersArray,function(i,pa){
+ $.each(pa.papers,function(i,paper){
+ var dt = new Date(paper.created_at);
+ var cur_mon = paper.created_at.substr(5,2);
+ var cur_year = dt.getFullYear();
+ var cdt = paper.created_at.substr(0,7).replace("-","");
+ formname = (cur_mon.charAt(0) == "0"?cur_mon.charAt(1) : cur_mon)
+ var bubbleData = {"fulldate" : t.monthList[parseInt(formname)] +", " + dt.getDate() + ", " + cur_year,"title":paper.title,"jtitle":"Harry","coauthors":paper.coauthors,"abstract":paper.abstract,"timestamp":cdt}
+ t.events.push(bubbleData);
+ if(cur_year != year){
+ year = cur_year;
+ if(scale.find("div[data-content="+year+"]").length == 0){
+ scale.append($(""+year+"
"));
+ }
+ }
+ if(cur_mon != mon){
+ mon = cur_mon;
+ var yr = scale.find("div[data-content="+year+"]");
+ yr.append($(""+t.monthList[parseInt(formname)]+"
"))
+ }
+ });
+ });
+ if(papersArray.length != 0){
+ // if(scale.find("div[data-content="+(year-1)+"]").length == 0)
+ // scale.append($(""+year+"
"));
+ t.ajaxload = true;
+ t.fromdate = [year,formname-1];
+ }
+ if(typeof callbackFn == "function"){
+ callbackFn.call(this,scale);
+ }
+ })
+
+ }
+ this.bubble_fx = function(){
+ $('.bubble').on({
+ mouseover: function(){
+ $(this)
+ .addClass('hover')
+ .append('');
+ },
+ mouseout: function(){
+ $(this)
+ .removeClass('hover')
+ .find('.icon-chevron-right').remove();
+ },
+ });
+ }
+ this.timeScaleForward = function(){
+
+ // var lastregion = regions.eq(regions.length-1);
+ // if(lastregion.offset().left < halfline){
+ // var year = lastregion.attr("data-content");
+ // $("div#orbit div#year_navigation ul a").removeClass("active");
+ // $("div#orbit div#year_navigation ul a[href="+year+"]").addClass("active");
+ // }
+ var regions = $("div.region_year");
+ regions.each(function(){
+ var offset = $(this).offset().left;
+ if(offset < t.halfline){
+ if(offset > 156){
+ var year = $(this).attr("data-content");
+ $("div#orbit div#year_navigation ul a").removeClass("active");
+ $("div#orbit div#year_navigation ul a[href="+year+"]").addClass("active");
+ }
+ }
+ })
+ }
+ this.timeScaleBackward = function(){
+ var regions = $("div.region_year");
+ regions.each(function(){
+ var offset = $(this).offset().left * -1
+ if(offset > t.halfline){
+ if(offset > 156){
+ var year = $(this).attr("data-content");
+ $("div#orbit div#year_navigation ul a").removeClass("active");
+ $("div#orbit div#year_navigation ul a[href="+year+"]").addClass("active");
+ }
+ }
+ })
+ }
+ this.ajaxEventPull = function(){
+ if(!t.update){
+ t.update = true;
+ $.getJSON("/desktop_orbit/ajaxeventpull",{"from":t.fromdate},function(){
+
+ })
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/assets/javascripts/desktop/orbitdesktop.js b/app/assets/javascripts/desktop/orbitdesktop.js
new file mode 100755
index 00000000..e241c2b2
--- /dev/null
+++ b/app/assets/javascripts/desktop/orbitdesktop.js
@@ -0,0 +1,1600 @@
+// JavaScript Document
+//harry
+//Inititialize function will initialize desktop
+
+//callback-method will be called after desktop controlled ajax call
+//container=true is the area where the view will be loaded
+//load = true is used to load the submenu item by default
+//response-type = "json"|"script"|"xml|html" default is json
+//autocomplete-list = "listname" an array from which autocomplete will be attached to its respective input or textarea
+//ajax-remote="get/delete/post/false" this will automatically bind the with remote ajax call. By default if the resposne is html, it ll be inserted in container=true, false option will not make any calls and also stop page refresh
+// content-holder = "jquery dom", the returned html of server will be put inside the dom mentioned in content-holder of a tag. this can be used in a tags as attributes
+//confirm-message ="Some message", this will prompt user with a confirm box and show the message before ajax call is made.
+//"toggle-onclick" = "classes to get toggle" this will toggle classes on toggle when a tags are clicked.
+//"delete-item" = "true" this will remove its respective item from the list.
+//"pagination-link" = "url" this url will be used for pagination.. this will override last link url.
+//"pagination-var" = "variable to send paramater with url for pagination" this will enable pagination with this attribute for that view.
+
+//for layout tinyscrollbar
+//content-layout="datalist|column|simple" datalist is for data list from database.. column is usually for forms and some other pages.. simple is without any columns, the page will be displayed as it is.. base width will be considered the default width for tinyscrollbar
+//base-width="300" this is the basic width of each column and in case of simple layout it ll be the final width
+//per-column="5" this option is only for datalist layout.. this ll specify number of enteries per column.. default is 4
+//column="true" this option is only for column layout... the columns will be formed on this column=true attribute and it should be a div
+//item=true this attribute should be present in the li tag. li with this attribute are considered as a separate item.
+
+
+$.extend($.expr[':'], {
+ 'containsi': function (elem, i, match, array) {
+ return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
+ }
+});
+$.fn.sort = function(c) {
+ return this.pushStack([].sort.apply(this, arguments), []);
+};
+var sortAscending = function(a, b) {
+ return $(a).find("h1").text() > $(b).find("h1").text() ? 1 : -1;
+};
+var sortDescending = function(a, b) {
+ return $(a).find("h1").text() < $(b).find("h1").text() ? 1 : -1;
+};
+jQuery.ajax = (function(_ajax){
+
+ var protocol = location.protocol,
+ hostname = location.hostname,
+ exRegex = RegExp(protocol + '//' + hostname),
+ YQL = 'http' + (/^https/.test(protocol)?'s':'') + '://query.yahooapis.com/v1/public/yql?callback=?',
+ query = 'select * from html where url="{URL}" and xpath="*"';
+
+ function isExternal(url) {
+ return !exRegex.test(url) && /:\/\//.test(url);
+ }
+
+ return function(o) {
+
+ var url = o.url;
+
+ if ( /get/i.test(o.type) && !/json/i.test(o.dataType) && isExternal(url) ) {
+
+ // Manipulate options so that JSONP-x request is made to YQL
+
+ o.url = YQL;
+ o.dataType = 'json';
+
+ o.data = {
+ q: query.replace(
+ '{URL}',
+ url + (o.data ?
+ (/\?/.test(url) ? '&' : '?') + jQuery.param(o.data)
+ : '')
+ ),
+ format: 'xml'
+ };
+
+ // Since it's a JSONP request
+ // complete === success
+ if (!o.success && o.complete) {
+ o.success = o.complete;
+ delete o.complete;
+ }
+
+ o.success = (function(_success){
+ return function(data) {
+
+ if (_success) {
+ // Fake XHR callback.
+ _success.call(this, {
+ responseText: (data.results[0] || '')
+ // YQL screws with