From 89820beb3de75c0dbb6aea76875932af4371edbe Mon Sep 17 00:00:00 2001 From: Christopher McCulloh Date: Tue, 3 Feb 2015 14:42:41 -0500 Subject: [PATCH] (1027---clean-up-code-formatting) cleans up codebase according to ET standards --- js/checkbox.js | 117 ++++----- js/combobox.js | 69 +++--- js/datepicker.js | 404 ++++++++++++++++++------------- js/dropdown-autoflip.js | 84 ++++--- js/infinite-scroll.js | 75 +++--- js/loader.js | 52 ++-- js/pillbox.js | 137 ++++++----- js/placard.js | 153 ++++++------ js/radio.js | 74 +++--- js/repeater-list.js | 345 ++++++++++++++++----------- js/repeater-thumbnail.js | 159 +++++++------ js/repeater.js | 501 ++++++++++++++++++++++----------------- js/scheduler.js | 324 +++++++++++++------------ js/search.js | 48 ++-- js/selectlist.js | 70 +++--- js/spinbox.js | 95 ++++---- js/tree.js | 105 ++++---- js/wizard.js | 158 +++++++----- 18 files changed, 1654 insertions(+), 1316 deletions(-) diff --git a/js/checkbox.js b/js/checkbox.js index 9b97de0ba..dd963b3eb 100644 --- a/js/checkbox.js +++ b/js/checkbox.js @@ -6,10 +6,10 @@ * Licensed under the BSD New license. */ - // -- BEGIN UMD WRAPPER PREFACE -- +// -- BEGIN UMD WRAPPER PREFACE -- - // For more information on UMD visit: - // https://github.com/umdjs/umd/blob/master/jqueryPlugin.js +// For more information on UMD visit: +// https://github.com/umdjs/umd/blob/master/jqueryPlugin.js (function (factory) { if (typeof define === 'function' && define.amd) { @@ -36,20 +36,23 @@ this.$label = this.$element.parent(); this.$parent = this.$label.parent('.checkbox'); this.$toggleContainer = this.$element.attr('data-toggle'); - this.state = { disabled: false, checked: false }; + this.state = { + disabled: false, + checked: false + }; - if( this.$parent.length === 0 ) { + if (this.$parent.length === 0) { this.$parent = null; } - if( Boolean( this.$toggleContainer ) ) { - this.$toggleContainer = $( this.$toggleContainer ); + if (Boolean(this.$toggleContainer)) { + this.$toggleContainer = $(this.$toggleContainer); } else { this.$toggleContainer = null; } // handle events - this.$element.on('change.fu.checkbox', $.proxy( this.itemchecked, this )); + this.$element.on('change.fu.checkbox', $.proxy(this.itemchecked, this)); this.$label.unbind('click', $.proxy(this.toggle, this));//unbind previous binds so that double clickage doesn't happen (thus making checkbox appear to not work) this.$label.on('click', $.proxy(this.toggle, this));//make repeated label clicks work @@ -61,11 +64,11 @@ constructor: Checkbox, - setState: function( $chk ) { + setState: function ($chk) { $chk = $chk || this.$element; - this.state.disabled = Boolean( $chk.prop('disabled') ); - this.state.checked = Boolean( $chk.is(':checked') ); + this.state.disabled = Boolean($chk.prop('disabled')); + this.state.checked = Boolean($chk.is(':checked')); this._resetClasses(); @@ -77,28 +80,28 @@ this.toggleContainer(); }, - enable: function() { + enable: function () { this.state.disabled = false; this.$element.removeAttr('disabled'); this.$element.prop('disabled', false); this._resetClasses(); - this.$element.trigger( 'enabled.fu.checkbox' ); + this.$element.trigger('enabled.fu.checkbox'); }, - disable: function() { + disable: function () { this.state.disabled = true; this.$element.prop('disabled', true); this.$element.attr('disabled', 'disabled'); this._setDisabledClass(); - this.$element.trigger( 'disabled.fu.checkbox' ); + this.$element.trigger('disabled.fu.checkbox'); }, check: function () { this.state.checked = true; this.$element.prop('checked', true); - this.$element.attr('checked','checked'); + this.$element.attr('checked', 'checked'); this._setCheckedClass(); - this.$element.trigger( 'checked.fu.checkbox' ); + this.$element.trigger('checked.fu.checkbox'); }, uncheck: function () { @@ -106,18 +109,20 @@ this.$element.prop('checked', false); this.$element.removeAttr('checked'); this._resetClasses(); - this.$element.trigger( 'unchecked.fu.checkbox' ); + this.$element.trigger('unchecked.fu.checkbox'); }, isChecked: function () { return this.state.checked; }, - toggle: function(e) { + toggle: function (e) { //keep checkbox from being used if it is disabled. You can't rely on this.state.disabled, because on bind time it might not be disabled, but, state.disabled may be set to true after bind time (and this.state.disabled won't be updated for this bound instance) //To see how this works, uncomment the next line of code and go to http://0.0.0.0:8000/index.html click the "disable #myCustomCheckbox1" and then click on the first checkbox and see the disparity in the output between this.state and this.$element.attr //console.log('is disabled? this.state says, "' + this.state.disabled + '"; this.$element.attr says, "' + this.$element.attr('disabled') + '"'); - if(/* do not change this to this.state.disabled. It will break edge cases */ this.$element.prop('disabled')){return;} + if (/* do not change this to this.state.disabled. It will break edge cases */ this.$element.prop('disabled')) { + return; + } //keep event from firing twice in Chrome if (!e || (e.target === e.originalEvent.target)) { @@ -125,32 +130,34 @@ this._toggleCheckedState(); - if(Boolean(e)){ + if (Boolean(e)) { //stop bubbling, otherwise event fires twice in Firefox. e.preventDefault(); //make change event still fire (prevented by preventDefault to avoid firefox bug, see preceeding line) this.$element.trigger('change', e); } + } }, - toggleContainer: function(){ - if( Boolean( this.$toggleContainer ) ) { - if( this.state.checked ) { + toggleContainer: function () { + if (Boolean(this.$toggleContainer)) { + if (this.state.checked) { this.$toggleContainer.removeClass('hide hidden'); this.$toggleContainer.attr('aria-hidden', 'false'); - }else { + } else { this.$toggleContainer.addClass('hidden'); this.$toggleContainer.attr('aria-hidden', 'true'); } + } }, - itemchecked: function( element ) { - this.setState( $( element.target ) ); + itemchecked: function (element) { + this.setState($(element.target)); }, - destroy: function() { + destroy: function () { this.$parent.remove(); // remove any external bindings // [none] @@ -159,54 +166,54 @@ return this.$parent[0].outerHTML; }, - _resetClasses: function() { + _resetClasses: function () { var classesToRemove = []; - if( !this.state.checked ) { - classesToRemove.push( 'checked' ); + if (!this.state.checked) { + classesToRemove.push('checked'); } - if( !this.state.disabled ) { - classesToRemove.push( 'disabled' ); + if (!this.state.disabled) { + classesToRemove.push('disabled'); } - classesToRemove = classesToRemove.join( ' ' ); + classesToRemove = classesToRemove.join(' '); - this.$label.removeClass( classesToRemove ); + this.$label.removeClass(classesToRemove); - if( this.$parent ) { - this.$parent.removeClass( classesToRemove ); + if (this.$parent) { + this.$parent.removeClass(classesToRemove); } }, - _toggleCheckedState: function() { - if( this.state.checked ) { + _toggleCheckedState: function () { + if (this.state.checked) { this.check(); } else { this.uncheck(); } }, - _toggleDisabledState: function() { - if( this.state.disabled ) { + _toggleDisabledState: function () { + if (this.state.disabled) { this.disable(); } else { this.enable(); } }, - _setCheckedClass: function() { + _setCheckedClass: function () { this.$label.addClass('checked'); - if( this.$parent ) { + if (this.$parent) { this.$parent.addClass('checked'); } }, - _setDisabledClass: function() { + _setDisabledClass: function () { this.$label.addClass('disabled'); - if( this.$parent ){ + if (this.$parent) { this.$parent.addClass('disabled'); } } @@ -216,24 +223,24 @@ // CHECKBOX PLUGIN DEFINITION $.fn.checkbox = function (option) { - var args = Array.prototype.slice.call( arguments, 1 ); + var args = Array.prototype.slice.call(arguments, 1); var methodReturn; var $set = this.each(function () { - var $this = $( this ); - var data = $this.data('fu.checkbox'); + var $this = $(this); + var data = $this.data('fu.checkbox'); var options = typeof option === 'object' && option; - if( !data ) { + if (!data) { $this.data('fu.checkbox', (data = new Checkbox(this, options))); } - if( typeof option === 'string' ) { - methodReturn = data[ option ].apply( data, args ); + if (typeof option === 'string') { + methodReturn = data[option].apply(data, args); } }); - return ( methodReturn === undefined ) ? $set : methodReturn; + return (methodReturn === undefined) ? $set : methodReturn; }; $.fn.checkbox.defaults = {}; @@ -249,7 +256,7 @@ $(document).on('mouseover.fu.checkbox.data-api', '[data-initialize=checkbox]', function (e) { var $control = $(e.target).closest('.checkbox').find('[type=checkbox]'); - if ( !$control.data('fu.checkbox') ) { + if (!$control.data('fu.checkbox')) { $control.checkbox($control.data()); } }); @@ -264,6 +271,6 @@ }); }); -// -- BEGIN UMD WRAPPER AFTERWORD -- + // -- BEGIN UMD WRAPPER AFTERWORD -- })); - // -- END UMD WRAPPER AFTERWORD -- +// -- END UMD WRAPPER AFTERWORD -- diff --git a/js/combobox.js b/js/combobox.js index 7be092afc..6b5766186 100644 --- a/js/combobox.js +++ b/js/combobox.js @@ -8,7 +8,7 @@ // -- BEGIN UMD WRAPPER PREFACE -- -// For more information on UMD visit: +// For more information on UMD visit: // https://github.com/umdjs/umd/blob/master/jqueryPlugin.js (function (factory) { @@ -49,39 +49,38 @@ constructor: Combobox, - destroy: function() { + destroy: function () { this.$element.remove(); // remove any external bindings // [none] // set input value attrbute in markup - this.$element.find('input').each(function() { + this.$element.find('input').each(function () { $(this).attr('value', $(this).val()); }); - + // empty elements to return to original markup // [none] - + return this.$element[0].outerHTML; }, - doSelect: function($item){ + doSelect: function ($item) { if (typeof $item[0] !== 'undefined') { this.$selectedItem = $item; this.$input.val(this.$selectedItem.text().trim()); - } - else { + } else { this.$selectedItem = null; } }, - menuShown: function(){ - if(this.options.autoResizeMenu){ + menuShown: function () { + if (this.options.autoResizeMenu) { this.resizeMenu(); } }, - resizeMenu: function(){ + resizeMenu: function () { var width = this.$element.outerWidth(); this.$dropMenu.outerWidth(width); }, @@ -92,10 +91,13 @@ if (item) { var txt = this.$selectedItem.text().trim(); - data = $.extend({ text: txt }, this.$selectedItem.data()); - } - else { - data = { text: this.$input.val()}; + data = $.extend({ + text: txt + }, this.$selectedItem.data()); + } else { + data = { + text: this.$input.val() + }; } return data; @@ -103,8 +105,8 @@ selectByText: function (text) { var $item = $([]); - this.$element.find('li').each(function(){ - if((this.textContent || this.innerText || $(this).text() || '').toLowerCase() === (text || '').toLowerCase()){ + this.$element.find('li').each(function () { + if ((this.textContent || this.innerText || $(this).text() || '').toLowerCase() === (text || '').toLowerCase()) { $item = $(this); return false; } @@ -156,7 +158,9 @@ this.$selectedItem = $(e.target).parent(); // set input text and trigger input change event marked as synthetic - this.$input.val(this.$selectedItem.text().trim()).trigger('change', { synthetic: true }); + this.$input.val(this.$selectedItem.text().trim()).trigger('change', { + synthetic: true + }); // pass object including text and any data-attributes // to onchange event @@ -172,11 +176,9 @@ }, inputchanged: function (e, extra) { - // skip processing for internally-generated synthetic event // to avoid double processing if (extra && extra.synthetic) return; - var val = $(e.target).val(); this.selectByText(val); @@ -184,33 +186,34 @@ // if no match, pass the input value var data = this.selectedItem(); if (data.text.length === 0) { - data = { text: val }; + data = { + text: val + }; } // trigger changed event this.$element.trigger('changed.fu.combobox', data); - } - }; // COMBOBOX PLUGIN DEFINITION $.fn.combobox = function (option) { - var args = Array.prototype.slice.call( arguments, 1 ); + var args = Array.prototype.slice.call(arguments, 1); var methodReturn; var $set = this.each(function () { - var $this = $( this ); - var data = $this.data('fu.combobox'); + var $this = $(this); + var data = $this.data('fu.combobox'); var options = typeof option === 'object' && option; - if( !data ) $this.data('fu.combobox', (data = new Combobox( this, options ) ) ); - if( typeof option === 'string' ) methodReturn = data[ option ].apply( data, args ); + if (!data) $this.data('fu.combobox', (data = new Combobox(this, options))); + if (typeof option === 'string') + methodReturn = data[option].apply(data, args); }); - return ( methodReturn === undefined ) ? $set : methodReturn; + return (methodReturn === undefined) ? $set : methodReturn; }; $.fn.combobox.defaults = { @@ -228,7 +231,7 @@ $(document).on('mousedown.fu.combobox.data-api', '[data-initialize=combobox]', function (e) { var $control = $(e.target).closest('.combobox'); - if ( !$control.data('fu.combobox') ) { + if (!$control.data('fu.combobox')) { $control.combobox($control.data()); } }); @@ -237,12 +240,12 @@ $(function () { $('[data-initialize=combobox]').each(function () { var $this = $(this); - if ( !$this.data('fu.combobox') ) { + if (!$this.data('fu.combobox')) { $this.combobox($this.data()); } }); }); -// -- BEGIN UMD WRAPPER AFTERWORD -- + // -- BEGIN UMD WRAPPER AFTERWORD -- })); - // -- END UMD WRAPPER AFTERWORD -- \ No newline at end of file +// -- END UMD WRAPPER AFTERWORD -- diff --git a/js/datepicker.js b/js/datepicker.js index c9d9cd19e..af6634f9b 100644 --- a/js/datepicker.js +++ b/js/datepicker.js @@ -32,27 +32,27 @@ var old = $.fn.datepicker; var requestedMoment = false; - var runStack = function(){ + var runStack = function () { var i, l; requestedMoment = true; - for(i=0,l=datepickerStack.length; ifrom.year || (year===from.year && month>from.month) || (year===from.year && month===from.month && date>=from.date)) && - (year from.year || (year === from.year && month > from.month) || (year === from.year && month === from.month && date >= from.date)) && + (year < to.year || (year === to.year && month < to.month) || (year === to.year && month === to.month && date <= to.date)) + ) { return true; } + } return false; }, - monthClicked: function(e){ + monthClicked: function (e) { this.$wheelsMonth.find('.selected').removeClass('selected'); $(e.currentTarget).parent().addClass('selected'); }, - next: function(){ + next: function () { var month = this.$headerTitle.attr('data-month'); var year = this.$headerTitle.attr('data-year'); month++; - if(month>11){ - if(this.sameYearOnly){ + if (month > 11) { + if (this.sameYearOnly) { return; } + month = 0; year++; } + this.renderMonth(new Date(year, month, 1)); }, - onYearScroll: function(e){ - if(this.artificialScrolling){ return; } + onYearScroll: function (e) { + if (this.artificialScrolling) { + return; + } var $yearUl = $(e.currentTarget); - var height = ($yearUl.css('box-sizing')==='border-box') ? $yearUl.outerHeight() : $yearUl.height(); + var height = ($yearUl.css('box-sizing') === 'border-box') ? $yearUl.outerHeight() : $yearUl.height(); var scrollHeight = $yearUl.get(0).scrollHeight; var scrollTop = $yearUl.scrollTop(); var bottomPercentage = (height / (scrollHeight - scrollTop)) * 100; var topPercentage = (scrollTop / scrollHeight) * 100; var i, start; - if(topPercentage<5) { + if (topPercentage < 5) { start = parseInt($yearUl.find('li:first').attr('data-year'), 10); - for (i=(start-1); i >(start-11); i--) { + for (i = (start - 1); i > (start - 11); i--) { $yearUl.prepend('
  • '); } this.artificialScrolling = true; - $yearUl.scrollTop(($yearUl.get(0).scrollHeight-scrollHeight) + scrollTop); + $yearUl.scrollTop(($yearUl.get(0).scrollHeight - scrollHeight) + scrollTop); this.artificialScrolling = false; - }else if(bottomPercentage>90){ + } else if (bottomPercentage > 90) { start = parseInt($yearUl.find('li:last').attr('data-year'), 10); - for(i=(start+1); i<(start+11); i++){ + for (i = (start + 1); i < (start + 11); i++) { $yearUl.append('
  • '); } } }, //some code ripped from http://stackoverflow.com/questions/2182246/javascript-dates-in-ie-nan-firefox-chrome-ok - parseDate: function(date) { + parseDate: function (date) { var self = this; var BAD_DATE = new Date(NaN); var dt, isoExp, momentParse, momentParseWithFormat, tryMomentParseAll, month, parts, use; - if(date){ - if(this.moment){ //if we have moment, use that to parse the dates - momentParseWithFormat = function(d) { + if (date) { + if (this.moment) {//if we have moment, use that to parse the dates + momentParseWithFormat = function (d) { var md = moment(d, self.momentFormat); return (true === md.isValid()) ? md.toDate() : BAD_DATE; }; - momentParse = function(d) { - var md = moment( new Date(d) ); + momentParse = function (d) { + var md = moment(new Date(d)); return (true === md.isValid()) ? md.toDate() : BAD_DATE; }; - tryMomentParseAll = function(d, parseFunc1, parseFunc2) { + tryMomentParseAll = function (d, parseFunc1, parseFunc2) { var pd = parseFunc1(d); if (!self.isInvalidDate(pd)) { return pd; } + pd = parseFunc2(pd); if (!self.isInvalidDate(pd)) { return pd; } + return BAD_DATE; }; - if ('string' === typeof(date)) { + if ('string' === typeof (date)) { // Attempts to parse date strings using this.momentFormat, falling back on newing a date return tryMomentParseAll(date, momentParseWithFormat, momentParse); } else { // Attempts to parse date by newing a date object directly, falling back on parsing using this.momentFormat return tryMomentParseAll(date, momentParse, momentParseWithFormat); } - }else{ //if moment isn't present, use previous date parsing strategy - if(typeof(date)==='string'){ + + } else {//if moment isn't present, use previous date parsing strategy + if (typeof (date) === 'string') { dt = new Date(Date.parse(date)); - if(!this.isInvalidDate(dt)){ + if (!this.isInvalidDate(dt)) { return dt; - }else{ + } else { date = date.split('T')[0]; isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/; parts = isoExp.exec(date); - if(parts){ - month = parseInt(parts[2],10); + if (parts) { + month = parseInt(parts[2], 10); dt = new Date(parts[1], month - 1, parts[3]); - if(month===(dt.getMonth() + 1)){ + if (month === (dt.getMonth() + 1)) { return dt; } + } + } - }else{ + + } else { dt = new Date(date); - if(!this.isInvalidDate(dt)){ + if (!this.isInvalidDate(dt)) { return dt; } + } + } + } + return new Date(NaN); }, - prev: function(){ + prev: function () { var month = this.$headerTitle.attr('data-month'); var year = this.$headerTitle.attr('data-year'); month--; - if(month<0){ - if(this.sameYearOnly){ + if (month < 0) { + if (this.sameYearOnly) { return; } + month = 11; year--; } + this.renderMonth(new Date(year, month, 1)); }, - renderMonth: function(date){ + renderMonth: function (date) { date = date || new Date(); var firstDay = new Date(date.getFullYear(), date.getMonth(), 1).getDay(); @@ -444,7 +473,7 @@ var year = date.getFullYear(); var curDate, curMonth, curYear, i, j, rows, stage, $td, $tr; - if(selected){ + if (selected) { selected = { date: selected.getDate(), month: selected.getMonth(), @@ -461,62 +490,70 @@ }); $tbody.empty(); - if(firstDay!==0){ + if (firstDay !== 0) { curDate = lastMonthDate - firstDay + 1; stage = -1; - }else{ + } else { curDate = 1; stage = 0; } - rows = (lastDate<=(35-firstDay)) ? 5 : 6; - for(i=0; i'); - for(j=0; j<7; j++){ + for (j = 0; j < 7; j++) { $td = $(''); - if(stage===-1){ + if (stage === -1) { $td.addClass('last-month'); - }else if(stage===1){ + } else if (stage === 1) { $td.addClass('next-month'); } curMonth = month + stage; curYear = year; - if(curMonth<0){ + if (curMonth < 0) { curMonth = 11; curYear--; - }else if(curMonth>11){ + } else if (curMonth > 11) { curMonth = 0; curYear++; } - $td.attr({ 'data-date': curDate, 'data-month': curMonth, 'data-year': curYear }); - if(curYear===nowYear && curMonth===nowMonth && curDate===nowDate){ + $td.attr({ + 'data-date': curDate, + 'data-month': curMonth, + 'data-year': curYear + }); + if (curYear === nowYear && curMonth === nowMonth && curDate === nowDate) { $td.addClass('current-day'); - }else if(curYear' + curDate + ''); - }else{ + } else { $td.html(''); } curDate++; - if(stage===-1 && curDate>lastMonthDate){ + if (stage === -1 && curDate > lastMonthDate) { curDate = 1; stage = 0; - }else if(stage===0 && curDate>lastDate){ + } else if (stage === 0 && curDate > lastDate) { curDate = 1; stage = 1; } @@ -527,17 +564,17 @@ } }, - renderWheel: function(date){ + renderWheel: function (date) { var month = date.getMonth(); var $monthUl = this.$wheelsMonth.find('ul'); var year = date.getFullYear(); var $yearUl = this.$wheelsYear.find('ul'); var i, $monthSelected, $yearSelected; - if(this.sameYearOnly){ + if (this.sameYearOnly) { this.$wheelsMonth.addClass('full'); this.$wheelsYear.addClass('hide'); - }else{ + } else { this.$wheelsMonth.removeClass('full'); this.$wheelsYear.removeClass('hide'); } @@ -545,99 +582,122 @@ $monthUl.find('.selected').removeClass('selected'); $monthSelected = $monthUl.find('li[data-month="' + month + '"]'); $monthSelected.addClass('selected'); - $monthUl.scrollTop($monthUl.scrollTop() + ($monthSelected.position().top - $monthUl.outerHeight()/2 - $monthSelected.outerHeight(true)/2)); + $monthUl.scrollTop($monthUl.scrollTop() + ($monthSelected.position().top - $monthUl.outerHeight() / 2 - $monthSelected.outerHeight(true) / 2)); $yearUl.empty(); - for(i=(year-10); i<(year+11); i++){ + for (i = (year - 10); i < (year + 11); i++) { $yearUl.append('
  • '); } $yearSelected = $yearUl.find('li[data-year="' + year + '"]'); $yearSelected.addClass('selected'); this.artificialScrolling = true; - $yearUl.scrollTop($yearUl.scrollTop() + ($yearSelected.position().top - $yearUl.outerHeight()/2 - $yearSelected.outerHeight(true)/2)); + $yearUl.scrollTop($yearUl.scrollTop() + ($yearSelected.position().top - $yearUl.outerHeight() / 2 - $yearSelected.outerHeight(true) / 2)); this.artificialScrolling = false; $monthSelected.find('button').focus(); }, - selectClicked: function(){ + selectClicked: function () { var month = this.$wheelsMonth.find('.selected').attr('data-month'); var year = this.$wheelsYear.find('.selected').attr('data-year'); this.changeView('calendar', new Date(year, month, 1)); }, - setCulture: function(cultureCode){ - if(!cultureCode){ return false; } - if(this.moment){ + setCulture: function (cultureCode) { + if (!cultureCode) { + return false; + } + + if (this.moment) { moment.locale(cultureCode); - }else{ + } else { throw MOMENT_NOT_AVAILABLE; } }, - setDate: function(date){ + setDate: function (date) { var parsed = this.parseDate(date); - if(!this.isInvalidDate(parsed)){ - if(!this.isRestricted(parsed.getDate(), parsed.getMonth(), parsed.getFullYear())){ + if (!this.isInvalidDate(parsed)) { + if (!this.isRestricted(parsed.getDate(), parsed.getMonth(), parsed.getFullYear())) { this.selectedDate = parsed; this.renderMonth(parsed); this.$input.val(this.formatDate(parsed)); - }else{ + } else { this.selectedDate = false; this.renderMonth(); } - }else{ + + } else { this.selectedDate = null; this.renderMonth(); } + this.inputValue = this.$input.val(); return this.selectedDate; }, - setFormat: function(format){ - if(!format){ return false; } - if(this.moment){ + setFormat: function (format) { + if (!format) { + return false; + } + + if (this.moment) { this.momentFormat = format; - }else{ + } else { throw MOMENT_NOT_AVAILABLE; } }, - setRestrictedDates: function(restricted){ + setRestrictedDates: function (restricted) { var parsed = []; var self = this; var i, l; - var parseItem = function(val){ - if(val===-Infinity){ - return { date: -Infinity, month: -Infinity, year: -Infinity }; - }else if(val===Infinity){ - return { date: Infinity, month: Infinity, year: Infinity }; - }else{ + var parseItem = function (val) { + if (val === -Infinity) { + return { + date: -Infinity, + month: -Infinity, + year: -Infinity + }; + } else if (val === Infinity) { + return { + date: Infinity, + month: Infinity, + year: Infinity + }; + } else { val = self.parseDate(val); - return { date: val.getDate(), month: val.getMonth(), year: val.getFullYear() }; + return { + date: val.getDate(), + month: val.getMonth(), + year: val.getFullYear() + }; } }; this.restricted = restricted; - for(i=0,l=restricted.length; i= measurements.fromTop && measurements.dropdownHeight >= measurements.fromBottom ) { + } else if (measurements.dropdownHeight >= measurements.fromTop && measurements.dropdownHeight >= measurements.fromBottom) { // decide which one is bigger and put it there - if( measurements.fromTop >= measurements.fromBottom ) { + if (measurements.fromTop >= measurements.fromBottom) { return true; } else { return false; } + } + } - function _getContainer( element ) { + function _getContainer(element) { var containerElement, isWindow; - if (element.attr('data-target')){ + if (element.attr('data-target')) { containerElement = element.attr('data-target'); isWindow = false; - } - else { + } else { containerElement = window; isWindow = true; } - $.each( element.parents(), function(index, value) { - if( $(value).css('overflow') !== 'visible' ) { + $.each(element.parents(), function (index, value) { + if ($(value).css('overflow') !== 'visible') { containerElement = value; isWindow = false; return false; @@ -108,14 +112,16 @@ }); return { - overflowElement: $( containerElement ), + overflowElement: $(containerElement), isWindow: isWindow }; } // register empty plugin - $.fn.dropdownautoflip = function () { /* empty */ }; + $.fn.dropdownautoflip = function () { + /* empty */ + }; -// -- BEGIN UMD WRAPPER AFTERWORD -- + // -- BEGIN UMD WRAPPER AFTERWORD -- })); - // -- END UMD WRAPPER AFTERWORD -- \ No newline at end of file +// -- END UMD WRAPPER AFTERWORD -- diff --git a/js/infinite-scroll.js b/js/infinite-scroll.js index fba2f74fe..22631ac14 100644 --- a/js/infinite-scroll.js +++ b/js/infinite-scroll.js @@ -45,7 +45,7 @@ constructor: InfiniteScroll, - destroy: function() { + destroy: function () { this.$element.remove(); // any external bindings // [none] @@ -56,52 +56,58 @@ return this.$element[0].outerHTML; }, - disable: function(){ + disable: function () { this.$element.off('scroll.fu.infinitescroll'); }, - enable: function(){ + enable: function () { this.$element.on('scroll.fu.infinitescroll', $.proxy(this.onScroll, this)); }, - end: function(content){ + end: function (content) { var end = $('
    '); - if(content){ + if (content) { end.append(content); - }else{ + } else { end.append('---------'); } + this.$element.append(end); this.disable(); }, - getPercentage: function(){ - var height = (this.$element.css('box-sizing')==='border-box') ? this.$element.outerHeight() : this.$element.height(); + getPercentage: function () { + var height = (this.$element.css('box-sizing') === 'border-box') ? this.$element.outerHeight() : this.$element.height(); var scrollHeight = this.$element.get(0).scrollHeight; return (scrollHeight > height) ? ((height / (scrollHeight - this.curScrollTop)) * 100) : 0; }, - fetchData: function(force){ + fetchData: function (force) { var load = $('
    '); var self = this; var moreBtn; - var fetch = function(){ - var helpers = { percentage: self.curPercentage, scrollTop: self.curScrollTop }; + var fetch = function () { + var helpers = { + percentage: self.curPercentage, + scrollTop: self.curScrollTop + }; var $loader = $('
    '); load.append($loader); $loader.loader(); - if(self.options.dataSource){ - self.options.dataSource(helpers, function(resp){ + if (self.options.dataSource) { + self.options.dataSource(helpers, function (resp) { var end; load.remove(); - if(resp.content){ + if (resp.content) { self.$element.append(resp.content); } - if(resp.end){ - end = (resp.end!==true) ? resp.end : undefined; + + if (resp.end) { + end = (resp.end !== true) ? resp.end : undefined; self.end(end); } + self.fetchingData = false; }); } @@ -109,55 +115,56 @@ this.fetchingData = true; this.$element.append(load); - if(this.options.hybrid && force!==true){ + if (this.options.hybrid && force !== true) { moreBtn = $(''); - if(typeof this.options.hybrid === 'object'){ + if (typeof this.options.hybrid === 'object') { moreBtn.append(this.options.hybrid.label); - }else{ + } else { moreBtn.append(''); } - moreBtn.on('click.fu.infinitescroll', function(){ + + moreBtn.on('click.fu.infinitescroll', function () { moreBtn.remove(); fetch(); }); load.append(moreBtn); - }else{ + } else { fetch(); } }, - onScroll: function(e){ + onScroll: function (e) { this.curScrollTop = this.$element.scrollTop(); this.curPercentage = this.getPercentage(); - if(!this.fetchingData && this.curPercentage>=this.options.percentage){ + if (!this.fetchingData && this.curPercentage >= this.options.percentage) { this.fetchData(); } } - }; // INFINITE SCROLL PLUGIN DEFINITION $.fn.infinitescroll = function (option) { - var args = Array.prototype.slice.call( arguments, 1 ); + var args = Array.prototype.slice.call(arguments, 1); var methodReturn; var $set = this.each(function () { - var $this = $( this ); - var data = $this.data('fu.infinitescroll'); + var $this = $(this); + var data = $this.data('fu.infinitescroll'); var options = typeof option === 'object' && option; - if( !data ) $this.data('fu.infinitescroll', (data = new InfiniteScroll( this, options ) ) ); - if( typeof option === 'string' ) methodReturn = data[ option ].apply( data, args ); + if (!data) $this.data('fu.infinitescroll', (data = new InfiniteScroll(this, options))); + if (typeof option === 'string') + methodReturn = data[option].apply(data, args); }); - return ( methodReturn === undefined ) ? $set : methodReturn; + return (methodReturn === undefined) ? $set : methodReturn; }; $.fn.infinitescroll.defaults = { dataSource: null, - hybrid: false, //can be true or an object with structure: { 'label': (markup or jQuery obj) } - percentage: 95 //percentage scrolled to the bottom before more is loaded + hybrid: false,//can be true or an object with structure: { 'label': (markup or jQuery obj) } + percentage: 95//percentage scrolled to the bottom before more is loaded }; $.fn.infinitescroll.Constructor = InfiniteScroll; @@ -169,6 +176,6 @@ // NO DATA-API DUE TO NEED OF DATA-SOURCE -// -- BEGIN UMD WRAPPER AFTERWORD -- + // -- BEGIN UMD WRAPPER AFTERWORD -- })); -// -- END UMD WRAPPER AFTERWORD -- \ No newline at end of file +// -- END UMD WRAPPER AFTERWORD -- diff --git a/js/loader.js b/js/loader.js index 05947eb99..34e31f21d 100644 --- a/js/loader.js +++ b/js/loader.js @@ -20,9 +20,9 @@ factory(jQuery); } }(function ($) { -// -- END UMD WRAPPER PREFACE -- + // -- END UMD WRAPPER PREFACE -- -// -- BEGIN MODULE CODE HERE -- + // -- BEGIN MODULE CODE HERE -- var old = $.fn.loader; @@ -40,7 +40,7 @@ this.timeout = {}; var ieVer = this.msieVersion(); - if(ieVer!==false && ieVer<9){ + if (ieVer !== false && ieVer < 9) { this.$element.addClass('iefix'); this.isIElt9 = true; } @@ -53,7 +53,7 @@ constructor: Loader, - destroy: function() { + destroy: function () { this.$element.remove(); // any external bindings // [none] @@ -63,77 +63,79 @@ return this.$element[0].outerHTML; }, - ieRepaint: function(){ - if(this.isIElt9){ + ieRepaint: function () { + if (this.isIElt9) { this.$element.addClass('iefix_repaint').removeClass('iefix_repaint'); } }, - msieVersion: function(){ + msieVersion: function () { var ua = window.navigator.userAgent; var msie = ua.indexOf('MSIE '); - if(msie>0){ - return parseInt(ua.substring(msie+5, ua.indexOf(".", msie )), 10); - }else{ + if (msie > 0) { + return parseInt(ua.substring(msie + 5, ua.indexOf(".", msie)), 10); + } else { return false; } }, - next: function(){ + next: function () { this.frame++; - if(this.frame>this.end){ + if (this.frame > this.end) { this.frame = this.begin; } + this.$element.attr('data-frame', this.frame + ''); this.ieRepaint(); }, - pause: function(){ + pause: function () { clearTimeout(this.timeout); }, - play: function(){ + play: function () { var self = this; clearTimeout(this.timeout); - this.timeout = setTimeout(function(){ + this.timeout = setTimeout(function () { self.next(); self.play(); }, this.delay); }, - previous: function(){ + previous: function () { this.frame--; - if(this.frame li', $.proxy(this.suggestionClick, this)); } + if (this.options.edit) { this.$element.addClass('pills-editable'); this.$element.on('blur.fu.pillbox', '.pillbox-add-item', $.proxy(this.cancelEdit, this)); @@ -75,7 +77,7 @@ Pillbox.prototype = { constructor: Pillbox, - destroy: function() { + destroy: function () { this.$element.remove(); // any external bindings // [none] @@ -85,15 +87,15 @@ return this.$element[0].outerHTML; }, - items: function() { + items: function () { var self = this; - return this.$pillGroup.children('.pill').map(function() { + return this.$pillGroup.children('.pill').map(function () { return self.getItemData($(this)); }).get(); }, - itemClicked: function(e) { + itemClicked: function (e) { var self = this; var $target = $(e.target); var $item; @@ -115,14 +117,18 @@ el: $item })); } + return false; } else if (this.options.edit) { if ($item.find('.pillbox-list-edit').length) { return false; } + this.openEdit($item); } + } + } else { $item = $target; } @@ -130,18 +136,19 @@ this.$element.trigger('clicked.fu.pillbox', this.getItemData($item)); }, - readonly: function(enable) { + readonly: function (enable) { if (enable) { this.$element.attr('data-readonly', 'readonly'); } else { this.$element.removeAttr('data-readonly'); } + if (this.options.truncate) { this.truncate(enable); } }, - suggestionClick: function(e) { + suggestionClick: function (e) { var $item = $(e.currentTarget); var item = { text: $item.html(), @@ -163,14 +170,14 @@ this._closeSuggestions(); }, - itemCount: function() { + itemCount: function () { return this.$pillGroup.children('.pill').length; }, // First parameter is 1 based index (optional, if index is not passed all new items will be appended) // Second parameter can be array of objects [{ ... }, { ... }] or you can pass n additional objects as args // object structure is as follows (index and value are optional): { text: '', value: '' } - addItems: function() { + addItems: function () { var self = this; var items, index, isInternal; @@ -188,7 +195,7 @@ } if (items.length) { - $.each(items, function(i, value) { + $.each(items, function (i, value) { var data = { text: value.text, value: (value.value ? value.value : value.text), @@ -196,7 +203,7 @@ }; if (value['attr']) { - data['attr'] = value.attr; // avoid confusion with $.attr(); + data['attr'] = value.attr;// avoid confusion with $.attr(); } if (value['data']) { @@ -204,7 +211,6 @@ } items[i] = data; - }); if (this.options.edit && this.currentEdit) { @@ -216,12 +222,12 @@ } if (self.options.onAdd && isInternal) { - if (this.options.edit && this.currentEdit) { self.options.onAdd(items[0], $.proxy(self.saveEdit, this)); } else { self.options.onAdd(items[0], $.proxy(self.placeItems, this)); } + } else { if (this.options.edit && this.currentEdit) { self.saveEdit(items); @@ -231,15 +237,17 @@ } else { self.placeItems(items, isInternal); } + } + } - } + } }, //First parameter is the index (1 based) to start removing items //Second parameter is the number of items to be removed - removeItems: function(index, howMany) { + removeItems: function (index, howMany) { var self = this; var count; var $currentItem; @@ -260,13 +268,14 @@ } else { break; } + } } }, //First parameter is index (optional) //Second parameter is new arguments - placeItems: function() { + placeItems: function () { var $newHtml = []; var items; var index; @@ -286,7 +295,7 @@ } if (items.length) { - $.each(items, function(i, item) { + $.each(items, function (i, item) { var $item = $(item.el); var $neighbor; @@ -295,14 +304,12 @@ // DOM attributes if (item['attr']) { - $.each(item['attr'], function(key, value) { - + $.each(item['attr'], function (key, value) { if (key === 'cssClass' || key === 'class') { $item.addClass(value); } else { $item.attr(key, value); } - }); } @@ -323,9 +330,11 @@ } else { this.$pillGroup.children('.pill:last').after($newHtml); } + } else { this.$pillGroup.children('.pill:last').after($newHtml); } + } else { this.$pillGroup.prepend($newHtml); } @@ -336,10 +345,11 @@ value: items[0].value }); } + } }, - inputEvent: function(e) { + inputEvent: function (e) { var self = this; var text = this.$addItem.val(); var value; @@ -348,7 +358,6 @@ var $selection; if (this.acceptKeyCodes[e.keyCode]) { - if (this.options.onKeyDown && this._isSuggestionsOpen()) { $selection = this.$suggest.find('.pillbox-suggest-sel'); @@ -357,6 +366,7 @@ value = $selection.data('value'); attr = $selection.data('attr'); } + } //ignore comma and make sure text that has been entered (protects against " ,". https://github.com/ExactTarget/fuelux/issues/593), unless allowEmptyPills is true. @@ -377,7 +387,7 @@ }, true); } - setTimeout(function() { + setTimeout(function () { self.$addItem.show().val('').attr({ size: 10 }); @@ -411,12 +421,14 @@ return true; } + } else if (text.length > 10) { if (this.$addItem.width() < (this.$pillGroup.width() - 6)) { this.$addItem.attr({ size: text.length + 3 }); } + } this.$pillGroup.find('.pill').removeClass('pillbox-highlight'); @@ -430,6 +442,7 @@ if (this._isSuggestionsOpen()) { this._keySuggestions(e); } + return true; } @@ -438,13 +451,13 @@ this.options.onKeyDown({ event: e, value: text - }, function(data) { + }, function (data) { self._openSuggestions(e, data); }); } }, - openEdit: function(el) { + openEdit: function (el) { var index = el.index() + 1; var $addItemWrap = this.$addItemWrap.detach().hide(); @@ -457,7 +470,7 @@ this.$addItem.focus().select(); }, - cancelEdit: function(e) { + cancelEdit: function (e) { var $addItemWrap; if (!this.currentEdit) { return false; @@ -467,6 +480,7 @@ if (e) { this.$addItemWrap.before(this.currentEdit); } + this.currentEdit = false; $addItemWrap = this.$addItemWrap.detach(); @@ -477,7 +491,7 @@ //Must match syntax of placeItem so addItem callback is called when an item is edited //expecting to receive an array back from the callback containing edited items - saveEdit: function() { + saveEdit: function () { var item = arguments[0][0] ? arguments[0][0] : arguments[0]; this.currentEdit = $(item.el); @@ -497,11 +511,11 @@ }); }, - removeBySelector: function() { + removeBySelector: function () { var selectors = [].slice.call(arguments).slice(0); var self = this; - $.each(selectors, function(i, sel) { + $.each(selectors, function (i, sel) { self.$pillGroup.find(sel).remove(); }); @@ -511,11 +525,11 @@ }); }, - removeByValue: function() { + removeByValue: function () { var values = [].slice.call(arguments).slice(0); var self = this; - $.each(values, function(i, val) { + $.each(values, function (i, val) { self.$pillGroup.find('> .pill[data-value="' + val + '"]').remove(); }); @@ -525,11 +539,11 @@ }); }, - removeByText: function() { + removeByText: function () { var text = [].slice.call(arguments).slice(0); var self = this; - $.each(text, function(i, text) { + $.each(text, function (i, text) { self.$pillGroup.find('> .pill:contains("' + text + '")').remove(); }); @@ -539,7 +553,7 @@ }); }, - truncate: function(enable) { + truncate: function (enable) { var self = this; var available, full, i, pills, used; @@ -556,7 +570,7 @@ pills = this.$pillGroup.find('.pill').length; used = 0; - this.$pillGroup.find('.pill').each(function() { + this.$pillGroup.find('.pill').each(function () { var pill = $(this); if (!full) { i++; @@ -568,6 +582,7 @@ pill.addClass('truncated'); full = true; } + } else { pill.addClass('truncated'); } @@ -575,40 +590,41 @@ if (i === pills) { this.$addItemWrap.addClass('truncated'); } + } }, - inputFocus: function(e) { + inputFocus: function (e) { this.$element.find('.pillbox-add-item').focus(); }, - getItemData: function(el, data) { + getItemData: function (el, data) { return $.extend({ text: el.find('span:first').html() }, el.data(), data); }, - _removeElement: function(data) { + _removeElement: function (data) { data.el.remove(); delete data.el; this.$element.trigger('removed.fu.pillbox', data); }, - _removePillTrigger: function(removedBy) { + _removePillTrigger: function (removedBy) { this.$element.trigger('removed.fu.pillbox', removedBy); }, - _generateObject: function(data) { + _generateObject: function (data) { var obj = {}; - $.each(data, function(index, value) { + $.each(data, function (index, value) { obj[value] = true; }); return obj; }, - _openSuggestions: function(e, data) { + _openSuggestions: function (e, data) { var markup = ''; var $suggestionList = $('