<commit_before>/**
 * scripts for the admin-UI
 *
 * @package WordPress
 * @subpackage WP Colored Coding
 * @requires jQuery framework
 */
 // jshint strict: true, undef: true, unused: true
( function($, wpCcGlobals) {
	"use strict";

	$( document ).ready(
		function() {

			/**
			 * buttons for the textarea
			 */
			//remember the selection
			$( document ).on(
				'blur',
				'.wp-cc-codearea',
				function() {
					/**
					 * cross-browser selectrion
					 *
					 * @link http://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea
					 */
					var getInputSelection = function( el ) {
						var start = 0,
							end = 0;
						if ( 'number' == typeof( el.selectionStart )  && 'number' == typeof( el.selectionEnd ) ) {
							start = el.selectionStart;
							end = el.selectionEnd;
						}
						//@todo IE support
						return {
							start: start,
							end: end
						};
					};
					this.ccSelection = getInputSelection( this );
				}
			);

			// set the cursor to the right position
			$( document ).on(
				'focus',
				'.wp-cc-codearea',
				function() {
					if ( 'number' == typeof( this.selectionStart ) && 'undefined' != typeof( this.ccSelection ) )
						this.selectionStart = this.selectionEnd = this.ccSelection.start;

				}
			);

			//insert a tab
			$( document ).on(
				'click',
				'.wp-cc-insert-tab',
				function( e ) {
					e.preventDefault();
					var textarea = document.getElementById( $( this ).attr( 'data-target-id' ) );
					var selection = textarea.ccSelection;
					var len = textarea.value.length;
					textarea.value = textarea.value.substr( 0, selection.start ) + "\t" + textarea.value.substr( selection.start, len );
					textarea.ccSelection.start++;
					textarea.focus();
					return false;
				}
			);

		}
	);

	/**
	 * ajax stuff
	 */
	$( document ).ready(
		function() {
			// append a new codeblock section
			$( document ).on(
				'click',
				'#wp-cc-new-block',
				function() {
					$.post(
						wpCcGlobals.AjaxUrl,
						{
							nonce  : $( '#' + wpCcGlobals.NonceFieldId ).attr( 'value' ),
							action : wpCcGlobals.NewBlockAction
						},
						function( data ) {
							data = $( data );
							data.hide();
							$( '#wp-cc-code-list' ).append( data );
							data.slideDown();
						}
					);
				}
			);

			// update (and delete) a single codeblock
			$( document ).on(
				'click',
				'.wp-cc-single-update',
				function() {
					var ns = $( this ).attr( 'data-ns' );
					var pid = wpCcGlobals.PostID;
					var fields = $( '#' + ns + ' .cc-data' );
					var data = {
						nonce  : $( '#' + wpCcGlobals.NonceFieldId ).attr( 'value' ),
						action : wpCcGlobals.UpdateBlock,
						pid    : pid
					};
					fields.each(
						function( ) {
							var name = $( this ).attr( 'name' ).match( /\[(\w+)\]$/ );
							if ( 'text' == $( this ).attr( 'type' ) || 'TEXTAREA' == this.tagName )
								data[ name[ 1 ] ] = $( this ).attr( 'value' );
							if ( 'checkbox' == $( this ).attr( 'type' ) && 'checked' == $( this ).attr( 'checked' ) )
								data[ name[ 1 ] ] = $( this ).attr( 'value' );
						}
					);
					$.post(
						wpCcGlobals.AjaxUrl,
						data,
						function( data ) {
							if ( data.name ) {
								$( '#name-' + ns )
									.attr( 'value', data.name )
									.attr( 'readonly', 'readonly' );
							}
							if ( data.deleted ) {
								$( '#' + ns ).slideUp(
									'slow',
									function() {
										$( this ).remove();
									}
								);
							}
							else if ( data.updated ) {
								var box = $( '#' + ns + ' .cc-input' );
								box.css( { 'background-color': '#ff4' } );
								box.animate(
									{
										backgroundColor : '#f5f5f5'
									},
									500,
									function() {
										$( this ).css( { 'background-color': 'transparent' } );
									}
								);

							}
						},
						'json'
					);

				}
			);
		}
	);

	/**
	 * the dialog triggered by the TinyMCE Button
	 */
	var ccDialog  = {

		/**
		 * the formular
		 *
		 * @var Object
		 */
		dialog : null,

		/**
		 * start the magic for the dialog box
		 *
		 * @return void
		 */
		init : function() {

			// any tinymce here?
			if ( 'undefined' == typeof( edCanvas ) )
				return; //no!
			//tinyMCEPopup is still undefined at this point

			ccDialog.dialog = $( '#wp-cc-mce-popup' );
			ccDialog.dialog.submit( ccDialog.submit );
			ccDialog.dialog.on(
				'wpdialogbeforeopen',
				function( e ) {
					ccDialog.updateOptions( e );
				}<commit_msg>use .on() to attach event handler<commit_after>/**
 * scripts for the admin-UI
 *
 * @package WordPress
 * @subpackage WP Colored Coding
 * @requires jQuery framework
 */
 // jshint strict: true, undef: true, unused: true
( function($, wpCcGlobals) {
	"use strict";

	$( document ).ready(
		function() {

			/**
			 * buttons for the textarea
			 */
			//remember the selection
			$( document ).on(
				'blur',
				'.wp-cc-codearea',
				function() {
					/**
					 * cross-browser selectrion
					 *
					 * @link http://stackoverflow.com/questions/263743/how-to-get-cursor-position-in-textarea
					 */
					var getInputSelection = function( el ) {
						var start = 0,
							end = 0;
						if ( 'number' == typeof( el.selectionStart )  && 'number' == typeof( el.selectionEnd ) ) {
							start = el.selectionStart;
							end = el.selectionEnd;
						}
						//@todo IE support
						return {
							start: start,
							end: end
						};
					};
					this.ccSelection = getInputSelection( this );
				}
			);

			// set the cursor to the right position
			$( document ).on(
				'focus',
				'.wp-cc-codearea',
				function() {
					if ( 'number' == typeof( this.selectionStart ) && 'undefined' != typeof( this.ccSelection ) )
						this.selectionStart = this.selectionEnd = this.ccSelection.start;

				}
			);

			//insert a tab
			$( document ).on(
				'click',
				'.wp-cc-insert-tab',
				function( e ) {
					e.preventDefault();
					var textarea = document.getElementById( $( this ).attr( 'data-target-id' ) );
					var selection = textarea.ccSelection;
					var len = textarea.value.length;
					textarea.value = textarea.value.substr( 0, selection.start ) + "\t" + textarea.value.substr( selection.start, len );
					textarea.ccSelection.start++;
					textarea.focus();
					return false;
				}
			);

		}
	);

	/**
	 * ajax stuff
	 */
	$( document ).ready(
		function() {
			// append a new codeblock section
			$( document ).on(
				'click',
				'#wp-cc-new-block',
				function() {
					$.post(
						wpCcGlobals.AjaxUrl,
						{
							nonce  : $( '#' + wpCcGlobals.NonceFieldId ).attr( 'value' ),
							action : wpCcGlobals.NewBlockAction
						},
						function( data ) {
							data = $( data );
							data.hide();
							$( '#wp-cc-code-list' ).append( data );
							data.slideDown();
						}
					);
				}
			);

			// update (and delete) a single codeblock
			$( document ).on(
				'click',
				'.wp-cc-single-update',
				function() {
					var ns = $( this ).attr( 'data-ns' );
					var pid = wpCcGlobals.PostID;
					var fields = $( '#' + ns + ' .cc-data' );
					var data = {
						nonce  : $( '#' + wpCcGlobals.NonceFieldId ).attr( 'value' ),
						action : wpCcGlobals.UpdateBlock,
						pid    : pid
					};
					fields.each(
						function( ) {
							var name = $( this ).attr( 'name' ).match( /\[(\w+)\]$/ );
							if ( 'text' == $( this ).attr( 'type' ) || 'TEXTAREA' == this.tagName )
								data[ name[ 1 ] ] = $( this ).attr( 'value' );
							if ( 'checkbox' == $( this ).attr( 'type' ) && 'checked' == $( this ).attr( 'checked' ) )
								data[ name[ 1 ] ] = $( this ).attr( 'value' );
						}
					);
					$.post(
						wpCcGlobals.AjaxUrl,
						data,
						function( data ) {
							if ( data.name ) {
								$( '#name-' + ns )
									.attr( 'value', data.name )
									.attr( 'readonly', 'readonly' );
							}
							if ( data.deleted ) {
								$( '#' + ns ).slideUp(
									'slow',
									function() {
										$( this ).remove();
									}
								);
							}
							else if ( data.updated ) {
								var box = $( '#' + ns + ' .cc-input' );
								box.css( { 'background-color': '#ff4' } );
								box.animate(
									{
										backgroundColor : '#f5f5f5'
									},
									500,
									function() {
										$( this ).css( { 'background-color': 'transparent' } );
									}
								);

							}
						},
						'json'
					);

				}
			);
		}
	);

	/**
	 * the dialog triggered by the TinyMCE Button
	 */
	var ccDialog  = {

		/**
		 * the formular
		 *
		 * @var Object
		 */
		dialog : null,

		/**
		 * start the magic for the dialog box
		 *
		 * @return void
		 */
		init : function() {

			// any tinymce here?
			if ( 'undefined' == typeof( edCanvas ) )
				return; //no!
			//tinyMCEPopup is still undefined at this point

			ccDialog.dialog = $( '#wp-cc-mce-popup' );
			ccDialog.dialog.on(
				'submit',
				function( e ) {
					ccDialog.submit( e );
				}
			);
			ccDialog.dialog.on(
				'wpdialogbeforeopen',
				function( e ) {
					ccDialog.updateOptions( e );
				}
{'fraction_non_alphanumeric': 0.17189918195887685, 'fraction_numerical': 0.003979659518019014, 'mean_word_length': 1.794871794871795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '45185', 'n_tokens_mistral': 4385, 'n_tokens_neox': 2953, 'n_words': 665}