// jQuery Genome ID Selection Helper Plugin jQuery.genome = function(jel_selector, jel_scope) { if(typeof(jel_selector) != 'string') { return jQuery(jel_selector); } jel_selector = jel_selector.replace(/\[/g, '\\[').replace(/\]/g, '\\]'); var useScope = false; if(typeof(jel_scope) != 'undefined') { useScope = true; } var jel = null; if(useScope) { jel = jQuery(jel_selector, jel_scope); } else { jel = jQuery(jel_selector); } if(! jel.size() && typeof(jel_selector) == 'string') { if(jel_selector.substr(0, 1) != '#') { if(useScope) { jel = jQuery('#' + jel_selector, jel_scope); } else { jel = jQuery('#' + jel_selector); } } } return jel; }; // Ensure that the MMI "namespace" is available. if(typeof(window['MMI']) === 'undefined') { window.MMI = {}; } if(typeof(window.MMI['Exception']) === 'undefined') { window.MMI.Exception = function(message, code, method) { if(typeof(code) == 'undefined') { code = 0; } if(typeof(method) == 'string') { return 'MMI.Exception [' + code + '] ' + message + ' in ' + method; } else { return 'MMI.Exception [' + code + '] ' + message + ' in `unknown function`'; } }; } if(typeof(window.MMI['Util']) === 'undefined') { window.MMI.Util = {}; } MMI.Util = { config: { dump: true ,traceDumps: true ,log: true ,traceLogs: false ,trace: true ,group: true ,collapseGroups: true ,_hasConsole: false ,_hasConsoleDump: false ,_hasConsoleLog: false ,_hasConsoleTrace: false ,_hasConsoleGroup: false ,_hasConsoleGroupCollapsed: false ,_defaultArgumentDetailLevel: 2 } ,jsDir: '' ,imageDir: '' ,cssDir: '' ,_reservations: { 'locks': {}, 'oldValues': {} } // scope for now is always window - later I would like to set it up where you can reserve a variable name in any scope. /** Reserve * * @param string varName The name of the variable to reserve. */ ,reserve: function(varName) { if(typeof(MMI.Util._reservations['locks'][varName]) == 'undefined') { MMI.Util._reservations['locks'][varName] = true; MMI.Util._reservations['oldValues'][varName] = window[varName]; window[varName] = undefined; // Set this value to a clean value. } else { throw MMI.Exception('The variable `' + varName + '` is already reserved. Please release the reservation before using this variable name.', 0, 'MMI.Util.reserve()'); } } ,release: function(varName) { if(typeof(MMI.Util._reservations['locks'][varName]) != 'undefined' && MMI.Util._reservations['locks'][varName] === true) { window[varName] = MMI.Util._reservations['oldValues'][varName]; MMI.Util._reservations['locks'][varName] = undefined; MMI.Util._reservations['oldValues'][varName] = undefined; } } ,__init: function() { MMI.Util.config._hasConsole = (typeof(window.console) != 'undefined' && window.console != null && window.console); if(MMI.Util.config._hasConsole) { MMI.Util.config._hasConsoleDump = MMI.Util.isFunction(window.console.dir); MMI.Util.config._hasConsoleLog = MMI.Util.isFunction(window.console.log); MMI.Util.config._hasConsoleTrace = MMI.Util.isFunction(window.console.trace); MMI.Util.config._hasConsoleGroup = (MMI.Util.isFunction(window.console.group) && MMI.Util.isFunction(window.console.groupEnd)); MMI.Util.config._hasConsoleGroupCollapsed = (MMI.Util.isFunction(window.console.groupCollapsed) && MMI.Util.isFunction(window.console.groupEnd)); } MMI.Util.jsDir = MMI.Util.__DIR__(); MMI.Util.imageDir = MMI.Util.jsDir + '/utilities/images'; MMI.Util.cssDir = MMI.Util.jsDir + '/utilities/css'; } ,__FILE__: function() { var tag = document.getElementsByTagName('script'); var url = tag[tag.length-1]; if ('src' in url && url.src != '') { return url.src; } else { return window.location.href; } } /* Behaves like the __DIR__ magic constant in PHP. */ ,__DIR__: function() { return MMI.Util.dirname(MMI.Util.__FILE__()); } ,dirname: function(path) { return path.replace(/\\/g, '/').replace(/\/[^\/]*\/?$/, ''); } ,basename: function(path, suffix) { var b = path.replace(/^.*[\/\\]/g, ''); if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) { b = b.substr(0, b.length-suffix.length); } return b; } ,_strrchr: function(haystack, needle) { var pos = 0; if (typeof needle !== 'string') { needle = String.fromCharCode(parseInt(needle, 10)); } needle = needle.charAt(0); pos = haystack.lastIndexOf(needle); if (pos === -1) { return false; } return haystack.substr(pos); } ,substringReplace: function(str, replace, start, length) { if(start < 0) { // start position in str start = start + str.length; } length = length !== undefined ? length : str.length; if(length < 0) { length = length + str.length - start; } return str.slice(0, start)+replace.substr(0, length)+replace.slice(length)+str.slice(start+length); } ,'stringReplace': function(search, replace, subject, count) { var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0, f = [].concat(search), r = [].concat(replace), s = subject, ra = r instanceof Array, sa = s instanceof Array; s = [].concat(s); if (count) { this.window[count] = 0; } for (i=0, sl=s.length; i < sl; i++) { if (s[i] === '') { continue; } for (j=0, fl=f.length; j < fl; j++) { temp = s[i]+''; repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0]; s[i] = (temp).split(f[j]).join(repl); if (count && s[i] !== temp) { this.window[count] += (temp.length-s[i].length)/f[j].length;} } } return sa ? s : s[0]; } ,getFileExtension: function(path) { return MMI.Util._strrchr(path, '.'); } ,inArray: function(needle, haystack, argStrict) { var key = '', strict = !!argStrict; if (strict) { for (key in haystack) { if (haystack[key] === needle) { return true; } } } else { for (key in haystack) { if (haystack[key] == needle) { return true; } } } return false; }, 'arrayMerge': function() { var args = Array.prototype.slice.call(arguments), retObj = {}, k, j = 0, i = 0, retArr = true; for (i=0; i < args.length; i++) { if (!(args[i] instanceof Array)) { retArr=false; break; } } if (retArr) { retArr = []; for (i=0; i < args.length; i++) { retArr = retArr.concat(args[i]); } return retArr; } var ct = 0; for (i=0, ct=0; i < args.length; i++) { if (args[i] instanceof Array) { for (j=0; j < args[i].length; j++) { retObj[ct++] = args[i][j]; } } else { for (k in args[i]) { if (args[i].hasOwnProperty(k)) { if (parseInt(k, 10)+'' === k) { retObj[ct++] = args[i][k]; } else { retObj[k] = args[i][k]; } } } } } return retObj; } ,includeCss: function(url) { jQuery('head').append(''); } /* * Borrowed straight from Scriptaculous. */ ,includeJs: function(url) { jQuery('head').append('