/********************************************************************** * * * **********************************************************************/ ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) (function(require){ var module={} // make module AMD/node compatible... /*********************************************************************/ var toggler = require('lib/toggler') var actions = require('lib/actions') var features = require('lib/features') var keyboard = require('lib/keyboard') var data = require('imagegrid/data') var images = require('imagegrid/images') var ribbons = require('imagegrid/ribbons') var core = require('features/core') var base = require('features/base') /*********************************************************************/ var makeStateIndicator = function(type){ return $('
') .addClass('state-indicator-container ' + type || '') } // XXX do we need this??? var makeStateIndicatorItem = function(container, type, text){ var item = $('
') .addClass('item '+ type || '') .attr('text', text) this.dom.find('.state-indicator-container.'+container) .append(item) return item } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // XXX revise how/where info is displayed... var StatusBarActions = actions.Actions({ config: { 'status-bar': 'full', 'status-bars': { hidden: [ '---', 'mark', 'bookmark', ], minimal: [ 'index', 'ribbon', 'changes', '---', 'edit-mode', 'mark', 'bookmark', ], full: [ 'index', 'ribbon', 'changes', 'gid', 'path', '---', 'edit-mode', 'mark', 'bookmark', ], }, 'status-bar-index': { 'mode': 'normal', // NOTE: this would need to reconstruct the status bar for // changes to take effect, i.e. call .resetStatusBar() // XXX might be a good idea to run an editor on click on // touch devices... 'editable': true, 'live-update-on-edit': false, }, 'status-bar-ribbon-count': true, 'status-bar-changes-text': '*', 'status-bar-edit-mode-indicator-update-interval': 1000, // workspace stuff... 'status-bar-workspace-attrs': [ 'status-bar', ], 'status-bar-workspace-defaults': { 'default': 'full', 'single-image': 'minimal', 'slideshow': 'hidden', }, }, __statusbar_elements__: { /* item template... item: function(item){ // cleanup... if(item == null){ // XXX return } // setup the item DOM... if(typeof(item) == typeof('str')){ var type = item item = $('') .addClass('item-example') .attr('type', item) .text('example') // get stuff from the item... } else { var type = item.attr('type') } // update the item... // XXX return item }, */ index: function(item, gid, img){ // cleanup... if(item == null){ return } var that = this gid = gid || this.current // make an element... if(typeof(item) == typeof('str')){ var type = item item = $('') .addClass(type) .append(!(this.config['status-bar-index'] || {})['editable'] ? // not-editable... $('') .addClass('position') .attr('info', 'Image number (click to toggle ribbon/global)') // toggle index state... .click(function(){ that.toggleStatusBarIndexMode() that.updateStatusBar() }) // editable... : $('') .addClass('position editable') .attr('info', 'Image number (click to edit)') .makeEditable({ propagate_unhandled_keys: false, reset_on_done: false, }) // select image when done... .on('edit-commit', function(_, text){ var i = parseInt(text) i = i >= 1 ? i-1 : i == null ? 'current' : i that.focusImage(i, item.hasClass('global') ? 'global' : undefined) }) // update image position... // XXX this appears to be run in the node context... .keyup(function(){ // XXX KeyboardEvent does not appear to have this... //event.stopPropagation() if((that.config['status-bar-index'] || {})['live-update-on-edit']){ var i = parseInt($(this).text()) i = i >= 1 ? i-1 : i == null ? 'current' : i that.focusImage(i, item.hasClass('global') ? 'global' : undefined) } }) .focus(function(){ $(this).selectText() }) .blur(function(){ that.updateStatusBar() })) .append($('') .addClass('length') .attr('info', 'Image count (click to toggle ribbon/global)') // toggle index state... .click(function(){ that.toggleStatusBarIndexMode() that.updateStatusBar() })) } else { var type = item.attr('type') } // NOTE: using .toggleStatusBarIndexMode(..) here will fall // into an infinite recursion... var cls = (that.config['status-bar-index'] || {})['mode'] || 'normal' // global index... if(cls == 'global'){ var i = this.data ? this.data.getImageOrder(gid) : -1 var l = this.data ? this.data.length : 0 // ribbon index... } else { var i = this.data ? this.data.getImageOrder('ribbon', gid) : -1 var l = this.data ? this.data.getImages(gid).len : 0 } // update... item .addClass(cls) .removeClass(cls != 'normal' ? 'normal' : 'global') .find('.position:not(:focus)') .text(i >= 0 ? i+1 : '-') .end() .find('.length') .text(l > 0 ? ('/' + l) : '') return item }, ribbon: function(item, gid, img){ // cleanup... if(item == null){ return } var that = this // get ribbon number... var n = (this.data && this.data.ribbon_order.length > 0) ? this.data.getRibbonOrder(gid || this.current) : null var t = (this.config['status-bar-ribbon-count'] && this.data) ? this.data.ribbon_order.length : null // make an element... if(typeof(item) == typeof('str')){ item = $('') .addClass('ribbon-index') .append($('') .addClass('ribbon-number') .attr('info', 'Current ribbon (click to edit)') .makeEditable({ propagate_unhandled_keys: false, reset_on_done: false, }) .on('edit-commit', function(_, text){ var i = parseInt(text) i = i >= 1 ? i-1 : i == null ? 'current' : i that.focusRibbon(text == '*' ? that.base : i) }) .focus(function(){ $(this).selectText() }) .blur(function(){ that.updateStatusBar() })) .append($('') .addClass('ribbon-count') .attr('info', 'Ribbon count')) } item .find('.ribbon-number') .html(n != null ? n+1 : '-') .end() .find('.ribbon-count') .html(t || '') // flag the base ribbon... // NOTE: for some reason can't get jQuery .prop(..)/.removeProp(..) // to work here... if(this.data && this.data.base && this.data.getRibbon(gid) == this.base){ item[0].setAttribute('base', '') } else { item[0].removeAttribute('base') } return item }, changes: function(item, gid, img){ // cleanup... if(item == null){ return } if(typeof(item) == typeof('str')){ item = $('') .addClass('changes') .attr('info', 'Unsaved changes') } //item.html(this.changes !== false ? // this.config['status-bar-changes-text'] || '*' // : '') // XXX not yet sure about .hasOwnProperty(..) here... item.html(this.hasOwnProperty('changes') && this.changes !== false ? this.config['status-bar-changes-text'] || '*' : '') return item }, // XXX handle path correctly... gid: function(item, gid, img){ // cleanup... if(item == null){ return } var that = this gid = gid || this.current img = img || (this.images && gid in this.images && this.images[gid]) // make an element... if(typeof(item) == typeof('str')){ var type = item item = $('') .addClass(type + ' expanding-text ') .attr('info', type == 'gid' ? 'Image GID' : type == 'path'? 'Image filename/path' : '') .append($('')) .append($('