Sha256: 3d35a6de0489b410ce8c29ff5a001ea8a613fdf0698e3ed5aa5fcaff56443ab2
Contents?: true
Size: 1.74 KB
Versions: 4
Compression:
Stored size: 1.74 KB
Contents
/*jslint vars: true, white: true */ /*global jQuery, IQVOC */ IQVOC.ConceptMapper = (function($) { "use strict"; // `selector` is either a jQuery object, a DOM node or a string function ConceptMapper(selector) { if(arguments.length === 0) { // subclassing return; } this.root = selector.jquery ? selector : $(selector); this.matchTypes = this.determineMatchTypes(); var matchOptions = $.map(this.matchTypes, function(desc, id) { return $("<option />").val(id).text(desc)[0]; }); // spawn UI elements this.container = $("<div />").addClass("concept-mapper control-group"); this.input = $("<input />").attr("type", "text").addClass("form-control"). prependTo(this.container); $("<button />").addClass("btn btn-default fa fa-plus"). insertAfter(this.input).click($.proxy(this, "onConfirm")); this.matchType = $("<select />").addClass("form-control"). append(matchOptions).insertAfter(this.input); this.container.prependTo(this.root); } ConceptMapper.prototype.delimiter = ", "; ConceptMapper.prototype.onConfirm = function(ev) { ev.preventDefault(); var textAreaName = this.matchType.val(); var textArea = document.getElementsByName(textAreaName)[0]; textArea = $(textArea); var newURI = this.input.val(); var newValue = $.trim(textArea.val() + this.delimiter + newURI); textArea.val(newValue); this.input.val(""); this.root.trigger("concept-mapped", { uri: newURI, matchType: this.matchTypes[textAreaName] }); }; ConceptMapper.prototype.determineMatchTypes = function() { var data = {}; $("label", this.root).each(function(i, node) { var el = $(node); var fieldName = el.attr("for"); data[fieldName] = el.text(); }); return data; }; return ConceptMapper; }(jQuery));
Version data entries
4 entries across 4 versions & 1 rubygems