Page 1 of 8 123 ... LastLast
Results 1 to 20 of 141

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Improving our Coding Skills

  1. #1
    Default Improving our Coding Skills
    I know that there are probably a lot of phone modders out there that want to get their feet wet into how to mess with Style Sheet (CSS) HTML and Javascripting for your themes and widgets; everything from the simplest of removing or adding an image, to moving the positioning of elements up or down, left or right to actually getting a widget to call data from a JSON link and get it to show on your screen. Where I am now compared to where I was 2 years ago is VERY different. With the help of coding giants like The_Durben, Dacal, Ian Nicoll, MaxPa1n, The.Drifter, BombMom, Chevy & Schnedi to super competent others like MamaJaay, King_O_Hill, MartyMcFly, Simon, EricB78, nateD, Ferlop15 and so many others, I know I've learned from the best.

    But there are still times when I just need someone to handhold for more than 1 post or 2. And I don't want to gum up all the great theme and tweak threads to ask 'coding' questions. So I hope this is the best sub-forum to put this in and I'm going to invite several of our best folks to subscribe to this thread and offer their helpful input when they can.

    Hope this is helpful to several!

    To improivng our coding skills!
    Grant (NewD)


    --------------------------
    So what have we learned in this thread so far!
    ---------------------------

    Key to certain code elements:

    ==
    -- is equal to
    != -- is NOT equal to
    && -- and
    || -- or
    " " -- double quotes surround a string of text - sometimes single quotes ' ' can function the same - not always
    "" -- two double quotes side by side refer to something undefined or empty of data
    if ( condition is stated here between two parentheses ) { what you want done goes here between two curly brackets and a semi colon before the end of the 'then' statement ;}
    ____________

    Removing Text from a string of text.

    So if a string (series of characters) contains characters you need removed or changed to some other format you use the replace syntax.
    If you have "Chester County" being reported in 'obj.county' and you want it to only show "Chester" then here's the code:
    Code:
    obj.county = obj.county.replace(/County/g,"")
    -- the word to be replaced goes between the / / and what to replace it with goes between the quotes " " - in this case you want 'nothing' so we use the "" side by side quoted. The g, is just the separator between the two sections.
    _____________
    Seeing if a string of text CONTAINS something.

    So if you need to test for a certain smaller string of text exists within a fuller string of text you use the IndexOF syntax. So let's test if the content of obj.county has the word "County" in it.
    Code:
    if (obj.county.indexOf("County") != -1) { then do this.....  ;}
    _____________
    Seeing if a string of text DOES NOT CONTAIN something.

    So if you need to test for a certain smaller string NOT existing within a fuller string of text you use the same IndexOF syntax. So let's test if the content of obj.county DOESN'T have the word "County" in it.
    Code:
    if (obj.county.indexOf("County") == -1) { then do this.....  ;}
    . Notice the only difference between this one and the last one is != versus ==. The last two are 'case sensitive too' .. So "County" and "county" are not the same thing. Using the OR syntax you could test for both.
    Code:
    if ((obj.county.indexOf("County") != -1) || (obj.county.indexOf("county") != -1)) { then do this.....  ;}
    Notice how if you test for 'two' things -- you need double parentheses (( before the first test and after the second test)) before you state the 'THEN' clause of the if/then statement { ;}
    _____________
    A BASIC IF/THEN STATEMENT

    Let's combine two of the above into a statement that I needed recently to make sure the word "County" wasn't displayed in the County name even if it was in the XML file from WidgetWeather. In Canada the extraLocCounty field in the XML states the county name ONLY without the word "County" but in the US it adds the word County. So Marty in his MaxPa1n version of the the UniAW Lockscreen set the text to show on the screen as COUNTY OF: ____then the County Name Here___. In the US we were seeing things like COUNTY OF: CHESTER COUNTY where in Canada they would only see things like COUNTY OF: SIMCOE. To make sure both in the US and in CANADA you'd only ever see the County's NAME after the : the code fix went like this.
    Code:
    if (obj.county.indexOf("County") != -1) {obj.county = obj.county.replace(/ County/g,"");}
    which basically translates to:
    If the words in obj.county contain the word "County", then replace the word "County" with blank space.
    Now wherever later in the code he calls for the county to be displayed - it will never contain the WORD "County" whether it's in the XML file or not.
    _______________
    Last edited by NewdestinyX; 09-16-2013 at 11:23 AM.
    Here to help if I can. If I can't I know someone who can!

  2. The Following 8 Users Say Thank You to NewdestinyX For This Useful Post:

    chevymusclecar (09-12-2013), daddykool (04-22-2014), King_O_Hill (09-10-2013), MnM'S (09-15-2013), nateD (09-10-2013), RKO1195 (09-14-2013), The_Durben (09-15-2013), wiipro (04-28-2014)

  3. #2
    Is this the new Great Debate thread? Just kidding. Will follow what goes on here.

  4. The Following 3 Users Say Thank You to Krima For This Useful Post:

    King_O_Hill (09-10-2013), nateD (09-10-2013), NewdestinyX (09-10-2013)

  5. #3
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,507
    Thanks
    42,116
    Thanked 17,950 Times in 6,529 Posts

    Ok, I'm in.
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  6. The Following 3 Users Say Thank You to King_O_Hill For This Useful Post:

    nateD (09-10-2013), NewdestinyX (09-10-2013), RKO1195 (09-14-2013)

  7. #4
    Quote Originally Posted by Krima View Post
    Is this the new Great Debate thread? Just kidding. Will follow what goes on here.
    Quote Originally Posted by King_O_Hill View Post
    Ok, I'm in.
    Thanks, Krima & King. Knew I could count on you guys.

    My first question may not seem so 'noob' and I don't want to scare away any people who simply need to learn about the top: and left: commands. ALL QUESTIONS are welcome here no matter how basic.

    But - after parusing Rasputin007's set of code lines to draw city data from Google rather than Yahoo I hit a coding snare I've not dealt with before.

    In the model widget I patterned after The.Drifter's widget he sent me to beta for him in the main.js he had the usual.

    ------------MAIN.JS------------------
    var =
    var =
    var =
    ------(several variables to start go here)
    -------------------------------------
    function init () {
    }
    --------this is where you can do many things that are affect on launch of the widget (I think)
    ---I found I had to do my sizing change to fonts here --> based on what font was chosen in the options.plist of my iWidget.

    --------------------------------------
    function dealWithWeather (obj) {
    }
    ------this is where I put all my if/then/else statement that scan the XML document from Widget Weather to figure out whether it's a city, township name,etc.. and then I can also define what then appears on the screen with documentGetElementById("City"), etc.. Any switches go here too..
    ---------------------------------
    function UpdateClock() {
    }
    ---haven't learned this section yet but obviously it deals with how the widgets views time passing
    ---------------------------------------
    function UpdateWeather () {
    }
    This is where the main jQuery.get command points to the XML file's location, where the timers of the widget are established in time intervals.
    AND -- it's where you GET data from a location or document to be used and looked for in the if/then/else statements.. So for example the lines:
    obj.city = $(this).find.('city').text (); //this grabs whatever's in the field 'city' in the XML and gives it an object name called: obj.city
    obj.city2 = $(this).find.('extraLocCity').text (); //this grabs whatever's in the field 'extraLocCity' in the XML and gives it an object name called: obj.city2
    ...etc.......
    ...finally a overall update refresh timer for the widget ends this section of code....
    --------------------------------------------------------


    Okay... that format worked GREAT for when I was only examining the XML file that the Widget weather tweak outputs.. But I got 'intrigued' by Ras' Google location JSON (JSON is another database of info a website puts out) script. So I added it as Ras' described in his post in the Widget Weather thread. I got it to work in terms of it getting the data from Google and I learned the ".split" syntax to strip away all text that you don't need to deal with... BUT -- AND THIS IS MY FIRST QUESTION!!!:

    WHEN I removed all // Comment out tags in my iWdget (that I'd put there just to start working with the Google JSON) from the IF/THEN/ELSE statements under my "function dealWithWeather (obj)" section they were no longer seeing the obj.city, obj.city2 data anymore that I'd defined in the "function UpdateWeather ()" section ----> UNTIL I moved ALL my IF/THEN/ELSE and documentGetElementById coding to the "function UpdateWeather ()" section of the code... UNDER the JSON request (don't know if that's pertinent)..

    SO -- is there something about using a (var, url) JSON request that requires you to do all IF/THEN/ELSE and documentGetElementById in the same 'function' area of the code??
    Last edited by NewdestinyX; 09-10-2013 at 12:11 PM.
    Here to help if I can. If I can't I know someone who can!

  8. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-10-2013)

  9. #5
    I'm in .

    For your question, it's just because the obj variable is not global i think. Are you sure to call "dealWithWeather(obj);" at the end of the UpdateWeather function ?

    You can check with a console - with chrome, for exemple - by typing "console.log(obj)". If it doesn't return "undefined"but the element from the XML file and/or feed, it's good, your variable is global.

    You can also try to add a "var obj = new Array();" at the beginning of the main.js file.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  10. The Following 5 Users Say Thank You to Dacal For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-10-2013), NewdestinyX (09-10-2013), RKO1195 (09-14-2013), Simon (09-10-2013)

  11. #6
    Quote Originally Posted by Dacal View Post
    I'm in .

    For your question, it's just because the obj variable is not global i think. Are you sure to call "dealWithWeather(obj);" at the end of the UpdateWeather function ?

    You can check with a console - with chrome, for exemple - by typing "console.log(obj)". If it doesn't return "undefined"but the element from the XML file and/or feed, it's good, your variable is global.

    You can also try to add a "var obj = new Array();" at the beginning of the main.js file.
    Thanks, Dacal.. Though I already had "var obj = new Array();" at the beginning. So that's not it. In The.Drifter's original model he used for his iWidget - he called dealWithWeather BEFORE UpdateWeather. And his widget worked perfectly. Now it was only using checks to the XML - no JSON call. My widget also uses a JSON call.

    Here is the Main.js from my widget - and in the order below v v v v the fields only return UNDEFINED. (By the way - my 'sizevariable'/'fontvariable' are all defined in the HTML under <script>.
    Code:
    function updateWeather() {
    
    //jQuery.get('file:///private/var/mobile/Documents/widgetweather.xml', function(data) { 
    jQuery.get("widgetweather.xml", function(data){
    
    obj.updatetimestring = $(data).find('updatetimestring').text();
    
    if (updateFileTimer != obj.updatetimestring) {
    
    obj.time24hour = new Array;
    obj.hwhere = new Array;
    
    //GET DATA FROM XML	
    $(data).find('currentcondition').each( function() {
    obj.county =$(this).find('extraLocCounty').text();
    obj.statecode =$(this).find('extraLocStateCode').text();
    obj.coords =$(this).find('extraLocName').text();
    obj.lati = obj.coords.split(",")[0];
    obj.longi = obj.coords.split(" ")[1];
    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.lati + "," + obj.longi + "&sensor=false"
    $.getJSON(url, function(data) {
    obj.one = data.results[1].formatted_address;
    obj.two = data.results[2].formatted_address;
    obj.thr = data.results[3].formatted_address;
    obj.city = obj.two.split(",")[0];
    obj.city2 = obj.one.split(",")[0];
    obj.neighborhood = obj.thr.split(",")[0];
    
    })
    	
    });
    	
    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    }
    
    }).fail(function() {
    document.getElementById("xmlupdate").innerHTML = "No XML file !";
    });
    
    refreshTimer = setTimeout(updateWeather, 20*1000);
    }
    Last edited by NewdestinyX; 09-10-2013 at 07:27 PM.
    Here to help if I can. If I can't I know someone who can!

  12. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-10-2013)

  13. #7
    function updateWeather() {

    //jQuery.get('file:///private/var/mobile/Documents/widgetweather.xml', function(data) {
    jQuery.get("widgetweather.xml", function(data){

    obj.updatetimestring = $(data).find('updatetimestring').text();

    if (updateFileTimer != obj.updatetimestring) {

    obj.time24hour = new Array;
    obj.hwhere = new Array;

    //GET DATA FROM XML
    $(data).find('currentcondition').each( function() {
    obj.county =$(this).find('extraLocCounty').text();
    obj.statecode =$(this).find('extraLocStateCode').text();
    obj.coords =$(this).find('extraLocName').text();
    obj.lati = obj.coords.split(",")[0];
    obj.longi = obj.coords.split(" ")[1];
    });

    updateFileTimer = obj.updatetimestring;
    updateGoogle(obj);
    dealWithWeather(obj);
    }
    }).fail(function() {
    document.getElementById("xmlupdate").innerHTML = "No XML file !";
    });

    refreshTimer = setTimeout(updateWeather, 20*1000);
    }

    function updateGoogle(obj) {
    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.lati + "," + obj.longi + "&sensor=false";
    $.getJSON(url, function(data) {
    obj.one = data.results[1].formatted_address;
    obj.two = data.results[2].formatted_address;
    obj.thr = data.results[3].formatted_address;
    obj.city = obj.two.split(",")[0];
    obj.city2 = obj.one.split(",")[0];
    obj.neighborhood = obj.thr.split(",")[0];
    });
    }
    Your quotes were not at right places. Do a JSON request inside another request is not a good idea, i have separate both (you can keep the "updateGoogle" part inside the updateweather function if you prefer).

    BTW,

    obj.coords = $(this).find('extraLocName').text().replace(/ /g,"");
    ....
    ....
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    Last edited by Dacal; 09-10-2013 at 06:39 PM.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  14. The Following 4 Users Say Thank You to Dacal For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-10-2013), NewdestinyX (09-10-2013), RKO1195 (09-14-2013)

  15. #8
    Quote Originally Posted by Dacal View Post
    Your quotes were not at right places. Do a JSON request inside another request is not a good idea, i have separate both (you can keep the "updateGoogle" part inside the updateweather function if you prefer).
    AH.. YES! Thanks, Dacal. I see it now.. And even looking at the code I pasted today -- I saw a couple of ' { } ' that seemed to have one but not the other.. It seems like 'timers' don't need both a { and a }... So some of that confuses me..

    BTW,
    Code:
    obj.coords = $(this).find('extraLocName').text().replace(/ /g,"");
     ....
     ....
     var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    Now I don't understand what you're telling me there???? The way I used to 'split' the latitude and longitude was working fine for me.. Is this just an alternate way to code it? Better? More efficient? I'm just a little confused as to what you're trying to communicate to me there. Please elaborate.
    Here to help if I can. If I can't I know someone who can!

  16. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-10-2013)

  17. #9
    Quote Originally Posted by NewdestinyX View Post
    Now I don't understand what you're telling me there???? The way I used to 'split' the latitude and longitude was working fine for me.. Is this just an alternate way to code it? Better? More efficient? I'm just a little confused as to what you're trying to communicate to me there. Please elaborate.
    U're welcome.

    It's just a better/smaller code, just need of one variable, not three. You can do the same for updategoogle function : 6 to 3 variables. . You dońt need obj.one, two,... Merge the lines.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  18. The Following 3 Users Say Thank You to Dacal For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-10-2013), RKO1195 (09-14-2013)

  19. #10
    Hmmm. Dacal, even with your updates and adding the functionGoogle(obj) - I still get Undefined in both places where a city and a township should be showing.. I'm PM you a link to the widget..

    The moment I move all the IF/THEN/ELSE from function dealWithWeather UNDER function UpdateWeather -- then the widget works.

    But here's what I get with your update..
    Here to help if I can. If I can't I know someone who can!

  20. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-10-2013)

  21. #11
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,507
    Thanks
    42,116
    Thanked 17,950 Times in 6,529 Posts

    Quote Originally Posted by NewdestinyX View Post
    Hmmm. Dacal, even with your updates and adding the functionGoogle(obj) - I still get Undefined in both places where a city and a township should be showing.. I'm PM you a link to the widget..

    The moment I move all the IF/THEN/ELSE from function dealWithWeather UNDER function UpdateWeather -- then the widget works.

    But here's what I get with your update..
    How are you parsing the lat/long coords to the JSON call?
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  22. The Following User Says Thank You to King_O_Hill For This Useful Post:

    NewdestinyX (09-10-2013)

  23. #12
    Quote Originally Posted by King_O_Hill View Post
    How are you parsing the lat/long coords to the JSON call?
    I'm getting them right from the XML when it gets an update. The field, 'extraLocName', is a set of two 8-digit latitude/longitude numbers.
    So:
    You get the data from the XML this way:
    obj.coords =$(this).find('extraLocName').text();

    Split the data into two distinct numbers here:
    obj.lati = obj.coords.split(",")[0];
    obj.longi = obj.coords.split(" ")[1];

    then reference those two numbers in the JSON call itself here:
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.lati + "," + obj.longi + "&sensor=false";
    $.getJSON(url, function(data) {

    I've had the JSON call work working perfectly and returning values for obj.city and obj.city2 and obj.neighborhood (from google now, and not the XML) but ONLY when I place all the "function dealWithWeather" IF/ELSE IF/ELSE stuff within the "function UpdateWeather" section AFTER the JSON call itself. So I just don't understand why everything works fine when I'm ONLY calling for data from XML - but then I try to get certain data from Google (in the JSON call) I have to reposition all the code within dealWithWeather to the UpdateWeather function.
    Last edited by NewdestinyX; 09-10-2013 at 10:20 PM.
    Here to help if I can. If I can't I know someone who can!

  24. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-11-2013)

  25. #13
    Quote Originally Posted by NewdestinyX View Post
    Hmmm. Dacal, even with your updates and adding the functionGoogle(obj) - I still get Undefined in both places where a city and a township should be showing.. I'm PM you a link to the widget..

    The moment I move all the IF/THEN/ELSE from function dealWithWeather UNDER function UpdateWeather -- then the widget works.

    But here's what I get with your update..
    It's normal. You need to have a response from the two requests before launching dealwithweather function, and by default the requests are asynchronous.

    So, when you launch dealwithweather, you still don't have the response from Google. Two choice, configure the Ajaxsetup to do all requests synchronous OR call the dealwithweather function at the end of the last request.

    I have sent you a link.


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  26. The Following 4 Users Say Thank You to Dacal For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-11-2013), NewdestinyX (09-11-2013), RKO1195 (09-14-2013)

  27. #14
    King Kong ain't got nothing on me! King_O_Hill's Avatar
    Join Date
    Apr 2011
    Location
    USA
    Posts
    9,507
    Thanks
    42,116
    Thanked 17,950 Times in 6,529 Posts

    Yes! Thanks Dacal!
    Widget-Weather App Now Available! Also with MyLocation Support!
    Check out the thread here - Widget-Weather
    To install the Widget-Weather app, just go to Cydia and install. This will also remove MyLocation, as it is built in!
    Want to protect your JailBreak! Add this repo http://cydia.myrepospace.com/iLEXiNFO/ & Install "iLEX R.A.T."
    It will allow you to bring your phone back to a fresh jailbroken state!

  28. The Following 2 Users Say Thank You to King_O_Hill For This Useful Post:

    chevymusclecar (09-12-2013), Dacal (09-11-2013)

  29. #15
    Quote Originally Posted by Dacal View Post
    It's normal. You need to have a response from the two requests before launching dealwithweather function, and by default the requests are asynchronous.

    So, when you launch dealwithweather, you still don't have the response from Google. Two choice, configure the Ajaxsetup to do all requests synchronous OR call the dealwithweather function at the end of the last request.

    I have sent you a link.
    Okay.. GREAT! So I'm guessing the reason, Drifter's original widget, that I used as my learning document, had the 'deal with weather' function first - was because he was NOT intending to use a JSON AND XML request? He wouldn't have this 'synchronous' issue to deal with. I think I get it...

    Thanks, Dacal!
    Grant
    Last edited by NewdestinyX; 09-11-2013 at 10:11 AM.
    Here to help if I can. If I can't I know someone who can!

  30. The Following User Says Thank You to NewdestinyX For This Useful Post:

    King_O_Hill (09-11-2013)

  31. #16
    So, let's examine what Dacal fixed.. to allow me to keep function dealWithWeather BEFORE functionUpdateWeather..

    Let's check out the differences... I'll add the differences in red later...

    My original code (which allowed the widget to work BUT ONLY if I put the dealWithWeather section AFTER the JSON code line and obj.city, etc creation lines:
    Code:
    function updateWeather() {
    
    //jQuery.get('file:///private/var/mobile/Documents/widgetweather.xml', function(data) { 
    jQuery.get("widgetweather.xml", function(data){
    
    obj.updatetimestring = $(data).find('updatetimestring').text();
    
    if (updateFileTimer != obj.updatetimestring) {
    
    obj.time24hour = new Array;
    obj.hwhere = new Array;
    
    //GET DATA FROM XML	
    $(data).find('currentcondition').each( function() {
    obj.county =$(this).find('extraLocCounty').text();
    obj.statecode =$(this).find('extraLocStateCode').text();
    obj.coords =$(this).find('extraLocName').text().replace(/ /g,"");
    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    $.getJSON(url, function(data) {
    obj.city = data.results[1].formatted_address.split(",")[0];
    obj.city2 = data.results[2].formatted_address.split(",")[0];
    obj.neighborhood = data.results[3].formatted_address.split(",")[0];
    });
    
    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    }
    
    }).fail(function() {
    document.getElementById("xmlupdate").innerHTML = "No XML file !";
    });
    refreshTimer = setTimeout(updateWeather, 20*1000);
    }
    After Dacal's fixes (which allowed me to keep dealWithWeather earlier as I'd wanted):
    Code:
    function updateWeather() {
    
    //jQuery.get('file:///private/var/mobile/Documents/widgetweather.xml', function(data) { 
    jQuery.get("widgetweather.xml", function(data){
    
    obj.updatetimestring = $(data).find('updatetimestring').text();
    
    if (updateFileTimer != obj.updatetimestring) {
    
    obj.time24hour = new Array;
    obj.hwhere = new Array;
    
    //GET DATA FROM XML	
    $(data).find('currentcondition').each( function() {
    obj.county =$(this).find('extraLocCounty').text();
    obj.statecode =$(this).find('extraLocStateCode').text();
    obj.coords =$(this).find('extraLocName').text().replace(/ /g,"");
    });
    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    $.getJSON(url, function(data) {
    obj.city = data.results[1].formatted_address.split(",")[0];
    obj.city2 = data.results[2].formatted_address.split(",")[0];
    obj.neighborhood = data.results[3].formatted_address.split(",")[0];
    
    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    });
    }
    
    }).fail(function() {
    document.getElementById("xmlupdate").innerHTML = "No XML file !";
    });
    
    refreshTimer = setTimeout(updateWeather, 20*1000);
    }
    So Dacal told us THIS earlier as being the reason I had to move the dealWithWeather function later to make it work (when I didn't want to):
    Quote Originally Posted by Dacal View Post
    It's normal. You need to have a response from the two requests (to XML and JSON{Google}) before launching dealwithweather function, and by default the requests are asynchronous.

    So, when you launch dealwithweather, you still don't have the response from Google. Two choices:....<snip>.....OR call the dealwithweather function at the end of the last request.
    HOW did he accomplish "calling the dealWithWeather function" at the END of the last request (which in my code is the JSON request to Google)?
    Last edited by NewdestinyX; 09-11-2013 at 10:12 AM.
    Here to help if I can. If I can't I know someone who can!

  32. The Following 3 Users Say Thank You to NewdestinyX For This Useful Post:

    Dacal (09-11-2013), King_O_Hill (09-11-2013), RKO1195 (09-14-2013)

  33. #17
    Quote Originally Posted by NewdestinyX View Post
    HOW did he accomplish "calling the dealWithWeather function" at the END of the last request (which in my code is the JSON request to Google)?

    Look the quotes :

    Yours :

    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    $.getJSON(url, function(data) {
    obj.city = data.results[1].formatted_address.split(",")[0];
    obj.city2 = data.results[2].formatted_address.split(",")[0];
    obj.neighborhood = data.results[3].formatted_address.split(",")[0];
    });

    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    Mine :

    //GET DATA FROM GOOGLE JSON
    var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.coords + "&sensor=false";
    $.getJSON(url, function(data) {
    obj.city = data.results[1].formatted_address.split(",")[0];
    obj.city2 = data.results[2].formatted_address.split(",")[0];
    obj.neighborhood = data.results[3].formatted_address.split(",")[0];

    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    });


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  34. The Following 2 Users Say Thank You to Dacal For This Useful Post:

    King_O_Hill (09-11-2013), NewdestinyX (09-11-2013)

  35. #18
    Quote Originally Posted by Dacal View Post
    Look the quotes :
    Yours :

    Mine :
    HAHA!! Yes, Dacal -- "I" know the answer.. I was 'testing' others that might be watching.. LOL!! But thanks.. I'm ALWAYS happy for you to give the 'answers to the test'.. .

    Learning what I learned here - I have two other question about this scenario.
    1) Would moving the REFRESH TIMER within the bounds of the JSON call help widgets to update their info any faster? or No..?
    2) What is the unique reason for the this type of quote: ' }); ' as opposed to a simple: ' ; ' or ' } ' to close a section?

    Thanks!
    Last edited by NewdestinyX; 09-11-2013 at 01:42 PM.
    Here to help if I can. If I can't I know someone who can!

  36. The Following 2 Users Say Thank You to NewdestinyX For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-11-2013)

  37. #19
    My iPhone is a Part of Me
    Join Date
    Aug 2009
    Posts
    666
    Thanks
    325
    Thanked 2,140 Times in 490 Posts

    1.) Sorry, for the "quick & dirty" way I write code. I wish I had Dacal's "clean" code attitude.
    2.)To explain Dacal's last post above.
    A javascript function always is inside a starting bracket,{, and a closing bracket, }. Once you run the code in that function and have got some variables you want to use in another function you have to put that at the end, before the closing bracket }, in that function. Variables are by default "local", meaning they only exist within the function they were created in. So in order to use them in another function, like dealWithWeather, you have to "pass" them on into the function by including them in the round brackets ().
    OK, in the above post and Dacal's last window, the time line is as follows: the funtion updateWeather is running and picking all the infos from the xml file and assigns them to variables (obj.xxxx), The Google url uses the obj.lati and obj.longi to get a JSON response file (JSON is a newer form of xml response file!). Now the function gets the info from that JSON response file and assigns them to variables (obj.xxxx). At the end of that updateWeather funtion is a call for the dealWithWeather funtion and the "local" variables (obj) are now being passed on to that new funtion so that the new funtion can work with those variables as well.

    Hope that helps. It is always better to understand why and how something works.

    EDIT
    I used the split feature because the obj.coords had an empty space after the comma, before the longitude value and the Google url did not like to have an empty space, hence the detour to split obj.coords into obj.lati and obj.longi.

    EDIT2:
    Quote Originally Posted by NewdestinyX View Post
    2) What is the unique reason for the this type of quote: ' }); ' as opposed to a simple: ' ; ' or ' } ' to close a section?
    A very very simple rule: Every opening bracket has to have a closing bracket, does not matter if they are curly or plain round bracket.
    Sometimes it is the positioning of the closing bracket that can make a lot of difference.
    See it this way, everything within the opening and closing bracket builds an unit.
    Code:
    $.getJSON(url, function(data) {
    obj.city = data.results[1].formatted_address.split(",")[0];
    obj.city2 = data.results[2].formatted_address.split(",")[0];
    obj.neighborhood = data.results[3].formatted_address.split(",")[0];
    
    updateFileTimer = obj.updatetimestring;
    dealWithWeather(obj);
    });
    Last edited by rasputin007; 09-11-2013 at 02:25 PM.

  38. The Following 5 Users Say Thank You to rasputin007 For This Useful Post:

    chevymusclecar (09-12-2013), Dacal (09-11-2013), King_O_Hill (09-11-2013), NewdestinyX (09-11-2013), RKO1195 (09-14-2013)

  39. #20
    Quote Originally Posted by NewdestinyX View Post
    HAHA!! Yes, Dacal -- "I" know the answer.. I was 'testing' others that might be watching.. LOL!! But thanks.. I'm ALWAYS happy for you to give the 'answers to the test'.. .

    Learning what I learned here - I have two other question about this scenario.
    1) Would moving the REFRESH TIMER within the bounds of the JSON call help widgets to update their info any faster? or No..?
    2) What is the unique reason for the this type of quote: ' }); ' as opposed to a simple: ' ; ' or ' } ' to close a section?

    Thanks!
    1) No
    2) It closes the jQuery.get request .

    Look with a HTML/JS editor like Notepad++ .


    My themes : Jade HD, Silex HD, BaSalt HD,ToPaz
    All are on Cydia and/or Theme It.

  40. The Following 4 Users Say Thank You to Dacal For This Useful Post:

    chevymusclecar (09-12-2013), King_O_Hill (09-11-2013), rasputin007 (09-11-2013), RKO1195 (09-14-2013)

Page 1 of 8 123 ... LastLast
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •