'use strict';
(function($) {
var woonp_timeout = null;
$(function() {
$('.woonp-input').each(function() {
woonp_init($(this));
});
});
$(document).on('woosq_loaded', function() {
woonp_init($('#woosq-popup .woonp-input'));
});
$(document).on('found_variation', function(e, t) {
var $input = $(e['target']).
closest('.variations_form').
find('.woonp-input');
if ($input.length && woonp_vars.default_value === 'price') {
var value = parseFloat($input.val());
if ($input.data('price') === undefined) {
// save the default value to reset
$input.data('price', value);
}
if (t['display_price'] !== undefined && t['display_price'] !== '') {
// Set the input value to the variation's display price if available
$input.val(t['display_price']);
}
woonp_init($input);
}
});
$(document).on('reset_data', function(e) {
var $input = $(e['target']).
closest('.variations_form').
find('.woonp-input');
if ($input.length && woonp_vars.default_value === 'price') {
if ($input.data('price') !== undefined) {
// Restore the default value (if previously saved)
$input.val($input.data('price'));
}
woonp_init($input);
}
});
$(document).on('keyup click', '.woonp-input', function() {
var $this = $(this);
if (woonp_timeout != null) clearTimeout(woonp_timeout);
woonp_timeout = setTimeout(woonp_init, 1000, $this);
});
function woonp_init($input) {
var val = parseFloat($input.val());
var min = parseFloat($input.attr('min'));
var max = parseFloat($input.attr('max'));
var step = parseFloat($input.attr('step'));
var out_of_range_flag = false;
if ((val !== '') && !isNaN(val)) {
var fix = Math.pow(10, Number(woonp_decimal_places(step)) + 2);
if ((step === '') || isNaN(step) || step <= 0) {
// Ensure step has a valid value, defaulting to 1 if not
step = 1;
}
if ((min === '') || isNaN(min) || min < 0) {
// Ensure minimum value is valid, defaulting to step if not
min = step;
}
if (val < 0 || val < min) {
// If the value is less than the minimum, set it to the minimum
out_of_range_flag = true;
val = min;
}
var remainder_before = woonp_float_remainder(
(val * fix - min * fix) / fix, step);
if (remainder_before > 0) {
// Adjust the value if there's a remainder (based on rounding direction)
if (woonp_vars.rounding === 'up') {
val = (val * fix - remainder_before * fix + step * fix) / fix;
} else {
val = (val * fix - remainder_before * fix) / fix;
}
}
if (!isNaN(min) && (val < min)) {
// Ensure the value is not below the minimum
out_of_range_flag = true;
val = min;
}
if (!isNaN(max) && (val > max)) {
// Ensure the value is not above the maximum
out_of_range_flag = true;
val = max;
}
var remainder = woonp_float_remainder((val * fix - min * fix) / fix,
step);
if (remainder > 0) {
// Round the value if there's a remainder
val = (val * fix - remainder * fix) / fix;
}
// Check if the value has more than the number of decimals set in Woocommeerce settings or if the flag out_of_range_flag is at true
if (getDecimalPlaces(parseFloat($input.val())) > woonp_vars.price_decimals || out_of_range_flag === true) {
// If the value has more than 2 decimals or flag is at false, apply rounding and set the value
$input.val(val.toFixed(woonp_vars.price_decimals)).trigger('change');
} else {
// If 2 or fewer decimals and flag is false, leave the value unchanged
$input.trigger('change');
}
}
// Trigger a custom event to notify other parts of the code about the value update
$(document.body).trigger('woonp_init', [$input, val, min, max, step]);
}
// Helper function to get the number of decimal places in a number
function getDecimalPlaces(num) {
var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
return match && match[1] ? match[1].length : 0;
}
// Function to calculate the number of decimal places in the step value
function woonp_decimal_places(num) {
var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
if (!match) {
return 0;
}
var result = Math.max(0, // Number of digits right of decimal point.
(match[1] ? match[1].length : 0)
// Adjust for scientific notation.
- (match[2] ? +match[2] : 0));
return result;
}
// Function to calculate the remainder when dividing by the step value
function woonp_float_remainder(val, step) {
var valDecCount = (val.toString().split('.')[1] || '').length;
var stepDecCount = (step.toString().split('.')[1] || '').length;
var decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
var valInt = parseInt(val.toFixed(decCount).replace('.', ''));
var stepInt = parseInt(step.toFixed(decCount).replace('.', ''));
return (valInt % stepInt) / Math.pow(10, decCount);
}
})(jQuery);
]]>A second question for the day: I would like to completely reformat the default Category pages on the Lifestyle Child theme.
At the moment, my category pages look like this by default
https://1309.fr/category/eat-drink
I would like it to look more like this
https://www.mylittleparis.com/resto-bars
So basically I think I’d like to get rid of all the preset codes in the category pages and start building afresh. But I can’t even find a category.php file to edit (does such a thing exist?)
Your help would be greatly appreciated! Enjoy your day ^^
Nikki
]]>So I’m trying to reformat my “News” page so that the first post is displayed on the left (left aligned) with the next post under it with a small summation. Then to the right of that are all the other posts that would be on that page (maybe using a widget? Im not sure). Right now that page is set up so that all the posts categorized as “News” show up there.
my site is: www.thenoise-music.com
I understand I have to create a new page template however I know nothing about php. How should I go about doing this?
Thanks!
]]>Can I amend this?
I tried to use a smaller image but then it just stretched out the image to the same proportion and came out blurry with the low resolution of the smaller file.
please advise.
thank you!
www.tulikam.com
]]>I don’t insert a lot of video [https://www.thatbeatsall.com/], so when I tried to insert video on a post and it didn’t work, I was curious…
I found that the video’s normal code was being changed to something else…
example:
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="src" value="https://www.youtube.com/v/2TCHSGvNwRY?fs=1&hl=en_US" />
<param name="allowfullscreen" value="true" />
First, I started with Windows Live Writer… Checked to ensure the embed code was being placed in the the post. [not being rewritten] Everything looked good there…
I then went to the Site, viewed the source code [HTML] of the site, and saw the NEW code for the video… It’s not what I pasted.
I went to WordPress and found that Windows Live Writer was uploading the correct embed code [as it should], but once the page is rendered the code gets changed.
I tried changing the code manually via the WordPress editor, on the post, and nothing seems to work. It all gets converted, and the videos don’t show up…
When I compared it to some of my Blogger posts the embed code was there just fine…
So my question is, why or where would I check to stop the actual HTML code from being changed?
]]>It will not let me! Please help!
]]>I am using the fetch_rss() native to WP to grab my twitter feed. However, the publish date comes through in a much longer format than I like. Does anyone know if there is a way to manipulate this parsed date using PHP, or is there a file I can alter?
The date comes in as part of an array $item['pubdate']
, and echos out as Tue, 30 Dec 2008 05:47:11 +0000
I like it to be more like, Dec 30 – 5:47.
Any help would be great!
PS. If you are wondering why I don’t use one of the great plugins already developed for twitter ~ I needed a plugin that supports an offset of posts, which none of them do. Fetch_rss() does.
Thanks everyone.
]]>in one current project, I need pretty much control over the HTML-code, so the content of the page is created in Dreamweaver or just a normal text-editor and then copied into WordPress.
I already deactivated the visual editor for the admin account to prevent code-rewriting and also installed the “Disable wpautop Plugin”.
So at the current state, no code changes happen in the editor within WordPress, but the final code that is sent to the browser still gets modified:
As an examle this code:
<div class=”headline”><span class=”floatLeft”><img src=”/wp-content/images/course_numbers/headlines/w01.gif” width=”58″ height=”25″></span>
<h1 class=”short”>Headline content text</h1>
</div>
Is turned into this:
<div class=”headline”><span class=”floatLeft”><img src=”/wp-content/images/course_numbers/headlines/w01.gif” width=”58″ height=”25″></span></p>
<h1 class=”short”>Headline content text</h1>
</p></div>
So for some reason, WP writes two closing paragraphs into
the source, what makes no sense in this case.
There’s no need for visual editing at this time in this project.
I just need a window for pasting in HTML code and get it sent to the browser without any filtering.
Is there any plugin I could use or a way to remove this filtering by commenting out some php-code?
I found this behaviour in WP 2.3.3, 2.5.1 and also in the beta for WP 2.6.
Any ideas how to solve this?
Thanks in advance for you help!
Daniel
]]>Unless there is some way to do that in 2.3.3 that I don’t know about…
]]>