(function() { var activate, fetchDescription, openContentBrowser, save, template; scrivito.on('load', function() { return scrivito.define_editor('link', scrivito.editors.link_editor); }); scrivito.editors.link_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=link]'); }, activate: function(element) { return activate($(element)); } }; fetchDescription = function(cmsField, objId) { return scrivito.description_for_editor([objId]).then(function(descriptions) { var urlInput; urlInput = cmsField.find('[name=url][data-value]'); if (descriptions[0]) { return urlInput.val(descriptions[0]); } }); }; activate = function(cmsField) { var link; link = cmsField.scrivito('content') || {}; cmsField.addClass('scrivito_editors_ui').html(template(link)); if (link.obj_id) { fetchDescription(cmsField, link.obj_id); } scrivito.editors._linkTargetEditing.activate(cmsField, cmsField.find('li'), link); cmsField.on('scrivito_editors_private:target_changed', function() { return save(cmsField); }).on('blur', 'input', function() { return save(cmsField); }).on('click', '[data-scrivito-editors-browse]', function() { return openContentBrowser(cmsField); }); return cmsField.find('[name=url]').on('focus', function() { var input, raw; input = $(this); raw = input.attr('data-value'); if (raw) { input.val(raw); } return input.removeAttr('data-value'); }); }; template = function(link) { var objUrl, title, url; if (link.obj_id) { objUrl = URI(scrivito.path_for_id(link.obj_id)).query(link.query || null).fragment(link.fragment || null); } url = link.url || objUrl || ''; title = link.title || ''; return $("