Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
bignumber is an example of the kind of library that would be useful. BigDecimal, derived from IBM code, is another. But really, calculating in cents and optimizing the order of calculations should beat either one.

e: Unless you're doing compound interest calculations and then holy moly you really need to talk with an accountant.

Gazpacho fucked around with this message at 01:57 on Feb 10, 2013

Adbot
ADBOT LOVES YOU

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Tei posted:

Well.. yes.. is money. People don't like wen money is lost.

I can't say for sure, but I have this feeling, a hunch, that unless you're dealing with bank-like volumes of money, floats are fine.

A POS terminal would probably be fine. I'm imagining a situation where a customer with an overflowing shopping cart and even still a single transaction would probably be fewer than 1000 items and the money involved would be less than 10000.

At the end of the transaction, round the result to 2 decimals and I'm pretty sure that your calculations would be correct.

This whole floats-are-too-inaccurate-for-money honestly sounds like one of those programming-related legends that are not applicable to over 99% of use cases.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Jabor posted:

I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off?
The only thing that comes to mind would be gas for the 9/10 cent pricing, but that's probably not going to involve a standard POS.

The Gripper
Sep 14, 2004
i am winner

Jabor posted:

I have no idea why anyone would need sub-cent precision for a POS terminal. Does anyone actually care that they end up paying $15/item instead of $14.995 when they get nominally 50% off?
It can cause problems with end-of-week/month/year totals depending on system, even if the discrepancy is a fraction of a cent. I've dealt with stocktake/accounting systems that will halt when doing reports if the total calculated in the accounting system doesn't match the figures provided from POS terminals exactly, though generally you'll just get a warning saying "hey the figures are off, what do you want to do? [review] [override]".

Also depending on how you process refunds (whether it's based on final invoice price or recalculated based on number of stock purchased, price and discounts, which is fairly common in wholesale though rare in retail) you could make people mad that they can't match their $14.9995 refund to their original $15 invoice.

It's super minor but if it can be avoided there's no reason to not get it as accurate as the rest of your system.

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
Also don't store currency in a back-end system in anything other than an extensible decimal format, because you'll be screwed if the precision requirements change.

Tei it's really hard to give you abstract advice without knowing anything about your requirements. You'll be using floating-point arithmetic either way (binary or decimal) so you should learn how it works, and not treat it as magic. And again, if you are going to deal with real money, have an accountant review your calculation methods.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following?

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

DreadCthulhu posted:

Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following?
I don't know your level - IANAWD (I am not a web developer) but here's the way I see it:

Say you want to do MVC. You have your model classes (where your data is.) You have your view - the thing that presents your data.

Your problem is that without a framework, you need to figure out yourself how to get your view to reflect the content of your model. You can do this yourself but it's boring and sucks rear end.

With a framework like knockout JS, you get stuff like

* Declarative Bindings - easily associate DOM elements with model data.
* Automatic UI refresh - when the data in your model changes, the UI will automatically update itself to reflect the state of the model for free.

So you get the ability to just annotate an HTML file with a tag indicating that the html element (like an item dropdown) is part of your model, and the framework will update the content of the dropdown accordingly, and change the values in the model when the value changes in the UI.

Regarding which framework is best, I have no idea because I am a C++ developer and know very little about front end development. Just pick the one that's least annoying - I liked knockout for what it's worth, but I bet people hate it because microsoft likes it.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

You guys should check out meteor if you haven't already, it's pretty cool.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Thanks for the clarification. Are any of those frameworks particularly friendly to highly relational and hierarchical data?

Say I'm writing the admin dashboard for an analytics service, and so I end up fetching a lot of data across tables (pre-empting the NoSQL suggestion, yes it's something I'm thinking about), joining it and and doing some light processing of it in before displaying it (yes, this should be eventually done server side, but at this early piloting stage it's ok). Backbone sucked balls for this and I ended up having to basically do a manual two step of "fetch all of the data I might need", one table at a time, with Parse's promises. Once the data is available, I process it and dump the results into the DOM. Using

Backbone views and models for linking 3-4 tables together looked significantly harder than doing it by hand "the dumb way".

DreadCthulhu fucked around with this message at 01:17 on Feb 12, 2013

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

DreadCthulhu posted:

Using Backbone views and models for linking 3-4 tables together looked significantly harder than doing it by hand "the dumb way".
Backbone makes some stuff easy, but it is really focused on doing a few things and nothing else. However there is a pretty big ecosystem of projects that build on backbone and give more features. You should look at backbone.relational or backbone.associations or backbone supermodels for building a hierarchy of models. Also since you asked about MVC stuff, Marionette is a great framework that builds on backbone that I like.

