Re: [jQuery] Re: Removing percentage after dot - font-size: 30.6207px
I think that using Math.round() would suit best your needs: $(".ui-selected").css('font-size', Math.round(maxFont * percentage) + "px"); parseInt(12.9) // 12 Math.round(12.9) // 13 -- Massimo Lombardo Linux user #437712
Re: [jQuery] What software distributes jQuery?
On Tue, Jan 12, 2010 at 20:54, justintr wrote: > Are there any products that currently distribute jQuery? Just to name the first ones that popped up in my mind: - Aptana Inc. Aptana Studio, through plugin [1] - ActiveState Komodo (both IDE and Edit flavors), through plugin [2] - MacroMates TextMate, through bundle [3, 4] - MacRabbit Espresso, through sugar [5, 6] - NetBeans (not completely sure about this) [1] http://www.aptana.org/ [2] http://www.activestate.com/komodo_edit/ [3] http://macromates.com/ [4] http://github.com/kswedberg/jquery-tmbundle [5] http://macrabbit.com/espresso/ [6] http://fileability.net/coffee/sugar/jQuery -- Massimo Lombardo Linux user #437712
Re: [jQuery] Extracting content from a div?
If the string pattern is always the same -- i.e. nothing but the inner text changes -- then you can simply use a regular expression. I think this will help you: http://www.regular-expressions.info/examples.html -- Massimo Lombardo Linux user #437712
Re: [jQuery] Loading jQuery dynamically
On Thu, Oct 22, 2009 at 04:19, Christophe wrote: > It seems that the usual ways to dynamically load scripts (like DOM > insert) are all asynchronous. Basically, I am looking for a function > like getScript, outside jQuery. var scriptLoader = document.createElement("script"); scriptLoader.src = "http://bit.ly/jq132m";; scriptLoader.onload = scriptLoader.onreadystatechange = function () { if (!this.readyState || "loaded" === this.readyState || "complete" === this.readyState) { // replace the following line with something that properly suits your needs alert("jQuery " + jQuery.fn.jquery + " has loaded successfully and is up and running!"); } }; document.documentElement.appendChild(scriptLoader); Hope it's what you're looking for. -- Massimo Lombardo Linux user #437712
Re: [jQuery] Scroll so that an element is at the bottom of the viewport
On Mon, Nov 2, 2009 at 11:28, Deniz Dogan wrote: > I'm looking for a JQuery plugin like scrollTo but which lets me scroll > the viewport so that the bottom of an element is at the bottom of the > viewport. > > Is this possible with scrollTo? If so, how? Otherwise, is there any > other plugin I can use? Hi there. What about using some "basic" CSS? :) #targetElementId { position: fixed; bottom: 0; } -- Massimo Lombardo Linux user #437712
[jQuery] Re: What Do I Do wrong?
To help us understand better, I think you should post the relevant XHTML as well. -- Massimo Lombardo Linux user #437712
[jQuery] Re: both 'if' and 'else' blocks being executed
On Mon, Jul 13, 2009 at 15:49, Matt Zagrabelny wrote: >> The glitch is probably caused by the fact that the two input fields >> *do* share the same name; then when you touch one, you *do* alter >> both! Bug or feature? > > Having two DOM elements with the same name attribute is still valid (see > .) Sure it is. But that doesn't mean that you could abuse the language, because, you know, that would lead to unpredictable results. You should be already aware of that, you experienced it! value0 value1 value2 Mess everything up! After running this code, what do you get? You get 'ouch'! Maybe you *did* wanted that, but maybe you did not. You certainly can assign the same name to different inputs / selects / textareas / buttons, but not just because you can, it means you should... After all, the form will send the last value set only... So, leave checkboxes as checkboxes, and hidden input as hidden inputs, using different names. You get no advantage in messing up. > My main question is how does both the 'if' block and the 'else' block get > executed in the same pass through the function? As other people in this thread already pointed out, this cannot happen. Ever. Debuggers are your best friends. Show them some love, 'cause they make your life easier. >> As far as I got it, (and pretending that I got it right) you're trying >> to enable/disable an hidden input field based on another checkbox's >> checked state. > > That is it. Yay. > That way only one of the two inputs of name="billable" get sent to the > handler on the server. ORLY!? So, how, I say, HOW in the world you came up with some solution like that!? *_* It simply doesn't make sense! :-) I mean, come on: a simple checkbox is enough! Billable Show me! After submitting, in the address bar you'll see '?billable=on' if checkbox was ticked, '?' otherwise. There, solved. Server handler checks against 'Yes'? Or against 'No'? Solved too! Billable Show me! Different value, same pattern: ?billable=Yes if checked, '?' otherwise. I'll skip the 'No' case, bear with me, huh? ;-) > This page is a RT (request tracker) module and RT handles the processing > of the (server-side.) I would rather not modify the RT codebase to > handle the checkbox - I thought it could be done via JS. Web Development Rule #1: never, ever, trust user-generated data. Corollary #1 to Web Development Rule #1: client-side validation is evil. Corollary #2 to Web Development Rule #1: client-side validation can be dangerous if it's the ONLY validation. Total changed lines: 1. Now you got no excuses, buddy! ^L^ :-P > My main questions still stands, how does both the 'if' and 'else' blocks > get executed on the same pass through the function? First of all: C null and JavaScript null are totally unrelated things; stop thinking and writing JavaScript as if it were C ;-) Instead, first launch: console.log(typeof something); // return a type like 'function', 'object', or 'number', etc. Then use: if ('expected type' === typeof something) { // everything is ok, let's move on } else { // something wrong happened. } Anyway, here's my test case: XHTML Billable JavaScript -- just added some calls to the console logger http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"</a>;> $(document).ready(function () { add_billable_oncheck(); }); function add_billable_oncheck () { var billable_hidden = $('#billable_hidden')[0]; var billable_checkbox = $('#billable_checkbox')[0]; if ((billable_hidden != null) && (billable_checkbox != null)) { console.log('entering first if block'); $(billable_checkbox).change(function () { console.log('billable_checkbox has changed state!'); if (billable_checkbox.checked) { console.log('billable_checkbox is checked!'); billable_hidden.disabled = true; } else { billable_hidden.disabled = false; console.log('billable_checkbox is not checked!'); } }); console.log('exiting first if block'); } } On page load, in the console, you'll see: entering first if block exiting first if block (Everything seems to be ok.) On clicking the checkbox once: billable_checkbox has changed state! billable_checkbox is checked! (Everything still seems to be ok.) On clicking the checkbox one more time: billable_checkbox has changed state! billable_checkbox is not checked! (Still everything ok.) So, as you can see, it's *not* like you say ;-) Only one of them get executed, as it SHOULD be. :-) To sum up: change your server-side code, it's worth it! :) Hope to have been helpful. -- Massimo Lombardo Linux user #437712
[jQuery] Re: both 'if' and 'else' blocks being executed
Please, using plain English only, explain what you want to do. Then we'll try to help ;) The glitch is probably caused by the fact that the two input fields *do* share the same name; then when you touch one, you *do* alter both! Bug or feature? As far as I got it, (and pretending that I got it right) you're trying to enable/disable an hidden input field based on another checkbox's checked state. If so, you're running insanely fast by the wrong side of the street... So: give us some hint :) On Fri, Jul 10, 2009 at 22:38, Matt Zagrabelny wrote: > Greetings, > > I am experiencing some crazy stuff, at least crazy to me... > > Both the 'if' and 'else' blocks (according to firebug) are being > executed in the following anonymous function: > > > > src="/usr/share/javascript/jquery/jquery.js"> > > $(function() { > add_billable_oncheck(); > }); > > function add_billable_oncheck() { > var billable_hidden = $('#billable_hidden')[0]; > var billable_checkbox = $('#billable_checkbox')[0]; > if ((billable_hidden != null) && > (billable_checkbox != null)) { > $(billable_checkbox).change( > function(event) { > > // These are the blocks that both get executed on checkbox check > if (billable_checkbox.checked) { > billable_hidden.disabled = true; > } else { > billable_hidden.disabled = false; > } > // ^^^ > > } > ); > } > } > > > > > value="No" /> > value="Yes" /> > > > > > Does anyone have any insight into this one? > > If I add 'return;' statements at the end of the blocks, things work as > expected, however I wouldn't expect that I should have to do that. > > Thanks for the help, > > -- > Matt Zagrabelny - mzagr...@d.umn.edu - (218) 726 8844 > University of Minnesota Duluth > Information Technology Systems & Services > PGP key 1024D/84E22DA2 2005-11-07 > Fingerprint: 78F9 18B3 EF58 56F5 FC85 C5CA 53E7 887F 84E2 2DA2 > > He is not a fool who gives up what he cannot keep to gain what he cannot > lose. > -Jim Elliot > -- Linux user #437712
[jQuery] Re: Decrement on click?
Here's a simple pattern: var counter = $('element0').length; $('element1').text(counter); $('element2').click(function () { $('element1').text(counter--); }); Live example: open a live JavaScript console (like Firebug if you're using Firefox), then paste the following $('body').append(''); $('#test').css({ position: 'absolute', top: '200px', right: '0px', width: '80px', padding: '10px', backgroundColor: '#f00', color: '#fff' }); var count = 25; $('#test').text(count); $('body').click(function () { $('#test').text(--count); }); Launch it, then click on the body: you'll see the number decrease :) On Thu, Jul 9, 2009 at 16:46, littlerobothead wrote: > > I'm sure this is going to be an easy one. I'm just not seeing a > solution in any of the usual places. > > I'm getting the number of elements in a table like so: > > var count = $("#dataset-b tr").length; > > Then appending that number to a span, like so: > > $(".count").html("(" + count + ")"); > > What I want to do is subtract one from that number every time a user > clicks a row in the table I'm generating, like so: > > $("#dataset-b tr").click(function(){ > $(this).fadeOut(300); > var int = 1; > var prod = count - int; > $(".count").html("(" + prod + ")"); > }); > > The problem is that it works on the first click (9 changes to 8), but > nothing happens on subsequent clicks. Again, I'm sure this is > something simple I'm missing. Thanks for any help. > -- Linux user #437712
[jQuery] Re: Checking value
I don't know if it'll work 'cause you didn't post any XHTML, but you could give this try: if ('http://example.com/foo/bar.html' === $('a', $(this)).attr('href')) { alert('Hooray!'); } PS: avoid using == and !=, instead use === and !== On Wed, Jul 8, 2009 at 11:09, brightdad...@googlemail.com wrote: > > Hi Experts, > > I am trying to conditionally test what the value of href is equal to. > > like this; > > if($(this).find('a').attr("href")=="map.html"){ > alert("yes"); > } > > This doesn't work. Do anyone knows what i am doing wrong. > > Psuedocode please. -- Massimo Lombardo Linux user #437712
[jQuery] Re: how to change 2,5 to 2,50 ?
Yeah, that's what I mean ;) That's why I explicitly cited IEEE754 in my reply instead of saying something like «heh, you know, it's that weird javascript thing with numbers» :) On Wed, Jul 8, 2009 at 04:53, RobG wrote: > > > > On Jul 7, 9:14 pm, Massimo Lombardo wrote: > [...] >> As I see you're dealing with cents, money and stuff, I have to >> remember you that JavaScript use IEEE 754 Floating Points as its own >> internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very >> picky when dealing with money, especially if it's *their* money! :) >> >> So: be careful. And if you're relying on JavaScript logic to handle >> people's money, change programming language, JavaScript is not good at >> it. > > The language is not the issue as such, any language using IEEE-754 > numbers will have exactly the same problem - certain decimal values > can't be represented exactly. The solution is to understand the issue > and deal with it, not live in fear. > > http://www.jibbering.com/faq/#binaryNumbers > > > > -- > Rob -- Massimo Lombardo Linux user #437712
[jQuery] Re: how to change 2,5 to 2,50 ?
Thank you :) On Tue, Jul 7, 2009 at 16:46, Cesar Sanz wrote: > > Massimos' > > Number.prototype.padRight = function (fill) { > var v = this.toString().split('.'), d = v[1] || ''; > return (v[0] || '0') + '.' + d + fill.substr(d.length); > } > > Very elegant solution!! -- Massimo Lombardo Linux user #437712
[jQuery] Re: how to change 2,5 to 2,50 ?
This one is more general (and faster, I think: no if-else, no regexp) Number.prototype.padRight = function (fill) { var v = this.toString().split('.'), d = v[1] || ''; return (v[0] || '0') + '.' + d + fill.substr(d.length); } test1 = 2; test2 = 3.141592; test3 = 0.001; test4 = .33; test1.padRight('00'); // returns 2.00 test2.padRight('00'); // returns 3.141592 test3.padRight('00'); // returns 0.001 test4.padRight('00'); // returns 0.33 As I see you're dealing with cents, money and stuff, I have to remember you that JavaScript use IEEE 754 Floating Points as its own internal number type, so 0.1 + 0.2 !== 0.3: people tend to be very picky when dealing with money, especially if it's *their* money! :) So: be careful. And if you're relying on JavaScript logic to handle people's money, change programming language, JavaScript is not good at it. On Tue, Jul 7, 2009 at 12:11, weidc wrote: > > hi, > > thats my code: > > endpreis =Math.round(endpreis*100)/100; > > to round the price of something but i'd like to have 2,00 or 2,50 > instead of 2 and 2,5. > > > i'd be happy about any help. > > --weidc -- Massimo Lombardo Linux user #437712
[jQuery] Re: Howto detect DOM element from selected text
On Tue, Jun 30, 2009 at 12:31, Alexander wrote: > I am trying to detect the DOM element on a unkown web page from the > current selected text on that page. > > Which means: I select text on a web page and then I would like to get > the dom element to which this text belongs. This is not a jQuery-specific topic, it's pure JavaScript / DOM management. You need to use the W3C DOM selection API / IE DOM selection API to do that. In particular, you need to differentiate between the standard W3C implementation and the non-standard IE implementation: if (typeof window.getSelection === 'function') { // W3C DOM selection API available :) } else { if (typeof window.selection === 'object') { // IE selection API available :| } else { // No selection API available :( } } Be sure to read: https://developer.mozilla.org/en/DOM/Selection http://msdn.microsoft.com/en-us/library/ms535869.aspx -- Massimo Lombardo Linux user #437712