Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > tinymce code fragment

Reply
Thread Tools

tinymce code fragment

 
 
deostroll
Guest
Posts: n/a
 
      04-06-2009
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
 
Reply With Quote
 
 
 
 
Thomas Allen
Guest
Posts: n/a
 
      04-06-2009
On Apr 5, 11:49*pm, deostroll <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 1:49*pm, deostroll <(E-Mail Removed)> 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
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 4:46*pm, RobG <(E-Mail Removed)> 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

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-06-2009
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
 
Reply With Quote
 
deostroll
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 10:23*am, Thomas Allen <(E-Mail Removed)> wrote:
> On Apr 5, 11:49*pm, deostroll <(E-Mail Removed)> 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
 
Reply With Quote
 
Thomas Allen
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 10:14*am, deostroll <(E-Mail Removed)> wrote:
> On Apr 6, 10:23*am, Thomas Allen <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 5, 11:49*pm, deostroll <(E-Mail Removed)> 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
 
Reply With Quote
 
deostroll
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 7:22*pm, Thomas Allen <(E-Mail Removed)> wrote:
> On Apr 6, 10:14*am, deostroll <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 6, 10:23*am, Thomas Allen <(E-Mail Removed)> wrote:

>
> > > On Apr 5, 11:49*pm, deostroll <(E-Mail Removed)> 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.
 
Reply With Quote
 
Thomas Allen
Guest
Posts: n/a
 
      04-06-2009
On Apr 6, 10:28*am, deostroll <(E-Mail Removed)> wrote:
> On Apr 6, 7:22*pm, Thomas Allen <(E-Mail Removed)> wrote:
>
>
>
> > On Apr 6, 10:14*am, deostroll <(E-Mail Removed)> wrote:

>
> > > On Apr 6, 10:23*am, Thomas Allen <(E-Mail Removed)> wrote:

>
> > > > On Apr 5, 11:49*pm, deostroll <(E-Mail Removed)> 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
 
Reply With Quote
 
Jon Gómez
Guest
Posts: n/a
 
      04-06-2009

Thomas Allen wrote [trimmed quote]:
> On Apr 6, 10:28 am, deostroll <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ciphering tinymce source code deostroll Javascript 6 04-03-2009 02:51 PM
tinyMce validation problem? Ravi Katta Ruby 1 08-26-2008 02:09 PM
Cursor in TinyMCE in SWTBrowser jsimon Java 0 12-13-2006 01:24 PM
Willing to pay for some expert help integrating TinyMCE davehansen22@gmail.com Java 3 07-19-2006 09:51 PM
tinymce Manfred W Java 2 08-12-2005 08:46 AM



Advertisments