uncleTomOfFinland
May 25, 2008

DreadCthulhu posted:

Can someone in the know kindly summarize what's going on with all of the JS MVC frameworks that have sprouted in the past couple of years? Angular, Ember, Knockout, Backbone etc.. why does the world need so many and which ones should I be following?

This seemed like a pretty good summary to me:
http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/

Personally I have been playing around a little with Angular and so far I'm kind of liking it. Not so bare-bones (heh get it) as backbone but ones like Meteor seem to go a bit too far.

Zeether
Aug 26, 2011

I'm doing a "Robo-speak convertor" as an assignment in JS and I have most of the logic down, but something is failing in one place or another and I'm not sure why. It's supposed to be a menu where you enter 1, 2, 3 or "exit" in a text box and click submit, and each of these commands does a specific thing. 1 prompts you to enter the string to be converted into robo-speak, 2 will convert the string and then 3 will output it. "Exit" just says "Thanks for using the convertor" and stops the program. When the text is converted, if a word is more than 6 letters long it adds "zzz" to the beginning of the word, and if it's less than 6 letters it adds "eep-" to the beginning.

I started off by assigning global variables:
code:
var flag = 0;
	var stringToConvert = new String();
	var convertArray = new Array();
	var convertedArray = new Array();
	var convertedString;
Then I have two functions called "texter()" and "cleartext()" which output to the paragraph on the screen and clear the text box when it's clicked on respectively. Finally I have a huge function called "menu()" and this is where I can't really figure out what to do:

