<commit_before>/**
 * @package assets
 */

(function($) {

	/**
	 * This plugin makes items orderable.
	 *
	 * @param {Object} custom_settings
	 *  An object specifying the item to be ordered, their handles and 
	 *  a initialization delay
	 */
	$.fn.symphonyOrderable = function(custom_settings) {
		var objects = this,
			settings = {
				items:				'li',
				handles:			'*',
				delay_initialize:	false
			};

		$.extend(settings, custom_settings);

	/*-----------------------------------------------------------------------*/

		objects = objects.map(function() {
			var object = this,
				state = null;

			var start = function(item) {		
				state = {
					item:		item,
					min:		null,
					max:		null,
					delta:		0
				};

				$(document).bind('mousemove.orderable', change);
				$(document).bind('mouseup.orderable', stop);

				$(document).mousemove();
			};

			var change = function(event) {
				var item = state.item,
					target, next, top = event.pageY,
					a = item.height(),
					b = item.offset().top,
					prev = item.prev();

				state.min = Math.min(b, a + (prev.size() > 0 ? prev.offset().top : -Infinity));
				state.max = Math.max(a + b, b + (item.next().height() ||  Infinity));

				if(!object.is('.ordering')) {
					object.addClass('ordering');
					item.addClass('ordering');
					object.trigger('orderstart', [state.item]);
				}

				if(top < state.min) {
					target = item.prev(settings.items);

					while (true) {
						state.delta--;
						next = target.prev(settings.items);

						if(next.length === 0 || top >= (state.min -= next.height())) {
							item.insertBefore(target); break;
						}

						target = next;
					}
				}

				else if(top > state.max) {
					target = item.next(settings.items);

					while (true) {
						state.delta++;
						next = target.next(settings.items);

						if(next.length === 0 || top <= (state.max += next.height())) {
							item.insertAfter(target); 
							break;
						}

						target = next;
					}
				}

				object.trigger('orderchange', [state.item]);

				return false;
			};

			var stop = function() {
				$(document).unbind('.orderable');

				if(state != null) {
					object.removeClass('ordering');
					state.item.removeClass('ordering');
					object.trigger('orderstop', [state.item]);
					state = null;
				}

				return false;
			};<commit_msg>Fix for #645, correct triggering of orderchange event.<commit_after>/**
 * @package assets
 */

(function($) {

	/**
	 * This plugin makes items orderable.
	 *
	 * @param {Object} custom_settings
	 *  An object specifying the item to be ordered, their handles and 
	 *  a initialization delay
	 */
	$.fn.symphonyOrderable = function(custom_settings) {
		var objects = this,
			settings = {
				items:				'li',
				handles:			'*',
				delay_initialize:	false
			};

		$.extend(settings, custom_settings);

	/*-----------------------------------------------------------------------*/

		objects = objects.map(function() {
			var object = this,
				state = null;

			var start = function(item) {		
				state = {
					item:		item,
					min:		null,
					max:		null,
					delta:		0
				};

				$(document).bind('mousemove.orderable', change);
				$(document).bind('mouseup.orderable', stop);

				$(document).mousemove();
			};

			var change = function(event) {
				var item = state.item,
					target, next, top = event.pageY,
					a = item.height(),
					b = item.offset().top,
					prev = item.prev();

				state.min = Math.min(b, a + (prev.size() > 0 ? prev.offset().top : -Infinity));
				state.max = Math.max(a + b, b + (item.next().height() ||  Infinity));

				if(!object.is('.ordering')) {
					object.addClass('ordering');
					item.addClass('ordering');
					object.trigger('orderstart', [state.item]);
				}

				if(top < state.min) {
					target = item.prev(settings.items);

					while (true) {
						state.delta--;
						next = target.prev(settings.items);

						if(next.length === 0 || top >= (state.min -= next.height())) {
							item.insertBefore(target);
							object.trigger('orderchange', [state.item]);
							break;
						}

						target = next;
					}
				}

				else if(top > state.max) {
					target = item.next(settings.items);

					while (true) {
						state.delta++;
						next = target.next(settings.items);

						if(next.length === 0 || top <= (state.max += next.height())) {
							item.insertAfter(target); 
							object.trigger('orderchange', [state.item]);
							break;
						}

						target = next;
					}
				}

				return false;
			};

			var stop = function() {
				$(document).unbind('.orderable');

				if(state != null) {
					object.removeClass('ordering');
					state.item.removeClass('ordering');
					object.trigger('orderstop', [state.item]);
					state = null;
				}

				return false;
			};
{'fraction_non_alphanumeric': 0.19443281707827542, 'fraction_numerical': 0.0023022185014650483, 'mean_word_length': 2.1420118343195265, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '5815685', 'n_tokens_mistral': 2052, 'n_tokens_neox': 1472, 'n_words': 313}