tinymce code fragment

Discussion in 'Javascript' started by deostroll, Apr 6, 2009.

  1. deostroll

    deostroll Guest

    if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    (n.src))

    What does the above mean? I mean those thing in '|'s.

    --deostroll
     
    deostroll, Apr 6, 2009
    #1
    1. Advertising

  2. deostroll

    Thomas Allen Guest

    On Apr 5, 11:49 pm, deostroll <> wrote:
    > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > (n.src))
    >
    > What does the above mean? I mean those thing in '|'s.
    >
    > --deostroll


    If n.src returns true and one of the following filenames (see below)
    is in the return value of n.src, do stuff.

    The /tiny_mce part.../ is a regular expression. The part '|' that you
    were interested in is an "or" operator in regex, so the presence of
    any of the following filenames would cause the second part to return
    true:

    * tinymce_dev.js
    * tinymce_src.js
    * tinymce_gzip.js
    * tinymce_jquery.js
    * tinymce_prototype.js

    http://www.regular-expressions.info/javascript.html

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #2
    1. Advertising

  3. deostroll

    RobG Guest

    On Apr 6, 1:49 pm, deostroll <> wrote:
    > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > (n.src))
    >
    > What does the above mean? I mean those thing in '|'s.


    Others have answered that, but the first part of the test is redundant
    and insufficient, it would be better as:

    if (n && ...)

    It is insufficient as it does not protect the expression from throwing
    an error - if n is not defined, undefined or null, attempting to
    evaluate n.src will throw an error.

    The test of n.src is redundant because if n.src is undefined, the
    RegExp test will result in undefined, which is equivalent to false.
    There may be a small performance gain in testing n.src before applying
    the RegExp test, but it is likely insignificant.


    --
    Rob
     
    RobG, Apr 6, 2009
    #3
  4. deostroll

    RobG Guest

    On Apr 6, 4:46 pm, RobG <> wrote:
    [...]
    > The test of n.src is redundant because if n.src is undefined, the
    > RegExp test will result in undefined,


    Ooops, it will result in false.



    --
    Rob
     
    RobG, Apr 6, 2009
    #4
  5. RobG wrote:
    > RobG wrote:
    > [...]
    >> The test of n.src is redundant because if n.src is undefined, the
    >> RegExp test will result in undefined,

    >
    > Ooops, it will result in false.


    What you probably were to point out is that `RegExp.prototype.test(x)' (ES3F
    15.10.6.3) is equivalent to `RegExp.prototype.exec(x) != null' which uses
    the string representation of its argument (15.10.6.2). Therefore, the
    string representation of `undefined' would be used (usually "undefined" or
    "") which the RegExp does not match. Hence the observed return value.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Apr 6, 2009
    #5
  6. deostroll

    deostroll Guest

    On Apr 6, 10:23 am, Thomas Allen <> wrote:
    > On Apr 5, 11:49 pm, deostroll <> wrote:
    >
    > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > > (n.src))

    >
    > > What does the above mean? I mean those thing in '|'s.

    >
    > > --deostroll

    >
    > If n.src returns true and one of the following filenames (see below)
    > is in the return value of n.src, do stuff.
    >
    > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > were interested in is an "or" operator in regex, so the presence of
    > any of the following filenames would cause the second part to return
    > true:
    >
    > * tinymce_dev.js
    > * tinymce_src.js
    > * tinymce_gzip.js
    > * tinymce_jquery.js
    > * tinymce_prototype.js
    >
    > http://www.regular-expressions.info/javascript.html
    >
    > Thomas


    So u are essentially calling the test() which might reside in one of
    those above mentioned files...? Can we interpret this as linking to an
    external script at runtime?

    --deostroll
     
    deostroll, Apr 6, 2009
    #6
  7. deostroll

    Thomas Allen Guest

    On Apr 6, 10:14 am, deostroll <> wrote:
    > On Apr 6, 10:23 am, Thomas Allen <> wrote:
    >
    >
    >
    > > On Apr 5, 11:49 pm, deostroll <> wrote:

    >
    > > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > > > (n.src))

    >
    > > > What does the above mean? I mean those thing in '|'s.

    >
    > > > --deostroll

    >
    > > If n.src returns true and one of the following filenames (see below)
    > > is in the return value of n.src, do stuff.

    >
    > > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > > were interested in is an "or" operator in regex, so the presence of
    > > any of the following filenames would cause the second part to return
    > > true:

    >
    > > * tinymce_dev.js
    > > * tinymce_src.js
    > > * tinymce_gzip.js
    > > * tinymce_jquery.js
    > > * tinymce_prototype.js

    >
    > >http://www.regular-expressions.info/javascript.html

    >
    > > Thomas

    >
    > So u are essentially calling the test() which might reside in one of
    > those above mentioned files...? Can we interpret this as linking to an
    > external script at runtime?
    >
    > --deostroll


    No, "test" is a method of the Regex object. It accepts one argument
    which is the string to test (the "subject" in Regex parlance). You're
    right that n.src probably refers to a file name, but this code in no
    way interacts with any files, it just searches the string n.src to see
    if it includes any of the above filenames.

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #7
  8. deostroll

    deostroll Guest

    On Apr 6, 7:22 pm, Thomas Allen <> wrote:
    > On Apr 6, 10:14 am, deostroll <> wrote:
    >
    >
    >
    > > On Apr 6, 10:23 am, Thomas Allen <> wrote:

    >
    > > > On Apr 5, 11:49 pm, deostroll <> wrote:

    >
    > > > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > > > > (n.src))

    >
    > > > > What does the above mean? I mean those thing in '|'s.

    >
    > > > > --deostroll

    >
    > > > If n.src returns true and one of the following filenames (see below)
    > > > is in the return value of n.src, do stuff.

    >
    > > > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > > > were interested in is an "or" operator in regex, so the presence of
    > > > any of the following filenames would cause the second part to return
    > > > true:

    >
    > > > * tinymce_dev.js
    > > > * tinymce_src.js
    > > > * tinymce_gzip.js
    > > > * tinymce_jquery.js
    > > > * tinymce_prototype.js

    >
    > > >http://www.regular-expressions.info/javascript.html

    >
    > > > Thomas

    >
    > > So u are essentially calling the test() which might reside in one of
    > > those above mentioned files...? Can we interpret this as linking to an
    > > external script at runtime?

    >
    > > --deostroll

    >
    > No, "test" is a method of the Regex object. It accepts one argument
    > which is the string to test (the "subject" in Regex parlance). You're
    > right that n.src probably refers to a file name, but this code in no
    > way interacts with any files, it just searches the string n.src to see
    > if it includes any of the above filenames.
    >
    > Thomas


    So you can't load a function that resides in another file (in another
    location) which is not included in your html page? (You know, bw the
    script tag).

    Can we write our script in such a way that it is dependent on another
    script file being present? Else it should show some error message? (--
    >An article link tht demonstrates this will do).


    --deostroll.
     
    deostroll, Apr 6, 2009
    #8
  9. deostroll

    Thomas Allen Guest

    On Apr 6, 10:28 am, deostroll <> wrote:
    > On Apr 6, 7:22 pm, Thomas Allen <> wrote:
    >
    >
    >
    > > On Apr 6, 10:14 am, deostroll <> wrote:

    >
    > > > On Apr 6, 10:23 am, Thomas Allen <> wrote:

    >
    > > > > On Apr 5, 11:49 pm, deostroll <> wrote:

    >
    > > > > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > > > > > (n.src))

    >
    > > > > > What does the above mean? I mean those thing in '|'s.

    >
    > > > > > --deostroll

    >
    > > > > If n.src returns true and one of the following filenames (see below)
    > > > > is in the return value of n.src, do stuff.

    >
    > > > > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > > > > were interested in is an "or" operator in regex, so the presence of
    > > > > any of the following filenames would cause the second part to return
    > > > > true:

    >
    > > > > * tinymce_dev.js
    > > > > * tinymce_src.js
    > > > > * tinymce_gzip.js
    > > > > * tinymce_jquery.js
    > > > > * tinymce_prototype.js

    >
    > > > >http://www.regular-expressions.info/javascript.html

    >
    > > > > Thomas

    >
    > > > So u are essentially calling the test() which might reside in one of
    > > > those above mentioned files...? Can we interpret this as linking to an
    > > > external script at runtime?

    >
    > > > --deostroll

    >
    > > No, "test" is a method of the Regex object. It accepts one argument
    > > which is the string to test (the "subject" in Regex parlance). You're
    > > right that n.src probably refers to a file name, but this code in no
    > > way interacts with any files, it just searches the string n.src to see
    > > if it includes any of the above filenames.

    >
    > > Thomas

    >
    > So you can't load a function that resides in another file (in another
    > location) which is not included in your html page? (You know, bw the
    > script tag).
    >
    > Can we write our script in such a way that it is dependent on another
    > script file being present? Else it should show some error message? (--
    >
    > >An article link tht demonstrates this will do).

    >
    > --deostroll.


    The only way that I know of to do this is to insert a <script> tag
    pointing to the target script:

    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'path/to/your/script.js'
    document.body.appendChild(script);

    I'd be curious if anybody knows of better ways to do this...

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #9
  10. deostroll

    Jon Gómez Guest

    Thomas Allen wrote [trimmed quote]:
    > On Apr 6, 10:28 am, deostroll <> wrote:
    >> So you can't load a function that resides in another file (in another
    >> location) which is not included in your html page? (You know, bw the
    >> script tag).
    >>
    >> Can we write our script in such a way that it is dependent on another
    >> script file being present? Else it should show some error message? (--

    >
    > The only way that I know of to do this is to insert a <script> tag
    > pointing to the target script:
    >
    > var script = document.createElement('script');
    > script.type = 'text/javascript';
    > script.src = 'path/to/your/script.js'
    > document.body.appendChild(script);
    >
    > I'd be curious if anybody knows of better ways to do this...


    How cross-browser safe is that? I've been wondering since I first saw
    it in this group.
    Jon.
     
    Jon Gómez, Apr 6, 2009
    #10
  11. deostroll

    Thomas Allen Guest

    On Apr 6, 11:32 am, Jon Gómez <> wrote:
    > Thomas Allen wrote [trimmed quote]:
    >
    >
    >
    > > On Apr 6, 10:28 am, deostroll <> wrote:
    > >> So you can't load a function that resides in another file (in another
    > >> location) which is not included in your html page? (You know, bw the
    > >> script tag).

    >
    > >> Can we write our script in such a way that it is dependent on another
    > >> script file being present? Else it should show some error message? (--

    >
    > > The only way that I know of to do this is to insert a <script> tag
    > > pointing to the target script:

    >
    > > var script = document.createElement('script');
    > > script.type = 'text/javascript';
    > > script.src = 'path/to/your/script.js'
    > > document.body.appendChild(script);

    >
    > > I'd be curious if anybody knows of better ways to do this...

    >
    > How cross-browser safe is that?  I've been wondering since I first saw
    > it in this group.
    > Jon.


    I'm not sure, which is why I've never used it in my own code. Testing
    locally, one problem is timing the actions that depend on the loaded
    script. In Mozilla/Opera, I can give the sensitive calls a low
    setTimeout (50-200) which allows for the script to load, but this does
    not work in IE6/IE7 (it appears to check for the methods' presence
    immediately, throwing an error before the extra script has time to
    load).

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #11
  12. In comp.lang.javascript message <f3de9c0a-60de-43ed-87e3-63900af1078f@r5
    g2000prh.googlegroups.com>, Sun, 5 Apr 2009 23:46:45, RobG
    <> posted:
    >On Apr 6, 1:49 pm, deostroll <> wrote:
    >> if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    >> (n.src))
    >>
    >> What does the above mean? I mean those thing in '|'s.

    >
    >Others have answered that, but the first part of the test is redundant
    >and insufficient, it would be better as:
    >
    > if (n && ...)
    >
    >It is insufficient as it does not protect the expression from throwing
    >an error - if n is not defined, undefined or null, attempting to
    >evaluate n.src will throw an error.


    I don't think it's right to say, seeing that one statement, that the
    existence etc. of n needs to be tested in it; immediately preceding code
    might have established that n can at this stage be safely referred to,
    if only by being similar enough to have failed already otherwise.

    And the explicit test for n.src protects the programmer against doubt as
    to what a RegExp test on a non-existent item might return : discovering
    that from the ISO standard is non-trivial, and both that and testing
    presumes that all browsers get it right.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
    <URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
    NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
     
    Dr J R Stockton, Apr 6, 2009
    #12
  13. deostroll

    David Mark Guest

    On Apr 6, 11:48 am, Thomas Allen <> wrote:
    > On Apr 6, 11:32 am, Jon Gómez <> wrote:
    >
    >
    >
    > > Thomas Allen wrote [trimmed quote]:

    >
    > > > On Apr 6, 10:28 am, deostroll <> wrote:
    > > >> So you can't load a function that resides in another file (in another
    > > >> location) which is not included in your html page? (You know, bw the
    > > >> script tag).

    >
    > > >> Can we write our script in such a way that it is dependent on another
    > > >> script file being present? Else it should show some error message? (--

    >
    > > > The only way that I know of to do this is to insert a <script> tag
    > > > pointing to the target script:

    >
    > > > var script = document.createElement('script');
    > > > script.type = 'text/javascript';
    > > > script.src = 'path/to/your/script.js'
    > > > document.body.appendChild(script);

    >
    > > > I'd be curious if anybody knows of better ways to do this...

    >
    > > How cross-browser safe is that?  I've been wondering since I first saw
    > > it in this group.
    > > Jon.

    >
    > I'm not sure, which is why I've never used it in my own code. Testing
    > locally, one problem is timing the actions that depend on the loaded
    > script. In Mozilla/Opera, I can give the sensitive calls a low
    > setTimeout (50-200) which allows for the script to load, but this does
    > not work in IE6/IE7 (it appears to check for the methods' presence
    > immediately, throwing an error before the extra script has time to
    > load).
    >


    As usual, you are stabbing around in the dark. Scripts load
    asynchronously. Using a timeout to race the script download is
    madness and doomed to fail.

    Time spent in that jQuery group has retarded your development.
    Misunderstanding very basic concepts is the norm among jQuery users,
    authors, technical writers and the rest of their "large and active
    community" (see attributes vs. properties.) Who would put a penny on
    them?

    HTH :)
     
    David Mark, Apr 6, 2009
    #13
  14. deostroll

    Thomas Allen Guest

    On Apr 6, 5:02 pm, David Mark <> wrote:
    > On Apr 6, 11:48 am, Thomas Allen <> wrote:
    >
    >
    >
    > > On Apr 6, 11:32 am, Jon Gómez <> wrote:

    >
    > > > Thomas Allen wrote [trimmed quote]:

    >
    > > > > On Apr 6, 10:28 am, deostroll <> wrote:
    > > > >> So you can't load a function that resides in another file (in another
    > > > >> location) which is not included in your html page? (You know, bw the
    > > > >> script tag).

    >
    > > > >> Can we write our script in such a way that it is dependent on another
    > > > >> script file being present? Else it should show some error message?(--

    >
    > > > > The only way that I know of to do this is to insert a <script> tag
    > > > > pointing to the target script:

    >
    > > > > var script = document.createElement('script');
    > > > > script.type = 'text/javascript';
    > > > > script.src = 'path/to/your/script.js'
    > > > > document.body.appendChild(script);

    >
    > > > > I'd be curious if anybody knows of better ways to do this...

    >
    > > > How cross-browser safe is that?  I've been wondering since I first saw
    > > > it in this group.
    > > > Jon.

    >
    > > I'm not sure, which is why I've never used it in my own code. Testing
    > > locally, one problem is timing the actions that depend on the loaded
    > > script. In Mozilla/Opera, I can give the sensitive calls a low
    > > setTimeout (50-200) which allows for the script to load, but this does
    > > not work in IE6/IE7 (it appears to check for the methods' presence
    > > immediately, throwing an error before the extra script has time to
    > > load).

    >
    > As usual, you are stabbing around in the dark.  Scripts load
    > asynchronously.  Using a timeout to race the script download is
    > madness and doomed to fail.
    >
    > Time spent in that jQuery group has retarded your development.
    > Misunderstanding very basic concepts is the norm among jQuery users,
    > authors, technical writers and the rest of their "large and active
    > community" (see attributes vs. properties.)  Who would put a penny on
    > them?
    >
    > HTH  :)


    Cool, maybe I should remind you that I at times make use of the jQuery
    library. Then you can waste some more of your time rearranging the
    paragraphs in your weary criticism of jQuery.fn.attr.

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #14
  15. Thomas Allen wrote:
    > On Apr 5, 11:49 pm, deostroll <> wrote:
    >> if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    >> (n.src))
    >>
    >> What does the above mean? I mean those thing in '|'s.
    >>
    >> --deostroll

    >
    > If n.src returns true and one of the following filenames (see below)
    > is in the return value of n.src, do stuff.
    >
    > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > were interested in is an "or" operator in regex, so the presence of
    > any of the following filenames would cause the second part to return
    > true:
    >
    > * tinymce_dev.js
    > * tinymce_src.js
    > * tinymce_gzip.js
    > * tinymce_jquery.js
    > * tinymce_prototype.js


    Are you making the same mistake as the author of forgetting what an
    unescaped "." means in a regular expression literal?

    Garrett
     
    Garrett Smith, Apr 6, 2009
    #15
  16. deostroll

    RobG Guest

    On Apr 7, 12:38 am, Thomas Allen <> wrote:
    > On Apr 6, 10:28 am, deostroll <> wrote:
    >
    >
    >
    > > On Apr 6, 7:22 pm, Thomas Allen <> wrote:

    >
    > > > On Apr 6, 10:14 am, deostroll <> wrote:

    >
    > > > > On Apr 6, 10:23 am, Thomas Allen <> wrote:

    >
    > > > > > On Apr 5, 11:49 pm, deostroll <> wrote:

    >
    > > > > > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/..test
    > > > > > > (n.src))

    >
    > > > > > > What does the above mean? I mean those thing in '|'s.

    >
    > > > > > > --deostroll

    >
    > > > > > If n.src returns true and one of the following filenames (see below)
    > > > > > is in the return value of n.src, do stuff.

    >
    > > > > > The /tiny_mce part.../ is a regular expression. The part '|' thatyou
    > > > > > were interested in is an "or" operator in regex, so the presence of
    > > > > > any of the following filenames would cause the second part to return
    > > > > > true:

    >
    > > > > > * tinymce_dev.js
    > > > > > * tinymce_src.js
    > > > > > * tinymce_gzip.js
    > > > > > * tinymce_jquery.js
    > > > > > * tinymce_prototype.js

    >
    > > > > >http://www.regular-expressions.info/javascript.html

    >
    > > > > > Thomas

    >
    > > > > So u are essentially calling the test() which might reside in one of
    > > > > those above mentioned files...? Can we interpret this as linking toan
    > > > > external script at runtime?

    >
    > > > > --deostroll

    >
    > > > No, "test" is a method of the Regex object. It accepts one argument
    > > > which is the string to test (the "subject" in Regex parlance). You're
    > > > right that n.src probably refers to a file name, but this code in no
    > > > way interacts with any files, it just searches the string n.src to see
    > > > if it includes any of the above filenames.

    >
    > > > Thomas

    >
    > > So you can't load a function that resides in another file (in another
    > > location) which is not included in your html page? (You know, bw the
    > > script tag).

    >
    > > Can we write our script in such a way that it is dependent on another
    > > script file being present? Else it should show some error message? (--

    >
    > > >An article link tht demonstrates this will do).

    >
    > > --deostroll.

    >
    > The only way that I know of to do this is to insert a <script> tag
    > pointing to the target script:
    >
    > var script = document.createElement('script');
    > script.type = 'text/javascript';
    > script.src = 'path/to/your/script.js'
    > document.body.appendChild(script);
    >
    > I'd be curious if anybody knows of better ways to do this...


    You might want to browse the thread started by the following message:

    <URL: http://groups.google.com/group/comp.lang.javascript/msg/0a50b3e4b5d4b580
    >



    --
    Rob
     
    RobG, Apr 6, 2009
    #16
  17. deostroll

    David Mark Guest

    On Apr 6, 5:41 pm, Thomas Allen <> wrote:
    > On Apr 6, 5:02 pm, David Mark <> wrote:
    >
    >
    >
    > > On Apr 6, 11:48 am, Thomas Allen <> wrote:

    >
    > > > On Apr 6, 11:32 am, Jon Gómez <> wrote:

    >
    > > > > Thomas Allen wrote [trimmed quote]:

    >
    > > > > > On Apr 6, 10:28 am, deostroll <> wrote:
    > > > > >> So you can't load a function that resides in another file (in another
    > > > > >> location) which is not included in your html page? (You know, bwthe
    > > > > >> script tag).

    >
    > > > > >> Can we write our script in such a way that it is dependent on another
    > > > > >> script file being present? Else it should show some error message? (--

    >
    > > > > > The only way that I know of to do this is to insert a <script> tag
    > > > > > pointing to the target script:

    >
    > > > > > var script = document.createElement('script');
    > > > > > script.type = 'text/javascript';
    > > > > > script.src = 'path/to/your/script.js'
    > > > > > document.body.appendChild(script);

    >
    > > > > > I'd be curious if anybody knows of better ways to do this...

    >
    > > > > How cross-browser safe is that?  I've been wondering since I first saw
    > > > > it in this group.
    > > > > Jon.

    >
    > > > I'm not sure, which is why I've never used it in my own code. Testing
    > > > locally, one problem is timing the actions that depend on the loaded
    > > > script. In Mozilla/Opera, I can give the sensitive calls a low
    > > > setTimeout (50-200) which allows for the script to load, but this does
    > > > not work in IE6/IE7 (it appears to check for the methods' presence
    > > > immediately, throwing an error before the extra script has time to
    > > > load).

    >
    > > As usual, you are stabbing around in the dark.  Scripts load
    > > asynchronously.  Using a timeout to race the script download is
    > > madness and doomed to fail.

    >
    > > Time spent in that jQuery group has retarded your development.
    > > Misunderstanding very basic concepts is the norm among jQuery users,
    > > authors, technical writers and the rest of their "large and active
    > > community" (see attributes vs. properties.)  Who would put a penny on
    > > them?

    >
    > > HTH  :)

    >
    > Cool, maybe I should remind you that I at times make use of the jQuery library.


    Oh brother. How could I forget?

    > Then you can waste some more of your time rearranging the
    > paragraphs in your weary criticism of jQuery.fn.attr.


    If you feel I have wasted my time explaining that idiotic and
    omnipresent function, then you are either completely ignorant or
    irretrievably stupid.
     
    David Mark, Apr 6, 2009
    #17
  18. deostroll

    Thomas Allen Guest

    On Apr 6, 6:34 pm, RobG <> wrote:
    > On Apr 7, 12:38 am, Thomas Allen <> wrote:
    >
    >
    >
    > > On Apr 6, 10:28 am, deostroll <> wrote:

    >
    > > > On Apr 6, 7:22 pm, Thomas Allen <> wrote:

    >
    > > > > On Apr 6, 10:14 am, deostroll <> wrote:

    >
    > > > > > On Apr 6, 10:23 am, Thomas Allen <> wrote:

    >
    > > > > > > On Apr 5, 11:49 pm, deostroll <> wrote:

    >
    > > > > > > > if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|_prototype).js/.test
    > > > > > > > (n.src))

    >
    > > > > > > > What does the above mean? I mean those thing in '|'s.

    >
    > > > > > > > --deostroll

    >
    > > > > > > If n.src returns true and one of the following filenames (see below)
    > > > > > > is in the return value of n.src, do stuff.

    >
    > > > > > > The /tiny_mce part.../ is a regular expression. The part '|' that you
    > > > > > > were interested in is an "or" operator in regex, so the presence of
    > > > > > > any of the following filenames would cause the second part to return
    > > > > > > true:

    >
    > > > > > > * tinymce_dev.js
    > > > > > > * tinymce_src.js
    > > > > > > * tinymce_gzip.js
    > > > > > > * tinymce_jquery.js
    > > > > > > * tinymce_prototype.js

    >
    > > > > > >http://www.regular-expressions.info/javascript.html

    >
    > > > > > > Thomas

    >
    > > > > > So u are essentially calling the test() which might reside in oneof
    > > > > > those above mentioned files...? Can we interpret this as linking to an
    > > > > > external script at runtime?

    >
    > > > > > --deostroll

    >
    > > > > No, "test" is a method of the Regex object. It accepts one argument
    > > > > which is the string to test (the "subject" in Regex parlance). You're
    > > > > right that n.src probably refers to a file name, but this code in no
    > > > > way interacts with any files, it just searches the string n.src to see
    > > > > if it includes any of the above filenames.

    >
    > > > > Thomas

    >
    > > > So you can't load a function that resides in another file (in another
    > > > location) which is not included in your html page? (You know, bw the
    > > > script tag).

    >
    > > > Can we write our script in such a way that it is dependent on another
    > > > script file being present? Else it should show some error message? (--

    >
    > > > >An article link tht demonstrates this will do).

    >
    > > > --deostroll.

    >
    > > The only way that I know of to do this is to insert a <script> tag
    > > pointing to the target script:

    >
    > > var script = document.createElement('script');
    > > script.type = 'text/javascript';
    > > script.src = 'path/to/your/script.js'
    > > document.body.appendChild(script);

    >
    > > I'd be curious if anybody knows of better ways to do this...

    >
    > You might want to browse the thread started by the following message:
    >
    > <URL:http://groups.google.com/group/comp.lang.javascript/msg/0a50b3e4b5d4b580


    This is very interesting, thanks.

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #18
  19. deostroll

    Thomas Allen Guest

    On Apr 6, 2:33 pm, Dr J R Stockton <>
    wrote:
    > And the explicit test for n.src protects the programmer against doubt as
    > to what a RegExp test on a non-existent item might return : discovering
    > that from the ISO standard is non-trivial, and both that and testing
    > presumes that all browsers get it right.


    I don't know about that, as this line doesn't capture the return
    value.

    Here's the full function that OP is referring to:

    function getBase(n) {
    if (n.src && /tiny_mce(|_dev|_src|_gzip|_jquery|
    _prototype).js/.test(n.src)) {
    if (/_(src|dev)\.js/g.test(n.src))
    t.suffix = '_src';

    if ((p = n.src.indexOf('?')) != -1)
    t.query = n.src.substring(p + 1);

    t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));

    // If path to script is relative and a base href was found add
    that one infront
    if (base && t.baseURL.indexOf('://') == -1)
    t.baseURL = base + t.baseURL;

    return t.baseURL;
    }

    return null;
    };

    Thomas
     
    Thomas Allen, Apr 6, 2009
    #19
  20. deostroll

    Jorge Guest

    On Apr 6, 5:48 pm, Thomas Allen <> wrote:
    > On Apr 6, 11:32 am, Jon Gómez <> wrote:
    > > Thomas Allen wrote [trimmed quote]:

    >
    > > > On Apr 6, 10:28 am, deostroll <> wrote:
    > > >> So you can't load a function that resides in another file (in another
    > > >> location) which is not included in your html page? (You know, bw the
    > > >> script tag).

    >
    > > >> Can we write our script in such a way that it is dependent on another
    > > >> script file being present? Else it should show some error message? (--

    >
    > > > The only way that I know of to do this is to insert a <script> tag
    > > > pointing to the target script:

    >
    > > > var script = document.createElement('script');
    > > > script.type = 'text/javascript';
    > > > script.src = 'path/to/your/script.js'
    > > > document.body.appendChild(script);

    >
    > > > I'd be curious if anybody knows of better ways to do this...

    >
    > > How cross-browser safe is that?  I've been wondering since I first saw
    > > it in this group.
    > > Jon.

    >
    > I'm not sure, which is why I've never used it in my own code. Testing
    > locally, one problem is timing the actions that depend on the loaded
    > script. In Mozilla/Opera, I can give the sensitive calls a low
    > setTimeout (50-200) which allows for the script to load, but this does
    > not work in IE6/IE7 (it appears to check for the methods' presence
    > immediately, throwing an error before the extra script has time to
    > load).
    >


    That's the way most JSON (cross-domain) apis are being done nowadays.
    It's 100% cross-browser compatible, and 100% dangerous: don't ever do
    this if you're building a page for e.g. online banking !

    This is the way of doing it by polling: suppose that this is the
    script's source code:

    //useful code here, plus:
    window.scriptOneLoaded= true;

    then you insert it in the page... :

    if (window.scriptOneLoaded) {
    //already loaded
    } else {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'scriptNumberOne.js'
    document.body.appendChild(script);

    ....and enter a loop that checks for it:

    (function check () {
    if (! window.scriptOneLoaded) {
    setTimeout(check, 500);
    } else {
    //loaded, do whatever.
    }
    })();
    }

    or you can do it via a callback:

    1.- You choose a name for the callback (e.g.'callBackFunction') and
    define it:

    window.callBackFName= function (parameters) {
    //will execute upon loading of scriptOne.
    };

    2.- Insert the <script> in your page... :

    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'example.com/path/script.js?callBack=callBackFName';
    ^^^^^^^^^^^^^^^^^^^^^^^
    document.body.appendChild(script);

    3.- The server receives the request and extracts the callBack
    parameter from the search part of the URL, and appends this to the
    script's source:

    //the source, plus:
    window.callBackFName(parameters);

    When the script gets loaded, the callBack 'callBackFName' gets called.
    (that's the way many of Yahoo's json apis work currently).

    Each one has pros/cons: the former doesn't require passing the
    callback as a parameter, the latter requires some server-side
    programming but is more 'elegant'...

    --
    Jorge.
     
    Jorge, Apr 7, 2009
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manfred W

    tinymce

    Manfred W, Aug 12, 2005, in forum: Java
    Replies:
    2
    Views:
    567
    Roedy Green
    Aug 12, 2005
  2. Replies:
    3
    Views:
    445
    Oliver Wong
    Jul 19, 2006
  3. jsimon
    Replies:
    0
    Views:
    376
    jsimon
    Dec 13, 2006
  4. Ravi Katta

    tinyMce validation problem?

    Ravi Katta, Aug 26, 2008, in forum: Ruby
    Replies:
    1
    Views:
    198
    Mark Thomas
    Aug 26, 2008
  5. deostroll

    ciphering tinymce source code

    deostroll, Apr 3, 2009, in forum: Javascript
    Replies:
    6
    Views:
    126
    Thomas 'PointedEars' Lahn
    Apr 3, 2009
Loading...

Share This Page