code:
function menu(){//parses the input text
	var userInput = document.getElementById('input').value;
	texter(userInput);
	console.log("start "+userInput);
	
	if(flag == 0){
		if(userInput == "1"){
		 console.log("userInput was 1, ask user to enter a string");
		 texter("input a string");
		 stringToConvert = userInput;

	       }else if(userInput == "2"){

		 console.log("User entered 2 to convert the string");

		if (flag != 1){
		 texter("You must input a string first!");
		 flag = 1;
					
                }
                if (flag == 1){
			convertArray = userInput.split(" ");
			for (var i = 0; i < convertArray.length; i++){

				  if (convertArray[i].length < 6){
				   convertedArray[i] = "eep-" + convertArray[i];

				  }else{
				   convertedArray[i] = convertArray[i] + "zzz";
									}			
					console.log("userInput converted");
				}
				
			convertedString = convertArray.join(" ");
			//convert stringToConvert to robospeek;
			texter("The string has been saved.");
			console.log("Converted string saved.");
			}
		}
	
		else if (userInput == "3"){

		if (flag != 1){
			texter("You did not input a string to convert!");
		}
                if (flag == 1){
			//output convertedString to texter
			texter(convertedString);
			console.log("The converted text was output");
				}

	    }
		
	} else if(flag == 1){

	 //capture user input as string to convert
	 stringToConvert = userInput;
	 flag = 0;
	 console.log("user input string to be converted");

	}
}
I can get it to prompt for the input when I enter the number 1 and I can enter a string, but then when I enter the number 2 and press the button to convert it, it outputs both "The string has been saved." and "You must input a string first!" (The program is supposed to tell a user if they don't enter something to convert if they just enter 2 or 3 with no string) Entering 3 does not do anything. I have the feeling it has something to do with the flag global variable I set to control whether or not to convert, but it could also be something else I missed. The console.log() commands are there to keep it in check.

Zeether fucked around with this message at 23:31 on Feb 12, 2013

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Learn how to use the debugger. Open this up in the browser of your choice, open the console, and set a breakpoint on the start of your menu function. Then press buttons, and step through what's happening line-by-line. Especially the part that isn't working right.

I've spoilered the answer so you can investigate it yourself and then check your result:
Once you enter the first big if-block (i.e. when flag == 0), flag is ... 0! Which means that the following if-statements that check the value of flag are a little bit pointless. There are a few other issues in there too, but that's probably the first one you'll encounter.

I won't comment too much on the structure of the code, I'll just note that you should really work on decomposing your application into little independent, testable bits instead of putting them all together in one big function.

xenilk
Apr 17, 2004

ERRYDAY I BE SPLIT-TONING! Honestly, its the only skill I got other than shooting the back of women and calling it "Editorial".
Hopefully one of you can help me but I am ready to pay someone to implement a rotator into my already existing script. I've made a thread on SAMart :)

http://forums.somethingawful.com/showthread.php?threadid=3533585

Zeether
Aug 26, 2011

Jabor posted:

Learn how to use the debugger. Open this up in the browser of your choice, open the console, and set a breakpoint on the start of your menu function. Then press buttons, and step through what's happening line-by-line. Especially the part that isn't working right.

I've spoilered the answer so you can investigate it yourself and then check your result:
Once you enter the first big if-block (i.e. when flag == 0), flag is ... 0! Which means that the following if-statements that check the value of flag are a little bit pointless. There are a few other issues in there too, but that's probably the first one you'll encounter.

I won't comment too much on the structure of the code, I'll just note that you should really work on decomposing your application into little independent, testable bits instead of putting them all together in one big function.
I figured out the flag bit, thanks. I'll go through it piece by piece and figure out what's not working right after I work a bit on the flags.

Fake edit: I got it to save and convert the text string. Now I just need to fix the "3" part and add the exit command.

Loving Africa Chaps
Dec 3, 2007


We had not left it yet, but when I would wake in the night, I would lie, listening, homesick for it already.

Right i'm playing around with javascript at the moment and would like some help with what should be a very simple problem but for some reason every time i try to solve it i can't.

I'm trying to make a little script that populates an array and then does some maths using it. Basically what i would like it to do is something like this

code:
var author = [];			
var year = [];	
var number = [];	
var effect = [];	
var combined = [];

function newform () {
		var i=author.length;
		document.write('<form name=\"form' + [i] + '" id=' + [i] +'>');
		document.write('<input id=\"author\" type=\"text\"/>');
		document.write('<input id=\"year\" type=\"text\"/>');
		document.write('<input id=\"number\" type=\"text\"/>');
		document.write('<input id=\"effect\" type=\"text\"/>');
		document.write('<input type=\"button\" value=\"click\" onclick=\"run()\">');
		document.write('</form>');
};


newform();

function run(){
	var i=author.length;
	author.push(document.forms[i].author.value);
	year.push(document.forms[i].year.value); 
	number.push(document.forms[i].number.value); 
	effect.push(document.forms[i].effect.value); 
};//populate array with inputs

additup (); //do the math to complete array combined
display (); //display what i've got so far

newform ();//recreate input to add more stuff to arrays


Sending it to an xml database first would work seems kind of overkill since i don't give a poo poo about saving it long term and i'm sure there's a simple solution but i'm just being a retarded newbie.

smug forum asshole
Jan 15, 2005
What you want to do seems reasonable. Where are you stuck?

Loving Africa Chaps
Dec 3, 2007


We had not left it yet, but when I would wake in the night, I would lie, listening, homesick for it already.

It won't accept forms[i] as an argumet and if I just set a name the thing breaks after the second input.

Tei
Feb 19, 2011

I don't know what you code is suppose to do.
But I have some comments to make

(my comments inside the code)
code:

//Don't make a function that write to the document
// writting to the document is complicated, and may delete all existing html, if the document output stream is closed 
function gen_newform (i) {
  var html ='<form id="form_' + i +'">');
		+'<input name=\"author\" type=\"text\"/>'
		+''<input name=\"year\" type=\"text\"/>'
		+'<input name=\"number\" type=\"text\"/>'
		+'<input name=\"effect\" type=\"text\"/>'
		+'<input type=\"button\" value=\"click\" onclick=\"run()\">'
		+'</form>';
  return html;
};

// For this type of javascript,  jquery-less,  use innerHTML
function add_newform(i){
  var html = gen_newform(i);
  
  var out = document.getElementById("output");

  out.innerHTML = out.innerHTML + html;
} 

//you can always append more html inside innerHTML


don't read global variables inside a function, that whas parameters are for.

this:
newform(i){
//code here
}

is much better than this:
newform(){
i = something.Foo.value;
//code here
}

Modern browser have a console where you can type newform(33), and is easier to debug that way, because you control and debug, since you know what data is in 33.

Consider learning OOP, have many adventages over pure functional c-like style of code.

code:
var Stats ={
  data: [],
  newForm:function(){  },   
  process_data:function(){ },
  display_data:function(){ }
  run:function(){
   Stats.process_data();
   Stats.display_data();
 } 
};

Stats.run();

Tei fucked around with this message at 15:48 on Feb 14, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Loving Africa Chaps posted:

Right i'm playing around with javascript at the moment and would like some help with what should be a very simple problem but for some reason every time i try to solve it i can't.

I'm trying to make a little script that populates an array and then does some maths using it. Basically what i would like it to do is something like this

Here is a little script that populates an array and does some maths using it:
JavaScript code:
var someArray = [1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.10, 10.11];
var i;
var sum = 0;

for(i = 0; i < someArray.length; i++) {
    sum += someArray[i];
}

console.log("the average of the values in the array is: " + (sum/someArray.length));
You have to be a bit more specific.

Loving Africa Chaps posted:

It won't accept forms[i] as an argumet and if I just set a name the thing breaks after the second input.

What won't accept forms[i] as an argument? Nothing in your code uses forms[i] as an argument.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Tei posted:

code:

// For this type of javascript,  jquery-less,  use innerHTML
function add_newform(i){
  var html = gen_newform(i);
  
  var out = document.getElementById("output");

  out.innerHTML = out.innerHTML + html;
} 

//you can always append more html inside innerHTML

While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements.

This is a problem when you do something like this:

JavaScript code:
var someDiv = document.createElement('div');

someDiv.innerHTML = '<button id="coolButton">Click me to add asterisks after me</button>*';
document.body.appendChild(someDiv);

document.getElementById('coolButton').addEventListener('click', function () { someDiv.innerHTML += '*' }, false);
This works once, because the clickhandler points to the old coolButton and the new, serialized-deserialized, coolButton has no clickhandler.

Loving Africa Chaps
Dec 3, 2007


We had not left it yet, but when I would wake in the night, I would lie, listening, homesick for it already.

Cool, thanks everyone. Starting to see the stuff I've been doing wrong. Very new to this but will go away and redo my rubbish code.

Wheany posted:


You have to be a bit more specific.


Basically I want the page to do a meta analysis. The Maths stuff I've already got working with a pre-populated array it's just I'd like to be able to add studies from a webpage hence trying to add to an array via a form.

Tei
Feb 19, 2011

Wheany posted:

While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements.

This is a problem when you do something like this:
...

Using HTML as text (and not a nodes tree) has many problems, but make sense if you style of code is "C-like".


With the C-like pure style, you would write code more like this:
code:

var someDiv = document.createElement('div');

someDiv.innerHTML = '<button id="coolButton" onclick="foo()">Click me to add asterisks after me</button>*';
document.body.appendChild(someDiv);

function foo(){
  someDiv.innerHTML += '*';
}
This one works.
I don't like it, (I am more a jquery guy) :P

Tei fucked around with this message at 17:23 on Feb 14, 2013

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Loving Africa Chaps posted:

Cool, thanks everyone. Starting to see the stuff I've been doing wrong. Very new to this but will go away and redo my rubbish code.


Basically I want the page to do a meta analysis. The Maths stuff I've already got working with a pre-populated array it's just I'd like to be able to add studies from a webpage hence trying to add to an array via a form.

So you have a web page that has a form with some fields?

I assume that the html looks like the code in your earlier post:

Loving Africa Chaps posted:

code:
		document.write('<form name=\"form' + [i] + '" id=' + [i] +'>');
		document.write('<input id=\"author\" type=\"text\"/>');
		document.write('<input id=\"year\" type=\"text\"/>');
		document.write('<input id=\"number\" type=\"text\"/>');
		document.write('<input id=\"effect\" type=\"text\"/>');
		document.write('<input type=\"button\" value=\"click\" onclick=\"run()\">');
		document.write('</form>');

Do you want several such forms on the page at once, or do you have a single form that you reuse?

Maybe you were after something like this: http://jsfiddle.net/m8hkz/

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Tei posted:

Using HTML as text (and not a nodes tree) has many problems, but make sense if you style of code is "C-like".

I much prefer code like this:

JavaScript code:
var newElementStructure = function () {
	var div = docment.createElement('div');

	div.innerHTML = '<label class="a-label-of-sorts">First name:<input class="first-name-input"></label>'

	return div;
}
to
JavaScript code:
var newElementStructure = function () {
	var div = docment.createElement('div');

	var label = document.createElement('label')
	label.appendChild(document.createTextNode('First name:'));
	label.className = 'a-label-of-sorts';

	var input = document.createElement('input');
	input.className = 'first-name-input';

	label.appendChild(input);
	div.appendChild(span)

	return div;
}
e: typo

Wheany fucked around with this message at 18:39 on Feb 14, 2013

Tei
Feb 19, 2011


