Results 1 to 20 of 141

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

Thread: Improving our Coding Skills

Threaded View

  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:
    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.
    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.
    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.
    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 { ;}

    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.
    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)

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts