Ero sivun ”Widget:Form enabler” versioiden välillä
Järvi-meriwikistä
Rivi 1: | Rivi 1: | ||
<includeonly><script type="text/javascript"> | <includeonly><script type="text/javascript"> | ||
− | + | ||
function <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() { | function <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() { | ||
if ( typeof window.jQuery == 'undefined' ) { | if ( typeof window.jQuery == 'undefined' ) { | ||
setTimeout( function(){ <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() }, 300); | setTimeout( function(){ <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() }, 300); | ||
} else { | } else { | ||
− | + | <!--{$id|default:FormEnabler|escape:'html'}-->_funcX(); | |
− | + | } | |
− | |||
− | |||
− | |||
} | } | ||
+ | |||
setTimeout( function(){ <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() }, 300); | setTimeout( function(){ <!--{$id|default:FormEnabler|escape:'html'}-->_jQueryTest() }, 300); | ||
− | + | function <!--{$id|default:FormEnabler|escape:'html'}-->_funcX() { | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | jQuery('fieldset:visible .JwLocCheckboxes').each(function() { | ||
+ | |||
var input = jQuery( this ).children('input').first(); | var input = jQuery( this ).children('input').first(); | ||
Rivi 38: | Rivi 28: | ||
newLabel = old.substr(0, old.lastIndexOf(";")) + strArr[2].split('_').join(' '); | newLabel = old.substr(0, old.lastIndexOf(";")) + strArr[2].split('_').join(' '); | ||
jQuery( this ).html(newLabel); | jQuery( this ).html(newLabel); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | }); | ||
+ | |||
+ | jQuery('fieldset:visible .JwLocDropdowns > option').each(function() { | ||
+ | |||
+ | var classes = jQuery( this ).parent().attr('class').split(' '); | ||
+ | var val = jQuery( this ).val(); | ||
+ | |||
+ | for (var i in classes) { | ||
+ | |||
+ | strArr = classes[i].split('-'); | ||
+ | |||
+ | if (strArr[1] == val) { | ||
+ | str = strArr[2].split('_').join(' ').split('~').join('-'); | ||
+ | jQuery( this ).html(str); | ||
break; | break; | ||
} | } | ||
Rivi 43: | Rivi 51: | ||
}); | }); | ||
+ | } | ||
+ | function <!--{$id|default:FormEnabler|escape:'html'}-->_func() { | ||
+ | |||
+ | var lang = '<!--{$lang|default:fi|escape:'urlpathinfo'}-->'; | ||
+ | |||
+ | jQuery('.JwDisabled').each(function() { | ||
+ | jQuery( this ).attr('disabled', true); | ||
+ | jQuery( this ).attr('disabled', true); | ||
+ | jQuery( this ).attr('disabled', true); | ||
+ | }); | ||
+ | |||
jQuery( 'body' ).on( "mouseenter", ".JwMultipleTemplateInfo", null, function( event ) { | jQuery( 'body' ).on( "mouseenter", ".JwMultipleTemplateInfo", null, function( event ) { | ||
− | + | ||
var target = jQuery( this ); | var target = jQuery( this ); | ||
− | + | ||
target.removeClass('JwMultipleTemplateInfo'); | target.removeClass('JwMultipleTemplateInfo'); | ||
target.qtip({ | target.qtip({ | ||
− | + | content: { | |
− | + | title: { | |
− | + | text: target.find( '.smwtttitle' ), | |
− | + | button: FormEnablerLabels(0, lang) | |
− | + | }, | |
− | + | text: target.find( '.smwttcontent' ), //target.attr('data-content'), | |
− | + | button: 'X' | |
− | + | }, | |
− | + | position: { | |
− | + | my: 'left center', | |
− | + | at: 'center', | |
− | + | target: target, | |
− | + | adjust: { x: 5, y: -2 } | |
− | + | }, | |
− | + | show: { | |
− | + | solo: true | |
− | + | }, | |
− | + | hide: { | |
− | + | event: false | |
− | + | }, | |
− | + | style: { | |
classes: "jwqtip qtip qtip-default qtip-shadow qtip-bootstrap qtip-pos-bc qtip-focus" | classes: "jwqtip qtip qtip-default qtip-shadow qtip-bootstrap qtip-pos-bc qtip-focus" | ||
− | + | } | |
− | + | }); | |
+ | |||
+ | target.mouseenter(); | ||
+ | }); | ||
+ | |||
+ | |||
+ | jQuery('fieldset:visible .JwLocCheckboxes').each(function() { | ||
+ | |||
+ | var input = jQuery( this ).children('input').first(); | ||
+ | |||
+ | var classes = jQuery( this ).attr('class').split(' '); | ||
+ | var val = input.val(); | ||
+ | |||
+ | for (var i in classes) { | ||
− | + | strArr = classes[i].split('-'); | |
− | |||
− | jQuery('. | + | if (strArr[1] == val) { |
+ | old = input.parent().html(); | ||
+ | newLabel = old.substr(0, old.lastIndexOf(";")) + strArr[2].split('_').join(' '); | ||
+ | jQuery( this ).html(newLabel); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | }); | ||
+ | |||
+ | jQuery('fieldset:visible .multipleTemplateInstance').each(function() { | ||
var id = 'JwRandom_' + Math.random().toString().replace(".", "") + 'Id'; | var id = 'JwRandom_' + Math.random().toString().replace(".", "") + 'Id'; | ||
jQuery( this ).addClass(id); | jQuery( this ).addClass(id); | ||
Rivi 85: | Rivi 126: | ||
jQuery( this ).find('tr').first().prepend('<td><a href="javascript: Jw_MultipleForm_Toggler(\'' + id + '\');"><div id="' + id + '_button" class="JW_formlock_button locked"></div></a></td>'); | jQuery( this ).find('tr').first().prepend('<td><a href="javascript: Jw_MultipleForm_Toggler(\'' + id + '\');"><div id="' + id + '_button" class="JW_formlock_button locked"></div></a></td>'); | ||
Jw_MultipleForm_Toggler(id); | Jw_MultipleForm_Toggler(id); | ||
+ | /* | ||
var curdate = jQuery( this ).find('input.JwDateField').val(); | var curdate = jQuery( this ).find('input.JwDateField').val(); | ||
if (curdate == undefined) { curdate = ''; } | if (curdate == undefined) { curdate = ''; } | ||
Rivi 90: | Rivi 132: | ||
if (curfile == undefined) { curfile = ''; } | if (curfile == undefined) { curfile = ''; } | ||
var newhref = jQuery( this ).find('a.sfImagePreview').attr('href'); | var newhref = jQuery( this ).find('a.sfImagePreview').attr('href'); | ||
− | if (curfile | + | if (!!curfile) { |
newhref = newhref.substring(0, newhref.indexOf('&wpDestFile=')); | newhref = newhref.substring(0, newhref.indexOf('&wpDestFile=')); | ||
newhref += '&wpDestFile=' + curfile; | newhref += '&wpDestFile=' + curfile; | ||
jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | ||
} else { | } else { | ||
− | newhref = newhref + curdate.split('/').join('-'); | + | newhref = newhref.substring(0, newhref.lastIndexOf('.')) + curdate.split('/').join('-') + newhref.substring(newhref.lastIndexOf('.')); |
jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | ||
} | } | ||
+ | */ | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | + | jQuery('fieldset:visible .multipleTemplateStarter').each(function() { | |
− | |||
− | + | jQuery( this ).find('tr').first().prepend('<td><div class="JW_formlock_button open"></div></td>'); | |
− | + | /* | |
− | + | var curdate = jQuery( this ).find('input.JwDateField').val(); | |
− | + | if (curdate == undefined) { curdate = ''; } | |
− | + | var curfile = jQuery( this ).find('input.jwFileNameHide').val(); | |
− | + | if (curfile == undefined) { curfile = ''; } | |
− | + | var newhref = jQuery( this ).find('a.sfImagePreview').attr('href'); | |
− | + | if (curfile != "") { | |
− | + | newhref = newhref.substring(0, newhref.indexOf('&wpDestFile=')); | |
+ | newhref += '&wpDestFile=' + curfile; | ||
+ | jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | ||
+ | } else { | ||
+ | newhref = newhref.substring(0, newhref.lastIndexOf('.')) + curdate.split('/').join('-') + newhref.substring(newhref.lastIndexOf('.')); | ||
+ | jQuery( this ).find('a.sfImagePreview').attr('href', newhref); | ||
} | } | ||
− | + | */ | |
}); | }); | ||
− | + | ||
− | jQuery('.JwLocDropdowns | + | jQuery('fieldset:visible .JwLocDropdowns > option').each(function() { |
var classes = jQuery( this ).parent().attr('class').split(' '); | var classes = jQuery( this ).parent().attr('class').split(' '); | ||
Rivi 130: | Rivi 174: | ||
if (strArr[1] == val) { | if (strArr[1] == val) { | ||
str = strArr[2].split('_').join(' '); | str = strArr[2].split('_').join(' '); | ||
+ | str = strArr[2].split('~').join('-'); | ||
jQuery( this ).html(str); | jQuery( this ).html(str); | ||
break; | break; | ||
Rivi 137: | Rivi 182: | ||
}); | }); | ||
− | jQuery(window).resize(function() { setTimeout(function() { Jw_FormFieldResizer(); }, 500); }); | + | jQuery('fieldset:visible input.jwFileNameHide').each(function() { |
+ | if (!!jQuery( this ).val()) { | ||
+ | jQuery( this ).parent().append('<span class="jwRemovePic" style="display: inline;">| <a class="jwRemovePic" href="#">Poista kuva</a></span>'); | ||
+ | } else { | ||
+ | jQuery( this ).parent().append('<span class="jwRemovePic" style="display: none;">| <a class="jwRemovePic" href="#">Poista kuva</a></span>'); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | jQuery(window).resize(function() { | ||
+ | setTimeout(function() { Jw_FormFieldResizer(); }, 500); | ||
+ | }); | ||
setTimeout('Jw_FormFieldResizer()', 1000); | setTimeout('Jw_FormFieldResizer()', 1000); | ||
+ | |||
+ | jQuery( 'body' ).on('change.jw', 'input.jwFileNameHide', updatePic ); | ||
+ | jQuery( 'body' ).on('click.jw', 'a.jwRemovePic', deletePic ); | ||
+ | |||
+ | setInterval(function() { | ||
+ | Jw_FormFieldResizer(); | ||
+ | }, 3000); | ||
− | + | /* | |
− | + | jQuery('#sfForm').submit(function() { | |
− | + | console.log('submit'); | |
− | + | jQuery('fieldset:visible input').attr('disabled', false); | |
− | + | jQuery('fieldset:visible select').attr('disabled', false); | |
− | + | jQuery('fieldset:visible button').attr('disabled', false); | |
− | } | + | }); |
− | + | */ | |
+ | checkAgain(); | ||
+ | |||
+ | } | ||
+ | |||
function Jw_MultipleForm_Toggler(id) { | function Jw_MultipleForm_Toggler(id) { | ||
Rivi 154: | Rivi 220: | ||
jQuery('#' + id + '_button').removeClass('open'); | jQuery('#' + id + '_button').removeClass('open'); | ||
jQuery('#' + id + '_button').addClass('locked'); | jQuery('#' + id + '_button').addClass('locked'); | ||
− | jQuery('.' + id).find('input').attr('disabled', true); | + | jQuery('.' + id).find('input ').not('.jwToArchive').attr('disabled', true); |
jQuery('.' + id).find('select').attr('disabled', true); | jQuery('.' + id).find('select').attr('disabled', true); | ||
jQuery('.' + id).find('button').attr('disabled', true); | jQuery('.' + id).find('button').attr('disabled', true); | ||
Rivi 164: | Rivi 230: | ||
jQuery('.' + id).find('button').attr('disabled', false); | jQuery('.' + id).find('button').attr('disabled', false); | ||
//Jw_FormFieldResizer(); | //Jw_FormFieldResizer(); | ||
− | setTimeout(function() { Jw_FormFieldResizer(); }, | + | setTimeout(function() { Jw_FormFieldResizer(); }, 100); |
} | } | ||
jQuery('.' + id + '_more').toggle(); | jQuery('.' + id + '_more').toggle(); | ||
} | } | ||
+ | |||
+ | |||
+ | |||
+ | function deletePic(a) { | ||
+ | |||
+ | jQuery( a.target ).parent().parent().parent().parent().find('div.sfImagePreviewWrapper').html(''); | ||
+ | jQuery( a.target ).parent().parent().find('input.jwFileNameHide').val(''); | ||
+ | updatePic(a); | ||
+ | updateLink(a); | ||
+ | } | ||
+ | |||
+ | function updateLink(a) { | ||
+ | /* | ||
+ | var parent = jQuery(a.target).parents('div.multipleTemplateInstance').first(); | ||
+ | var curdate = parent.find('input.JwDateField').val(); | ||
+ | if (curdate == undefined) { curdate = ''; } | ||
+ | var curfile = parent.find('input.jwFileNameHide').val(); | ||
+ | if (curfile == undefined) { curfile = ''; } | ||
+ | var newhref = parent.find('a.sfImagePreview').attr('href'); | ||
+ | if (newhref != undefined) { | ||
+ | if (!!curfile) { | ||
+ | newhref = newhref.substring(0, newhref.indexOf('&wpDestFile=')); | ||
+ | newhref += '&wpDestFile=' + curfile; | ||
+ | parent.find('a.sfImagePreview').attr('href', newhref); | ||
+ | } else { | ||
+ | newhref = newhref.substring(0, newhref.lastIndexOf('_')); | ||
+ | newhref = newhref + '_' + curdate.split('/').join('-') + newhref.substring(newhref.lastIndexOf('.')); | ||
+ | parent.find('a.sfImagePreview').attr('href', newhref); | ||
+ | } | ||
+ | } | ||
+ | */ | ||
+ | } | ||
+ | |||
+ | function updatePic(a) { | ||
+ | var filename = (jQuery(a.target).val()); | ||
+ | if (filename == '') { | ||
+ | //jQuery(a.target).parents('.inputSpan').find('a.sfImagePreview').show(); | ||
+ | jQuery(a.target).parents('.inputSpan').find('span.jwRemovePic').hide(); | ||
+ | } else { | ||
+ | //jQuery(a.target).parents('.inputSpan').find('a.sfImagePreview').hide(); | ||
+ | jQuery(a.target).parents('.inputSpan').find('span.jwRemovePic').show(); | ||
+ | } | ||
+ | |||
+ | } | ||
function Jw_FormFieldResizer() { | function Jw_FormFieldResizer() { | ||
− | + | ||
jQuery('.jwResize').each(function() { | jQuery('.jwResize').each(function() { | ||
− | + | ||
jQuery(this).width(180); | jQuery(this).width(180); | ||
jQuery( this ).css('resize', 'none'); | jQuery( this ).css('resize', 'none'); | ||
− | + | ||
var sizer = Math.round(jQuery(this).parents('.jwSizer').first().width()); | var sizer = Math.round(jQuery(this).parents('.jwSizer').first().width()); | ||
if (sizer == 0) { | if (sizer == 0) { | ||
Rivi 187: | Rivi 297: | ||
} | } | ||
}); | }); | ||
− | + | ||
jQuery('.jwResizeToMax').each(function() { | jQuery('.jwResizeToMax').each(function() { | ||
− | + | ||
jQuery( this ).width(50); | jQuery( this ).width(50); | ||
jQuery( this ).css('resize', 'none'); | jQuery( this ).css('resize', 'none'); | ||
− | + | ||
var sizer = jQuery(this).parents('.jwSizer').first().outerWidth(); | var sizer = jQuery(this).parents('.jwSizer').first().outerWidth(); | ||
if (sizer == 0) { | if (sizer == 0) { | ||
Rivi 200: | Rivi 310: | ||
} | } | ||
}); | }); | ||
− | + | ||
jQuery('.jwResizeTo').each(function() { | jQuery('.jwResizeTo').each(function() { | ||
− | + | ||
jQuery( this ).width(50); | jQuery( this ).width(50); | ||
jQuery( this ).css('resize', 'none'); | jQuery( this ).css('resize', 'none'); | ||
− | + | ||
var sizer = jQuery(this).parents('.jwSizerContainer').find('.jwSizer').first().outerWidth(); | var sizer = jQuery(this).parents('.jwSizerContainer').find('.jwSizer').first().outerWidth(); | ||
if (sizer == 0) { | if (sizer == 0) { | ||
Rivi 213: | Rivi 323: | ||
} | } | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
function checkAgain() { | function checkAgain() { | ||
Rivi 298: | Rivi 357: | ||
lang = lang && (lang in labels) ? lang : 'en'; | lang = lang && (lang in labels) ? lang : 'en'; | ||
− | + | return labels[lang][labelId]; | |
} | } | ||
+ | |||
</script></includeonly> | </script></includeonly> |