var ActiveRecordProfiler = (function (my_module) { my_module = my_module || {}; var SOURCE_ROOT_KEY = "db_prof_source_root"; var SOURCE_EDITOR_KEY = "db_prof_source_editor"; var profilerSourceRootField, sourceEditorSelect, railsRoot, editorOptions, linkFormatters = {}; function supportsLocalStorage() { try { return (('localStorage' in window) && (window['localStorage'] !== null)); } catch (e) { return false; } } function setDBProfSourceRoot(value) { if (supportsLocalStorage()) { if (!!value) { window.localStorage[SOURCE_ROOT_KEY] = value; } else { window.localStorage.removeItem(SOURCE_ROOT_KEY); } } } function getDBProfSourceRoot() { var root = railsRoot; if (supportsLocalStorage()) { var localRoot = window.localStorage[SOURCE_ROOT_KEY]; if (!!localRoot) { root = localRoot; } } return root; } function setSourceEditor(value) { if (supportsLocalStorage()) { if (!!value) { window.localStorage[SOURCE_EDITOR_KEY] = value; } else { window.localStorage.removeItem(SOURCE_EDITOR_KEY); } } } function getSourceEditor() { if (supportsLocalStorage()) { return window.localStorage[SOURCE_EDITOR_KEY]; } else { return undefined; } } my_module.clearLinkFormatters = function () { $.each(linkFormatters, function (editorName, formatter) { if (editorOptions[editorName]) { editorOptions[editorName].remove(); } }); editorOptions = null; linkFormatters = {}; }; my_module.registerLinkFormatter = function (name, formatter) { if (!editorOptions) { editorOptions = {}; sourceEditorSelect.find('option').each(function (index, el) { jqElement = $(el); editorOptions[jqElement.text()] = jqElement; }); } linkFormatters[name] = formatter; if (!editorOptions[name]) { var newOption = $('