<commit_before>var annoLink;

(function($){
	var inputs = {}, ed;

	annoLink = {
		parentSelector: 'span[data-xmlel="ext-link"]',
		keySensitivity: 100,
		textarea: function() { return edCanvas; },

		init : function() {
			inputs.dialog = $('#anno-popup-link');
			inputs.submit = $('#anno-link-submit');
			inputs.url = $('#anno-link-url-field');
			inputs.title = $('#anno-link-title-field');
			inputs.alt = $('#anno-link-alt-field');

			// Bind event handlers
			inputs.dialog.keydown( annoLink.keydown );
			inputs.dialog.keyup( annoLink.keyup );
			inputs.submit.click( function(e){
				annoLink.update();
				e.preventDefault();
			});

			$('#anno-link-cancel').click(annoLink.close);

			inputs.dialog.bind('wpdialogrefresh', annoLink.refresh);
			inputs.dialog.bind('wpdialogbeforeopen', annoLink.beforeOpen);
			inputs.dialog.bind('wpdialogclose', annoLink.onClose);
		},

		beforeOpen : function() {
			annoLink.range = null;

			if ( ! annoLink.isMCE() && document.selection ) {
				annoLink.textarea().focus();
				annoLink.range = document.selection.createRange();
			}
		},

		isMCE : function() {
			return tinyMCEPopup && ( ed = tinyMCEPopup.editor ) && ! ed.isHidden();
		},

		refresh : function() {
			annoLink.mceRefresh();

			// Focus the URL field and highlight its contents.
			//     If this is moved above the selection changes,
			//     IE will show a flashing cursor over the dialog.
			inputs.url.focus()[0].select();
		},

		mceRefresh : function() {
			var e;
			ed = tinyMCEPopup.editor;

			tinyMCEPopup.restoreSelection();

			// If link exists, select proper values.
			if ( e = ed.dom.getParent(ed.selection.getNode(), this.parentSelector) ) {

				inputs.url.val( ed.dom.getAttrib(e, 'xlink:href'));
				inputs.title.val( ed.dom.getAttrib(e, 'title') );
				// Update save prompt.
				inputs.submit.val( annoLinkL10n.update );

			// If there's no link, set the default values.
			} else {
				annoLink.setDefaultValues();
			}

			tinyMCEPopup.storeSelection();
		},

		close : function() {
			tinyMCEPopup.close();
		},

		onClose: function() {
			if ( ! annoLink.isMCE() ) {
				annoLink.textarea().focus();
				if ( annoLink.range ) {
					annoLink.range.moveToBookmark( annoLink.range.getBookmark() );
					annoLink.range.select();
				}
			}
		},

		getAttrs : function() {
			var tmp_attrs = {};
			tmp_attrs['xlink:href'] = inputs.url.val();
			tmp_attrs['title'] = inputs.title.val();
			tmp_attrs['ext-link-type'] = 'uri';
			return tmp_attrs;
		},

		update : function() {
			var ed = tinyMCEPopup.editor,
				attrs = annoLink.getAttrs(),
				e, b;

			tinyMCEPopup.restoreSelection();
			e = ed.dom.getParent(ed.selection.getNode(), 'span');

			// If the values are empty, unlink and return
			if ( ! attrs['xlink:href'] || attrs['xlink:href'] == 'http://' ) {
				if ( e ) {
					tinyMCEPopup.execCommand("mceBeginUndoLevel");
					b = ed.selection.getBookmark();
					ed.dom.remove(e, 1);
					ed.selection.moveToBookmark(b);
					tinyMCEPopup.execCommand("mceEndUndoLevel");
					annoLink.close();
				}
				return;
			}

			tinyMCEPopup.execCommand("mceBeginUndoLevel");
			// Leverage the logic of CreateLink
			if (e == null) {
				tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});

				tinymce.each(ed.dom.select("a"), function(n) {
					if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
						var new_element = document.createElement('span');
					 	var old_innerHTML = n.innerHTML;

					 	attrs['class'] = 'ext-link';
					 	attrs['data-xmlel'] = 'ext-link';
						n.parentNode.replaceChild(new_element, n);
						e = new_element;
						ed.dom.setAttribs(e, attrs);
						e.innerHTML = old_innerHTML;
					}
				});

				// Sometimes WebKit lets a user create a link where
				// they shouldn't be able to. In this case, CreateLink
				// injects "#mce_temp_url#" into their content. Fix it.<commit_msg>Add xmlns for xlink to inline links<commit_after>var annoLink;

(function($){
	var inputs = {}, ed;

	annoLink = {
		parentSelector: 'span[data-xmlel="ext-link"]',
		keySensitivity: 100,
		textarea: function() { return edCanvas; },

		init : function() {
			inputs.dialog = $('#anno-popup-link');
			inputs.submit = $('#anno-link-submit');
			inputs.url = $('#anno-link-url-field');
			inputs.title = $('#anno-link-title-field');
			inputs.alt = $('#anno-link-alt-field');

			// Bind event handlers
			inputs.dialog.keydown( annoLink.keydown );
			inputs.dialog.keyup( annoLink.keyup );
			inputs.submit.click( function(e){
				annoLink.update();
				e.preventDefault();
			});

			$('#anno-link-cancel').click(annoLink.close);

			inputs.dialog.bind('wpdialogrefresh', annoLink.refresh);
			inputs.dialog.bind('wpdialogbeforeopen', annoLink.beforeOpen);
			inputs.dialog.bind('wpdialogclose', annoLink.onClose);
		},

		beforeOpen : function() {
			annoLink.range = null;

			if ( ! annoLink.isMCE() && document.selection ) {
				annoLink.textarea().focus();
				annoLink.range = document.selection.createRange();
			}
		},

		isMCE : function() {
			return tinyMCEPopup && ( ed = tinyMCEPopup.editor ) && ! ed.isHidden();
		},

		refresh : function() {
			annoLink.mceRefresh();

			// Focus the URL field and highlight its contents.
			//     If this is moved above the selection changes,
			//     IE will show a flashing cursor over the dialog.
			inputs.url.focus()[0].select();
		},

		mceRefresh : function() {
			var e;
			ed = tinyMCEPopup.editor;

			tinyMCEPopup.restoreSelection();

			// If link exists, select proper values.
			if ( e = ed.dom.getParent(ed.selection.getNode(), this.parentSelector) ) {

				inputs.url.val( ed.dom.getAttrib(e, 'xlink:href'));
				inputs.title.val( ed.dom.getAttrib(e, 'title') );
				// Update save prompt.
				inputs.submit.val( annoLinkL10n.update );

			// If there's no link, set the default values.
			} else {
				annoLink.setDefaultValues();
			}

			tinyMCEPopup.storeSelection();
		},

		close : function() {
			tinyMCEPopup.close();
		},

		onClose: function() {
			if ( ! annoLink.isMCE() ) {
				annoLink.textarea().focus();
				if ( annoLink.range ) {
					annoLink.range.moveToBookmark( annoLink.range.getBookmark() );
					annoLink.range.select();
				}
			}
		},

		getAttrs : function() {
			var tmp_attrs = {};
			tmp_attrs['xlink:href'] = inputs.url.val();
			tmp_attrs['title'] = inputs.title.val();
			tmp_attrs['ext-link-type'] = 'uri';
			return tmp_attrs;
		},

		update : function() {
			var ed = tinyMCEPopup.editor,
				attrs = annoLink.getAttrs(),
				e, b;

			tinyMCEPopup.restoreSelection();
			e = ed.dom.getParent(ed.selection.getNode(), 'span');

			// If the values are empty, unlink and return
			if ( ! attrs['xlink:href'] || attrs['xlink:href'] == 'http://' ) {
				if ( e ) {
					tinyMCEPopup.execCommand("mceBeginUndoLevel");
					b = ed.selection.getBookmark();
					ed.dom.remove(e, 1);
					ed.selection.moveToBookmark(b);
					tinyMCEPopup.execCommand("mceEndUndoLevel");
					annoLink.close();
				}
				return;
			}

			tinyMCEPopup.execCommand("mceBeginUndoLevel");
			// Leverage the logic of CreateLink
			if (e == null) {
				tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});

				tinymce.each(ed.dom.select("a"), function(n) {
					if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
						var new_element = document.createElement('span');
					 	var old_innerHTML = n.innerHTML;

					 	attrs['class'] = 'ext-link';
					 	attrs['data-xmlel'] = 'ext-link';
					 	attrs['xmlns:xlink'] = 'http://www.w3.org/1999/xlink';
						n.parentNode.replaceChild(new_element, n);
						e = new_element;
						ed.dom.setAttribs(e, attrs);
						e.innerHTML = old_innerHTML;
					}
				});

				// Sometimes WebKit lets a user create a link where
				// they shouldn't be able to. In this case, CreateLink
				// injects "#mce_temp_url#" into their content. Fix it.
{'fraction_non_alphanumeric': 0.16544210793007347, 'fraction_numerical': 0.0026602482898403852, 'mean_word_length': 3.1055642225689026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '525099', 'n_tokens_mistral': 3269, 'n_tokens_neox': 2695, 'n_words': 515}