UNPKG

webgme

Version:

Web-based Generic Modeling Environment

65 lines (53 loc) 1.53 kB
/*globals define, $ */ /*jshint browser: true*/ /** * @author rkereskenyi / https://github.com/rkereskenyi */ define([], function () { 'use strict'; function createButton(params) { var button, btnClass = 'btn btn-mini'; button = $('<a/>', { class: btnClass, href: '#', title: params.title, text: params.text }); if (params.data) { button.data(params.data); } if (params.icon) { if (typeof params.icon === 'string') { button.append($('<i/>', {class: params.icon})); } else { button.append(params.icon); } } if (params.text) { if (params.icon) { button.append(' '); } } if (params.clickFn) { button.on('click', function (event) { if (!button.hasClass('disabled')) { params.clickFn.call(this, $(this).data()); } if (params.clickFnEventCancel !== false) { event.stopPropagation(); event.preventDefault(); } }); } button.enabled = function (enabled) { if (enabled === true) { button.disable(false); } else { button.disable(true); } }; return button; } return {createButton: createButton}; });