| 1 |
/*global redux_change, wp, redux*/ |
| 2 |
|
| 3 |
(function( $ ) { |
| 4 |
"use strict"; |
| 5 |
|
| 6 |
redux.field_objects = redux.field_objects || {}; |
| 7 |
redux.field_objects.slides = redux.field_objects.slides || {}; |
| 8 |
|
| 9 |
$( document ).ready( |
| 10 |
function() { |
| 11 |
//redux.field_objects.slides.init(); |
| 12 |
} |
| 13 |
); |
| 14 |
|
| 15 |
redux.field_objects.slides.init = function( selector ) { |
| 16 |
|
| 17 |
if ( !selector ) { |
| 18 |
selector = $( document ).find( ".redux-group-tab:visible" ).find( '.redux-container-slides:visible' ); |
| 19 |
} |
| 20 |
|
| 21 |
$( selector ).each( |
| 22 |
function() { |
| 23 |
var el = $( this ); |
| 24 |
|
| 25 |
redux.field_objects.media.init(el); |
| 26 |
|
| 27 |
var parent = el; |
| 28 |
if ( !el.hasClass( 'redux-field-container' ) ) { |
| 29 |
parent = el.parents( '.redux-field-container:first' ); |
| 30 |
} |
| 31 |
if ( parent.is( ":hidden" ) ) { // Skip hidden fields |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
if ( parent.hasClass( 'redux-container-slides' ) ) { |
| 36 |
parent.addClass( 'redux-field-init' ); |
| 37 |
} |
| 38 |
|
| 39 |
if ( parent.hasClass( 'redux-field-init' ) ) { |
| 40 |
parent.removeClass( 'redux-field-init' ); |
| 41 |
} else { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
el.find( '.redux-slides-remove' ).live( |
| 46 |
'click', function() { |
| 47 |
redux_change( $( this ) ); |
| 48 |
|
| 49 |
$( this ).parent().siblings().find( 'input[type="text"]' ).val( '' ); |
| 50 |
$( this ).parent().siblings().find( 'textarea' ).val( '' ); |
| 51 |
$( this ).parent().siblings().find( 'input[type="hidden"]' ).val( '' ); |
| 52 |
|
| 53 |
var slideCount = $( this ).parents( '.redux-container-slides:first' ).find( '.redux-slides-accordion-group' ).length; |
| 54 |
|
| 55 |
if ( slideCount > 1 ) { |
| 56 |
$( this ).parents( '.redux-slides-accordion-group:first' ).slideUp( |
| 57 |
'medium', function() { |
| 58 |
$( this ).remove(); |
| 59 |
} |
| 60 |
); |
| 61 |
} else { |
| 62 |
var content_new_title = $( this ).parent( '.redux-slides-accordion' ).data( 'new-content-title' ); |
| 63 |
|
| 64 |
$( this ).parents( '.redux-slides-accordion-group:first' ).find( '.remove-image' ).click(); |
| 65 |
$( this ).parents( '.redux-container-slides:first' ).find( '.redux-slides-accordion-group:last' ).find( '.redux-slides-header' ).text( content_new_title ); |
| 66 |
} |
| 67 |
} |
| 68 |
); |
| 69 |
|
| 70 |
//el.find( '.redux-slides-add' ).click( |
| 71 |
el.find( '.redux-slides-add' ).off('click').click( |
| 72 |
function() { |
| 73 |
var newSlide = $( this ).prev().find( '.redux-slides-accordion-group:last' ).clone( true ); |
| 74 |
|
| 75 |
var slideCount = $( newSlide ).find( '.slide-title' ).attr( "name" ).match( /[0-9]+(?!.*[0-9])/ ); |
| 76 |
var slideCount1 = slideCount * 1 + 1; |
| 77 |
|
| 78 |
$( newSlide ).find( 'input[type="text"], input[type="hidden"], textarea' ).each( |
| 79 |
function() { |
| 80 |
|
| 81 |
$( this ).attr( |
| 82 |
"name", jQuery( this ).attr( "name" ).replace( /[0-9]+(?!.*[0-9])/, slideCount1 ) |
| 83 |
).attr( "id", $( this ).attr( "id" ).replace( /[0-9]+(?!.*[0-9])/, slideCount1 ) ); |
| 84 |
$( this ).val( '' ); |
| 85 |
if ( $( this ).hasClass( 'slide-sort' ) ) { |
| 86 |
$( this ).val( slideCount1 ); |
| 87 |
} |
| 88 |
} |
| 89 |
); |
| 90 |
|
| 91 |
var content_new_title = $( this ).prev().data( 'new-content-title' ); |
| 92 |
|
| 93 |
$( newSlide ).find( '.screenshot' ).removeAttr( 'style' ); |
| 94 |
$( newSlide ).find( '.screenshot' ).addClass( 'hide' ); |
| 95 |
$( newSlide ).find( '.screenshot a' ).attr( 'href', '' ); |
| 96 |
$( newSlide ).find( '.remove-image' ).addClass( 'hide' ); |
| 97 |
$( newSlide ).find( '.redux-slides-image' ).attr( 'src', '' ).removeAttr( 'id' ); |
| 98 |
$( newSlide ).find( 'h3' ).text( '' ).append( '<span class="redux-slides-header">' + content_new_title + '</span><span class="ui-accordion-header-icon ui-icon ui-icon-plus"></span>' ); |
| 99 |
$( this ).prev().append( newSlide ); |
| 100 |
} |
| 101 |
); |
| 102 |
|
| 103 |
el.find( '.slide-title' ).keyup( |
| 104 |
function( event ) { |
| 105 |
var newTitle = event.target.value; |
| 106 |
$( this ).parents().eq( 3 ).find( '.redux-slides-header' ).text( newTitle ); |
| 107 |
} |
| 108 |
); |
| 109 |
|
| 110 |
|
| 111 |
el.find( ".redux-slides-accordion" ) |
| 112 |
.accordion( |
| 113 |
{ |
| 114 |
header: "> div > fieldset > h3", |
| 115 |
collapsible: true, |
| 116 |
active: false, |
| 117 |
heightStyle: "content", |
| 118 |
icons: { |
| 119 |
"header": "ui-icon-plus", |
| 120 |
"activeHeader": "ui-icon-minus" |
| 121 |
} |
| 122 |
} |
| 123 |
) |
| 124 |
.sortable( |
| 125 |
{ |
| 126 |
axis: "y", |
| 127 |
handle: "h3", |
| 128 |
connectWith: ".redux-slides-accordion", |
| 129 |
start: function( e, ui ) { |
| 130 |
ui.placeholder.height( ui.item.height() ); |
| 131 |
ui.placeholder.width( ui.item.width() ); |
| 132 |
}, |
| 133 |
placeholder: "ui-state-highlight", |
| 134 |
stop: function( event, ui ) { |
| 135 |
// IE doesn't register the blur when sorting |
| 136 |
// so trigger focusout handlers to remove .ui-state-focus |
| 137 |
ui.item.children( "h3" ).triggerHandler( "focusout" ); |
| 138 |
var inputs = $( 'input.slide-sort' ); |
| 139 |
inputs.each( |
| 140 |
function( idx ) { |
| 141 |
$( this ).val( idx ); |
| 142 |
} |
| 143 |
); |
| 144 |
} |
| 145 |
} |
| 146 |
); |
| 147 |
} |
| 148 |
); |
| 149 |
}; |
| 150 |
})( jQuery ); |