Client build: modularize fa-icon button from ui.js

This commit is contained in:
Carl Eberhard
2014-12-09 12:55:24 -05:00
parent 76b523196a
commit 78a3869ca2
21 changed files with 123 additions and 68 deletions
@@ -0,0 +1,48 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else {
root.faIconButton = factory();
}
}(this, function () {
//============================================================================
/** Returns a jQuery object containing a clickable font-awesome button.
* options:
* tooltipConfig : option map for bootstrap tool tip
* classes : array of class names (will always be classed as icon-btn)
* disabled : T/F - add the 'disabled' class?
* title : tooltip/title string
* target : optional href target
* href : optional href
* faIcon : which font awesome icon to use
* onclick : function to call when the button is clicked
*/
var faIconButton = function( options ){
options = options || {};
options.tooltipConfig = options.tooltipConfig || { placement: 'bottom' };
options.classes = [ 'icon-btn' ].concat( options.classes || [] );
if( options.disabled ){
options.classes.push( 'disabled' );
}
var html = [
'<a class="', options.classes.join( ' ' ), '"',
(( options.title )?( ' title="' + options.title + '"' ):( '' )),
(( !options.disabled && options.target )? ( ' target="' + options.target + '"' ):( '' )),
' href="', (( !options.disabled && options.href )?( options.href ):( 'javascript:void(0);' )), '">',
// could go with something less specific here - like 'html'
'<span class="fa ', options.faIcon, '"></span>',
'</a>'
].join( '' );
var $button = $( html ).tooltip( options.tooltipConfig );
if( _.isFunction( options.onclick ) ){
$button.click( options.onclick );
}
return $button;
};
//============================================================================
return faIconButton;
}));
@@ -3,9 +3,10 @@ define([
"mvc/dataset/dataset-li",
"mvc/tags",
"mvc/annotations",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization"
], function( STATES, DATASET_LI, TAGS, ANNOTATIONS, BASE_MVC, _l ){
], function( STATES, DATASET_LI, TAGS, ANNOTATIONS, faIconButton, BASE_MVC, _l ){
//==============================================================================
var _super = DATASET_LI.DatasetListItemView;
/** @class Editing view for DatasetAssociation.
@@ -1,9 +1,10 @@
define([
"mvc/list/list-item",
"mvc/dataset/states",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization"
], function( LIST_ITEM, STATES, BASE_MVC, _l ){
], function( LIST_ITEM, STATES, faIconButton, BASE_MVC, _l ){
/* global Backbone */
/*==============================================================================
TODO:
@@ -1,8 +1,9 @@
define([
"mvc/dataset/states",
"mvc/history/hdca-li",
"jq-plugins/ui/fa-icon-button",
"utils/localization"
], function( STATES, HDCA_LI, _l ){
], function( STATES, HDCA_LI, faIconButton, _l ){
//==============================================================================
var _super = HDCA_LI.HDCAListItemView;
/** @class Editing view for HistoryDatasetCollectionAssociation.
@@ -7,6 +7,7 @@ define([
"mvc/history/hdca-li-edit",
"mvc/tags",
"mvc/annotations",
"jq-plugins/ui/fa-icon-button",
"utils/localization"
], function(
HPANEL,
@@ -17,6 +18,7 @@ define([
HDCA_LI_EDIT,
TAGS,
ANNOTATIONS,
faIconButton,
_l
){
/* =============================================================================
@@ -6,6 +6,7 @@ define([
"mvc/history/hdca-li",
"mvc/collection/collection-panel",
"mvc/user/user-model",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization",
"jq-plugins/ui/search-input"
@@ -17,6 +18,7 @@ define([
HDCA_LI,
COLLECTION_PANEL,
USER,
faIconButton,
BASE_MVC,
_l
){
-28
View File
@@ -486,31 +486,3 @@ PopupMenu.make_popup_menus = function( parent, menuSelector, buttonSelectorBuild
});
return popupMenusCreated;
};
//==============================================================================
var faIconButton = function( options ){
//TODO: move out of global
options = options || {};
options.tooltipConfig = options.tooltipConfig || { placement: 'bottom' };
options.classes = [ 'icon-btn' ].concat( options.classes || [] );
if( options.disabled ){
options.classes.push( 'disabled' );
}
var html = [
'<a class="', options.classes.join( ' ' ), '"',
(( options.title )?( ' title="' + options.title + '"' ):( '' )),
(( !options.disabled && options.target )? ( ' target="' + options.target + '"' ):( '' )),
' href="', (( !options.disabled && options.href )?( options.href ):( 'javascript:void(0);' )), '">',
// could go with something less specific here - like 'html'
'<span class="fa ', options.faIcon, '"></span>',
'</a>'
].join( '' );
var $button = $( html ).tooltip( options.tooltipConfig );
if( _.isFunction( options.onclick ) ){
$button.click( options.onclick );
}
return $button;
};
@@ -0,0 +1,48 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else {
root.faIconButton = factory();
}
}(this, function () {
//============================================================================
/** Returns a jQuery object containing a clickable font-awesome button.
* options:
* tooltipConfig : option map for bootstrap tool tip
* classes : array of class names (will always be classed as icon-btn)
* disabled : T/F - add the 'disabled' class?
* title : tooltip/title string
* target : optional href target
* href : optional href
* faIcon : which font awesome icon to use
* onclick : function to call when the button is clicked
*/
var faIconButton = function( options ){
options = options || {};
options.tooltipConfig = options.tooltipConfig || { placement: 'bottom' };
options.classes = [ 'icon-btn' ].concat( options.classes || [] );
if( options.disabled ){
options.classes.push( 'disabled' );
}
var html = [
'<a class="', options.classes.join( ' ' ), '"',
(( options.title )?( ' title="' + options.title + '"' ):( '' )),
(( !options.disabled && options.target )? ( ' target="' + options.target + '"' ):( '' )),
' href="', (( !options.disabled && options.href )?( options.href ):( 'javascript:void(0);' )), '">',
// could go with something less specific here - like 'html'
'<span class="fa ', options.faIcon, '"></span>',
'</a>'
].join( '' );
var $button = $( html ).tooltip( options.tooltipConfig );
if( _.isFunction( options.onclick ) ){
$button.click( options.onclick );
}
return $button;
};
//============================================================================
return faIconButton;
}));
@@ -3,9 +3,10 @@ define([
"mvc/dataset/dataset-li",
"mvc/tags",
"mvc/annotations",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization"
], function( STATES, DATASET_LI, TAGS, ANNOTATIONS, BASE_MVC, _l ){
], function( STATES, DATASET_LI, TAGS, ANNOTATIONS, faIconButton, BASE_MVC, _l ){
//==============================================================================
var _super = DATASET_LI.DatasetListItemView;
/** @class Editing view for DatasetAssociation.
+2 -1
View File
@@ -1,9 +1,10 @@
define([
"mvc/list/list-item",
"mvc/dataset/states",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization"
], function( LIST_ITEM, STATES, BASE_MVC, _l ){
], function( LIST_ITEM, STATES, faIconButton, BASE_MVC, _l ){
/* global Backbone */
/*==============================================================================
TODO:
+2 -1
View File
@@ -1,8 +1,9 @@
define([
"mvc/dataset/states",
"mvc/history/hdca-li",
"jq-plugins/ui/fa-icon-button",
"utils/localization"
], function( STATES, HDCA_LI, _l ){
], function( STATES, HDCA_LI, faIconButton, _l ){
//==============================================================================
var _super = HDCA_LI.HDCAListItemView;
/** @class Editing view for HistoryDatasetCollectionAssociation.
@@ -7,6 +7,7 @@ define([
"mvc/history/hdca-li-edit",
"mvc/tags",
"mvc/annotations",
"jq-plugins/ui/fa-icon-button",
"utils/localization"
], function(
HPANEL,
@@ -17,6 +18,7 @@ define([
HDCA_LI_EDIT,
TAGS,
ANNOTATIONS,
faIconButton,
_l
){
/* =============================================================================
@@ -6,6 +6,7 @@ define([
"mvc/history/hdca-li",
"mvc/collection/collection-panel",
"mvc/user/user-model",
"jq-plugins/ui/fa-icon-button",
"mvc/base-mvc",
"utils/localization",
"jq-plugins/ui/search-input"
@@ -17,6 +18,7 @@ define([
HDCA_LI,
COLLECTION_PANEL,
USER,
faIconButton,
BASE_MVC,
_l
){
-28
View File
@@ -486,31 +486,3 @@ PopupMenu.make_popup_menus = function( parent, menuSelector, buttonSelectorBuild
});
return popupMenusCreated;
};
//==============================================================================
var faIconButton = function( options ){
//TODO: move out of global
options = options || {};
options.tooltipConfig = options.tooltipConfig || { placement: 'bottom' };
options.classes = [ 'icon-btn' ].concat( options.classes || [] );
if( options.disabled ){
options.classes.push( 'disabled' );
}
var html = [
'<a class="', options.classes.join( ' ' ), '"',
(( options.title )?( ' title="' + options.title + '"' ):( '' )),
(( !options.disabled && options.target )? ( ' target="' + options.target + '"' ):( '' )),
' href="', (( !options.disabled && options.href )?( options.href ):( 'javascript:void(0);' )), '">',
// could go with something less specific here - like 'html'
'<span class="fa ', options.faIcon, '"></span>',
'</a>'
].join( '' );
var $button = $( html ).tooltip( options.tooltipConfig );
if( _.isFunction( options.onclick ) ){
$button.click( options.onclick );
}
return $button;
};
@@ -0,0 +1 @@
(function(a,b){if(typeof define==="function"&&define.amd){define([],b)}else{a.faIconButton=b()}}(this,function(){var a=function(b){b=b||{};b.tooltipConfig=b.tooltipConfig||{placement:"bottom"};b.classes=["icon-btn"].concat(b.classes||[]);if(b.disabled){b.classes.push("disabled")}var c=['<a class="',b.classes.join(" "),'"',((b.title)?(' title="'+b.title+'"'):("")),((!b.disabled&&b.target)?(' target="'+b.target+'"'):("")),' href="',((!b.disabled&&b.href)?(b.href):("javascript:void(0);")),'">','<span class="fa ',b.faIcon,'"></span>',"</a>"].join("");var d=$(c).tooltip(b.tooltipConfig);if(_.isFunction(b.onclick)){d.click(b.onclick)}return d};return a}));
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
define(["mvc/dataset/states","mvc/history/hdca-li","utils/localization"],function(a,e,b){var c=e.HDCAListItemView;var d=c.extend({_renderPrimaryActions:function(){this.log(this+"._renderPrimaryActions");return c.prototype._renderPrimaryActions.call(this).concat([this._renderDeleteButton()])},_renderDeleteButton:function(){var g=this,f=this.model.get("deleted");return faIconButton({title:f?b("Dataset collection is already deleted"):b("Delete"),classes:"delete-btn",faIcon:"fa-times",disabled:f,onclick:function(){g.$el.find(".icon-btn.delete-btn").trigger("mouseout");g.model["delete"]()}})},toString:function(){var f=(this.model)?(this.model+""):("(no model)");return"HDCAListItemEdit("+f+")"}});return{HDCAListItemEdit:d}});
define(["mvc/dataset/states","mvc/history/hdca-li","jq-plugins/ui/fa-icon-button","utils/localization"],function(a,f,c,b){var d=f.HDCAListItemView;var e=d.extend({_renderPrimaryActions:function(){this.log(this+"._renderPrimaryActions");return d.prototype._renderPrimaryActions.call(this).concat([this._renderDeleteButton()])},_renderDeleteButton:function(){var h=this,g=this.model.get("deleted");return c({title:g?b("Dataset collection is already deleted"):b("Delete"),classes:"delete-btn",faIcon:"fa-times",disabled:g,onclick:function(){h.$el.find(".icon-btn.delete-btn").trigger("mouseout");h.model["delete"]()}})},toString:function(){var g=(this.model)?(this.model+""):("(no model)");return"HDCAListItemEdit("+g+")"}});return{HDCAListItemEdit:e}});
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long