wp/wp-admin/js/widgets.js
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/*global ajaxurl, isRtl */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
var wpWidgets;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
(function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
wpWidgets = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
	init : function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
		var rem, the_id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
			self = this,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
			chooser = $('.widgets-chooser'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
			selectSidebar = chooser.find('.widgets-chooser-sidebars'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
			sidebars = $('div.widgets-sortables'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
			isRTL = !! ( 'undefined' !== typeof isRtl && isRtl );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
		$('#widgets-right .sidebar-name').click( function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
			var $this = $(this),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
				$wrap = $this.closest('.widgets-holder-wrap');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
			if ( $wrap.hasClass('closed') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
				$wrap.removeClass('closed');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
				$this.parent().sortable('refresh');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
			} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
				$wrap.addClass('closed');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
		$('#widgets-left .sidebar-name').click( function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
			$(this).closest('.widgets-holder-wrap').toggleClass('closed');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
		$(document.body).bind('click.widgets-toggle', function(e) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
			var target = $(e.target),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
				css = { 'z-index': 100 },
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
				widget, inside, targetWidth, widgetWidth, margin;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
			if ( target.parents('.widget-top').length && ! target.parents('#available-widgets').length ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
				widget = target.closest('div.widget');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
				inside = widget.children('.widget-inside');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
				targetWidth = parseInt( widget.find('input.widget-width').val(), 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
				widgetWidth = widget.parent().width();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
				if ( inside.is(':hidden') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
					if ( targetWidth > 250 && ( targetWidth + 30 > widgetWidth ) && widget.closest('div.widgets-sortables').length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
						if ( widget.closest('div.widget-liquid-right').length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
							margin = isRTL ? 'margin-right' : 'margin-left';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
						} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
							margin = isRTL ? 'margin-left' : 'margin-right';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
						}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
						css[ margin ] = widgetWidth - ( targetWidth + 30 ) + 'px';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
						widget.css( css );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
					widget.addClass( 'open' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
					inside.slideDown('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
					inside.slideUp('fast', function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
						widget.attr( 'style', '' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
						widget.removeClass( 'open' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			} else if ( target.hasClass('widget-control-save') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
				wpWidgets.save( target.closest('div.widget'), 0, 1, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			} else if ( target.hasClass('widget-control-remove') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
				wpWidgets.save( target.closest('div.widget'), 1, 1, 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
			} else if ( target.hasClass('widget-control-close') ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
				widget = target.closest('div.widget');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
				widget.removeClass( 'open' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
				wpWidgets.close( widget );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
		sidebars.children('.widget').each( function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
			var $this = $(this);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
			wpWidgets.appendTitle( this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
			if ( $this.find( 'p.widget-error' ).length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
				$this.find( 'a.widget-action' ).trigger('click');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
		$('#widget-list').children('.widget').draggable({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
			connectToSortable: 'div.widgets-sortables',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
			handle: '> .widget-top > .widget-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
			distance: 2,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
			helper: 'clone',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			zIndex: 100,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
			containment: 'document',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
			start: function( event, ui ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
				var chooser = $(this).find('.widgets-chooser');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
				ui.helper.find('div.widget-description').hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
				the_id = this.id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
				if ( chooser.length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
					// Hide the chooser and move it out of the widget
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
					$( '#wpbody-content' ).append( chooser.hide() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
					// Delete the cloned chooser from the drag helper
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
					ui.helper.find('.widgets-chooser').remove();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
					self.clearWidgetSelection();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
			},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
			stop: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
				if ( rem ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
					$(rem).hide();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
				rem = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		sidebars.sortable({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
			placeholder: 'widget-placeholder',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
			items: '> .widget',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			handle: '> .widget-top > .widget-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			cursor: 'move',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			distance: 2,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
			containment: 'document',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			start: function( event, ui ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
				var height, $this = $(this),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
					$wrap = $this.parent(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
					inside = ui.item.children('.widget-inside');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
				if ( inside.css('display') === 'block' ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
					inside.hide();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
					$(this).sortable('refreshPositions');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
				if ( ! $wrap.hasClass('closed') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
					// Lock all open sidebars min-height when starting to drag.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
					// Prevents jumping when dragging a widget from an open sidebar to a closed sidebar below.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
					height = ui.item.hasClass('ui-draggable') ? $this.height() : 1 + $this.height();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
					$this.css( 'min-height', height + 'px' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
			stop: function( event, ui ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
				var addNew, widgetNumber, $sidebar, $children, child, item,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
					$widget = ui.item,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
					id = the_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
				if ( $widget.hasClass('deleting') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
					wpWidgets.save( $widget, 1, 0, 1 ); // delete widget
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
					$widget.remove();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
				addNew = $widget.find('input.add_new').val();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
				widgetNumber = $widget.find('input.multi_number').val();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
				$widget.attr( 'style', '' ).removeClass('ui-draggable');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
				the_id = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
				if ( addNew ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
					if ( 'multi' === addNew ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
						$widget.html(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
							$widget.html().replace( /<[^<>]+>/g, function( tag ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
								return tag.replace( /__i__|%i%/g, widgetNumber );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
							})
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
						);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
						$widget.attr( 'id', id.replace( '__i__', widgetNumber ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
						widgetNumber++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
						$( 'div#' + id ).find( 'input.multi_number' ).val( widgetNumber );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
					} else if ( 'single' === addNew ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
						$widget.attr( 'id', 'new-' + id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
						rem = 'div#' + id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
					wpWidgets.save( $widget, 0, 0, 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
					$widget.find('input.add_new').val('');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
					$( document ).trigger( 'widget-added', [ $widget ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
				$sidebar = $widget.parent();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
				if ( $sidebar.parent().hasClass('closed') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
					$sidebar.parent().removeClass('closed');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
					$children = $sidebar.children('.widget');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
					// Make sure the dropped widget is at the top
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
					if ( $children.length > 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
						child = $children.get(0);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
						item = $widget.get(0);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
						if ( child.id && item.id && child.id !== item.id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
							$( child ).before( $widget );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
						}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
					}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
				if ( addNew ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
					$widget.find( 'a.widget-action' ).trigger('click');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
					wpWidgets.saveOrder( $sidebar.attr('id') );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
			activate: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
				$(this).parent().addClass( 'widget-hover' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
			deactivate: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
				// Remove all min-height added on "start"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
				$(this).css( 'min-height', '' ).parent().removeClass( 'widget-hover' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
			},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
			receive: function( event, ui ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
				var $sender = $( ui.sender );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
				// Don't add more widgets to orphaned sidebars
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
				if ( this.id.indexOf('orphaned_widgets') > -1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
					$sender.sortable('cancel');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
				// If the last widget was moved out of an orphaned sidebar, close and remove it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
				if ( $sender.attr('id').indexOf('orphaned_widgets') > -1 && ! $sender.children('.widget').length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
					$sender.parents('.orphan-sidebar').slideUp( 400, function(){ $(this).remove(); } );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
		}).sortable( 'option', 'connectWith', 'div.widgets-sortables' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
		$('#available-widgets').droppable({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			tolerance: 'pointer',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			accept: function(o){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
				return $(o).parent().attr('id') !== 'widget-list';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
			drop: function(e,ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
				ui.draggable.addClass('deleting');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
				$('#removing-widget').hide().children('span').empty();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
			over: function(e,ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
				ui.draggable.addClass('deleting');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
				$('div.widget-placeholder').hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
				if ( ui.draggable.hasClass('ui-sortable-helper') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
					$('#removing-widget').show().children('span')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
					.html( ui.draggable.find('div.widget-title').children('h4').html() );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			out: function(e,ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
				ui.draggable.removeClass('deleting');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
				$('div.widget-placeholder').show();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
				$('#removing-widget').hide().children('span').empty();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
		// Area Chooser
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
		$( '#widgets-right .widgets-holder-wrap' ).each( function( index, element ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
			var $element = $( element ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
				name = $element.find( '.sidebar-name h3' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
				id = $element.find( '.widgets-sortables' ).attr( 'id' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
				li = $('<li tabindex="0">').text( $.trim( name ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
			if ( index === 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
				li.addClass( 'widgets-chooser-selected' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
			selectSidebar.append( li );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
			li.data( 'sidebarId', id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
		$( '#available-widgets .widget .widget-title' ).on( 'click.widgets-chooser', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
			var $widget = $(this).closest( '.widget' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
			if ( $widget.hasClass( 'widget-in-question' ) || $( '#widgets-left' ).hasClass( 'chooser' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
				self.closeChooser();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
				// Open the chooser
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
				self.clearWidgetSelection();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
				$( '#widgets-left' ).addClass( 'chooser' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
				$widget.addClass( 'widget-in-question' ).children( '.widget-description' ).after( chooser );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
				chooser.slideDown( 300, function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
					selectSidebar.find('.widgets-chooser-selected').focus();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
				});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
				selectSidebar.find( 'li' ).on( 'focusin.widgets-chooser', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
					selectSidebar.find('.widgets-chooser-selected').removeClass( 'widgets-chooser-selected' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
					$(this).addClass( 'widgets-chooser-selected' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
				} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
		});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
		// Add event handlers
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
		chooser.on( 'click.widgets-chooser', function( event ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
			var $target = $( event.target );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
			if ( $target.hasClass('button-primary') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
				self.addWidget( chooser );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
				self.closeChooser();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
			} else if ( $target.hasClass('button-secondary') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
				self.closeChooser();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
		}).on( 'keyup.widgets-chooser', function( event ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
			if ( event.which === $.ui.keyCode.ENTER ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
				if ( $( event.target ).hasClass('button-secondary') ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
					// Close instead of adding when pressing Enter on the Cancel button
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
					self.closeChooser();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
				} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
					self.addWidget( chooser );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
					self.closeChooser();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
			} else if ( event.which === $.ui.keyCode.ESCAPE ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
				self.closeChooser();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
	saveOrder : function( sidebarId ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
		var data = {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			action: 'widgets-order',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			savewidgets: $('#_wpnonce_widgets').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			sidebars: []
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		if ( sidebarId ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
			$( '#' + sidebarId ).find( '.spinner:first' ).addClass( 'is-active' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		$('div.widgets-sortables').each( function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
			if ( $(this).sortable ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
				data['sidebars[' + $(this).attr('id') + ']'] = $(this).sortable('toArray').join(',');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
		$.post( ajaxurl, data, function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
			$( '.spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
	save : function( widget, del, animate, order ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
		var sidebarId = widget.closest('div.widgets-sortables').attr('id'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
			data = widget.find('form').serialize(), a;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		widget = $(widget);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
		$( '.spinner', widget ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
		a = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			action: 'save-widget',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			savewidgets: $('#_wpnonce_widgets').val(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
			sidebar: sidebarId
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
		if ( del ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
			a.delete_widget = 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   353
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		data += '&' + $.param(a);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
		$.post( ajaxurl, data, function(r) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
			var id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
			if ( del ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
				if ( ! $('input.widget_number', widget).val() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
					id = $('input.widget-id', widget).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
					$('#available-widgets').find('input.widget-id').each(function(){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
						if ( $(this).val() === id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
							$(this).closest('div.widget').show();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
				if ( animate ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
					order = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
					widget.slideUp('fast', function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
						$(this).remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
						wpWidgets.saveOrder();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
					widget.remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
			} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
				$( '.spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
				if ( r && r.length > 2 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
					$( 'div.widget-content', widget ).html( r );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
					wpWidgets.appendTitle( widget );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
					$( document ).trigger( 'widget-updated', [ widget ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
			if ( order ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
				wpWidgets.saveOrder();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	appendTitle : function(widget) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
		var title = $('input[id*="-title"]', widget).val() || '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
		if ( title ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
			title = ': ' + title.replace(/<[^<>]+>/g, '').replace(/</g, '&lt;').replace(/>/g, '&gt;');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
		$(widget).children('.widget-top').children('.widget-title').children()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
				.children('.in-widget-title').html(title);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
	close : function(widget) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
		widget.children('.widget-inside').slideUp('fast', function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
			widget.attr( 'style', '' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
	addWidget: function( chooser ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
		var widget, widgetId, add, n, viewportTop, viewportBottom, sidebarBounds,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
			sidebarId = chooser.find( '.widgets-chooser-selected' ).data('sidebarId'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
			sidebar = $( '#' + sidebarId );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
		widget = $('#available-widgets').find('.widget-in-question').clone();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
		widgetId = widget.attr('id');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
		add = widget.find( 'input.add_new' ).val();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
		n = widget.find( 'input.multi_number' ).val();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
		// Remove the cloned chooser from the widget
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
		widget.find('.widgets-chooser').remove();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
		if ( 'multi' === add ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
			widget.html(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
				widget.html().replace( /<[^<>]+>/g, function(m) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
					return m.replace( /__i__|%i%/g, n );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
				})
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
			);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
			widget.attr( 'id', widgetId.replace( '__i__', n ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
			n++;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
			$( '#' + widgetId ).find('input.multi_number').val(n);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
		} else if ( 'single' === add ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
			widget.attr( 'id', 'new-' + widgetId );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
			$( '#' + widgetId ).hide();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
		// Open the widgets container
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
		sidebar.closest( '.widgets-holder-wrap' ).removeClass('closed');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
		sidebar.append( widget );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
		sidebar.sortable('refresh');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
		wpWidgets.save( widget, 0, 0, 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
		// No longer "new" widget
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
		widget.find( 'input.add_new' ).val('');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
		$( document ).trigger( 'widget-added', [ widget ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
		/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
		 * Check if any part of the sidebar is visible in the viewport. If it is, don't scroll.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
		 * Otherwise, scroll up to so the sidebar is in view.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
		 * We do this by comparing the top and bottom, of the sidebar so see if they are within
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
		 * the bounds of the viewport.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
		viewportTop = $(window).scrollTop();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
		viewportBottom = viewportTop + $(window).height();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
		sidebarBounds = sidebar.offset();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
		sidebarBounds.bottom = sidebarBounds.top + sidebar.outerHeight();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
		if ( viewportTop > sidebarBounds.bottom || viewportBottom < sidebarBounds.top ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
			$( 'html, body' ).animate({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
				scrollTop: sidebarBounds.top - 130
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			}, 200 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
		window.setTimeout( function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			// Cannot use a callback in the animation above as it fires twice,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
			// have to queue this "by hand".
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			widget.find( '.widget-title' ).trigger('click');
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
		}, 250 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
	},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
	closeChooser: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
		var self = this;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
		$( '.widgets-chooser' ).slideUp( 200, function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			$( '#wpbody-content' ).append( this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
			self.clearWidgetSelection();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
	clearWidgetSelection: function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
		$( '#widgets-left' ).removeClass( 'chooser' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
		$( '.widget-in-question' ).removeClass( 'widget-in-question' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
$(document).ready( function(){ wpWidgets.init(); } );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
})(jQuery);