Makes sense. I have written a lot of code like your second example, and is tiring (in my defense: it was scripting in XUL, and there innerHTML is not recommended or flat out don't work).

Is just easier to write this way:
JavaScript code:
var Page = Page || [];

Page.newElementStructure = function () {
	var div = $('<div>');
	div.html('<label class="a-label-of-sorts">First name:</span><input class="first-name-input"></label>');
	return div;
};

Loving Africa Chaps
Dec 3, 2007


We had not left it yet, but when I would wake in the night, I would lie, listening, homesick for it already.

Wheany posted:

So you have a web page that has a form with some fields?

I assume that the html looks like the code in your earlier post:


Do you want several such forms on the page at once, or do you have a single form that you reuse?

Maybe you were after something like this: http://jsfiddle.net/m8hkz/

One form that got reused, the fiddle is exactly what i was trying to do. Thanks so much!

Mug
Apr 26, 2005
This is probably a Javascript related question but it's hard to put my finger on.

I have these two iPhone web-app thingies (They're not actual web apps, I just open them in Safari). One of them prevents the iPhone from going to sleep when you leave it on the screen, the other allows the iPhone to sleep/autolock if you leave it running.

If you visit http://dezigner.com.au/rhyscrape.php?updatespeed=2000 on iPhone safari, the phone will eventually sleep and autolock if you just leave it running.
If you visit http://dezigner.com.au/rhyscrape_old.php the phone will just stay alive at full brightness no matter how long you sit there starting at it.

We've tried it on two iPhones and we haven't disabled Autolock or anything like that. Can anyone give me a hint as to how on earth I caused the keep-alive in the original _old one, and why it's disappeared in the newer one?

Cawd Rud
Mar 12, 2009
Salad Prong

Mug posted:

This is probably a Javascript related question but it's hard to put my finger on.

I have these two iPhone web-app thingies (They're not actual web apps, I just open them in Safari). One of them prevents the iPhone from going to sleep when you leave it on the screen, the other allows the iPhone to sleep/autolock if you leave it running.

If you visit http://dezigner.com.au/rhyscrape.php?updatespeed=2000 on iPhone safari, the phone will eventually sleep and autolock if you just leave it running.
If you visit http://dezigner.com.au/rhyscrape_old.php the phone will just stay alive at full brightness no matter how long you sit there starting at it.

We've tried it on two iPhones and we haven't disabled Autolock or anything like that. Can anyone give me a hint as to how on earth I caused the keep-alive in the original _old one, and why it's disappeared in the newer one?
This was very interesting to look into, especially since auto-lock should not be something you can control from a web page. I did some experimenting and it's this line right here, which refreshes the page every 60 seconds:
code:
<meta http-equiv="refresh" content="60">
When the page is refreshed this way, it seems to count as a user interaction, which restarts the auto-lock counter. Now, yes, you have this exact same line in both of your pages. But what seems to be happening is that your new page takes ever so slightly longer to load, and the refresh timer starts just a bit later, causing it to fall after the default 1 minute auto-lock (whose timer started right after your last interaction, which was most likely you pressing "Go").

You can test this by going to your new page and touching the screen a few seconds after the page has loaded, then leave it alone. You'll see the page refresh once after about a minute and the phone won't auto-lock until about 2 minutes afterwards. Or you can change your iPhone's autolock to something else, like 2 minutes. That would fix it completely.

In short: To fix it, change the refresh delay to something shorter, like 50 seconds.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

HTML code:
<div class="template" id="newElementTemplate">
    <label class="a-label-of-sorts">First name:<input class="first-name-input"></label>
</div>

<script>
var newElementStructure = function () {
    return docment.getElementById("newElementTemplate").cloneNode(true);
};
</script>
:q:

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Wheany posted:

While you can append to innerHTML, often you should not, because first the contents of the parent-element get serialized and returned as the value of innerHTML, then they get deserialized into completely new set of elements.

I learned this thanks to IE, where removing this line:

JavaScript code:
elem.innerHTML = elem.innerHTML;
broke things.

Mug
Apr 26, 2005

Cawd Rud posted:

This was very interesting to look into, especially since auto-lock should not be something you can control from a web page. I did some experimenting and it's this line right here, which refreshes the page every 60 seconds:
code:
<meta http-equiv="refresh" content="60">
When the page is refreshed this way, it seems to count as a user interaction, which restarts the auto-lock counter. Now, yes, you have this exact same line in both of your pages. But what seems to be happening is that your new page takes ever so slightly longer to load, and the refresh timer starts just a bit later, causing it to fall after the default 1 minute auto-lock (whose timer started right after your last interaction, which was most likely you pressing "Go").

You can test this by going to your new page and touching the screen a few seconds after the page has loaded, then leave it alone. You'll see the page refresh once after about a minute and the phone won't auto-lock until about 2 minutes afterwards. Or you can change your iPhone's autolock to something else, like 2 minutes. That would fix it completely.

In short: To fix it, change the refresh delay to something shorter, like 50 seconds.

drat, I thought you'd figured it out. I changed the refresh to 50 seconds and it still goes to sleep 10 seconds after the auto-refresh :(
I've updated it now to use the 50 second refresh so you can see if it's doing it on your end, too.

edit: To give more info, the only reason that meta refresh is even in the new one is because I thought maybe that was what was disabling the auto-lock. (I don't need that refresh because Ajax does all the work anyway). Doesn't seem to work, though. So strange.

Mug fucked around with this message at 03:08 on Feb 15, 2013

Cawd Rud
Mar 12, 2009
Salad Prong

Mug posted:

drat, I thought you'd figured it out. I changed the refresh to 50 seconds and it still goes to sleep 10 seconds after the auto-refresh :(
I've updated it now to use the 50 second refresh so you can see if it's doing it on your end, too.

edit: To give more info, the only reason that meta refresh is even in the new one is because I thought maybe that was what was disabling the auto-lock. (I don't need that refresh because Ajax does all the work anyway). Doesn't seem to work, though. So strange.
Wow, definitely thought I had done enough experimenting to call it. Frustrating to test since I gotta wait a minute each time, though!

Actually, sometimes your new page works, and sometimes it doesn't. It's inconsistent. In fact right now I couldn't get it to auto-lock at all with the new page running until I locked and unlocked myself, then tried it again. :wtc:

Try this for me: load up the page. See it refresh at the 50sec mark. When the screen dims (but before it locks), tap on it to light up the screen again. Confirm that it doesn't auto-lock after that.

For my initial post I was testing with just a blank page with only the refresh meta tag and nothing else. I tried that with a 50 second delay and it worked. Now I'm only more curious why your new page doesn't behave this way. This is some very strange behavior.

I'll attempt to do test some more theories, but right now :iiam:

Mug
Apr 26, 2005
Do you think the Ajax calls cause more battery drain that the iPhone wants to lock, but the lack of Ajax means the phone will stay awake in the old version?
I mean, there's no way the iPhone specification ever indicates this behavior, but I was curious as to whether maybe that's what was happening.

I'll play with it a little more soon. I've just got a few other things to work on right now, too.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Suspicious Dish posted:

HTML code:
<div class="template" id="newElementTemplate">
    <label class="a-label-of-sorts">First name:<input class="first-name-input"></label>
</div>

<script>
var newElementStructure = function () {
    return docment.getElementById("newElementTemplate").cloneNode(true);
};
</script>
:q:

Okay, now I have a new preference.

Tei
Feb 19, 2011

Suspicious Dish posted:

HTML code:
<script>
var newElementStructure = function () {
    return docment.getElementById("newElementTemplate").cloneNode(true);
};
</script>

cloneNode is awesome for other reason than clarity: is loving fast.

I had some table, with columns, headers,and data in it. And rebuilding it with Javascript was really slow. So what I did was cloneNode the tree of the table empty, and replace it every time I had to start again with the table, this made a slow operation instantaneous.

Having html already in the page, hidden or inside a magic tag like <script language=template>, allows your serverside templating engine to control it. If your designer is the one writting the templates, you allow your designer to control the final html. This is ****much**** better than having HTML hardcoded in javascript. It gives the control of the html to the right person.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
It also gives you syntax highlighting, which is what I like.

DreadCthulhu
Sep 17, 2008

What the fuck is up, Denny's?!
Any advice on how to best manage complexity for larger fat client JS apps? I'm mostly modularizing as much as I can at this point, anything else that works really well for you?

Adbot
ADBOT LOVES YOU

Condiment
Oct 10, 2004
I WILL DESTROY THE OPPRESSIVE "TIPPING" SYSTEM BY BECOMING AN INSUFFERABLE TIGHTWAD

DreadCthulhu posted:

Any advice on how to best manage complexity for larger fat client JS apps? I'm mostly modularizing as much as I can at this point, anything else that works really well for you?

I've found that modularizing has diminishing returns as the size and complexity of the app grows. You reach a point where you have to split your code up into separate files and directories in order to separate concerns and keep things sane.

To avoid having 15 separate HTTP calls in your app, there are build tools like Require.js that can concatenate all the files across your entire project into a single, minified file for production.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply