diff options
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/dom')
206 files changed, 1395 insertions, 24558 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/dom/.svn/all-wcprops deleted file mode 100644 index 3abfe1e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/all-wcprops +++ /dev/null @@ -1,323 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 41 -/svn/!svn/ver/1472/trunk/closure/goog/dom -END -dom_test.html -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/1341/trunk/closure/goog/dom/dom_test.html -END -multirange.js -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/1302/trunk/closure/goog/dom/multirange.js -END -fontsizemonitor.js -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/1472/trunk/closure/goog/dom/fontsizemonitor.js -END -annotate.js -K 25 -svn:wc:ra_dav:version-url -V 52 -/svn/!svn/ver/850/trunk/closure/goog/dom/annotate.js -END -a11y.js -K 25 -svn:wc:ra_dav:version-url -V 49 -/svn/!svn/ver/1302/trunk/closure/goog/dom/a11y.js -END -tagname.js -K 25 -svn:wc:ra_dav:version-url -V 51 -/svn/!svn/ver/850/trunk/closure/goog/dom/tagname.js -END -selection_test.html -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/850/trunk/closure/goog/dom/selection_test.html -END -forms_test.html -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/850/trunk/closure/goog/dom/forms_test.html -END -dom_test.js -K 25 -svn:wc:ra_dav:version-url -V 53 -/svn/!svn/ver/1471/trunk/closure/goog/dom/dom_test.js -END -savedrange.js -K 25 -svn:wc:ra_dav:version-url -V 54 -/svn/!svn/ver/850/trunk/closure/goog/dom/savedrange.js -END -nodeoffset_test.html -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/850/trunk/closure/goog/dom/nodeoffset_test.html -END -classes_test.html -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/dom/classes_test.html -END -controlrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/850/trunk/closure/goog/dom/controlrange_test.html -END -tagiterator.js -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/850/trunk/closure/goog/dom/tagiterator.js -END -dataset.js -K 25 -svn:wc:ra_dav:version-url -V 51 -/svn/!svn/ver/850/trunk/closure/goog/dom/dataset.js -END -forms.js -K 25 -svn:wc:ra_dav:version-url -V 50 -/svn/!svn/ver/1472/trunk/closure/goog/dom/forms.js -END -xml_test.html -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/1123/trunk/closure/goog/dom/xml_test.html -END -textrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/850/trunk/closure/goog/dom/textrange_test.html -END -iframe_test.html -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/1472/trunk/closure/goog/dom/iframe_test.html -END -iter_test.html -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/850/trunk/closure/goog/dom/iter_test.html -END -nodeoffset.js -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/1302/trunk/closure/goog/dom/nodeoffset.js -END -multirange_test.html -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/850/trunk/closure/goog/dom/multirange_test.html -END -nodeiterator.js -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/850/trunk/closure/goog/dom/nodeiterator.js -END -browserfeature.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/1471/trunk/closure/goog/dom/browserfeature.js -END -annotate_test.html -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/dom/annotate_test.html -END -fontsizemonitor_test.html -K 25 -svn:wc:ra_dav:version-url -V 67 -/svn/!svn/ver/1472/trunk/closure/goog/dom/fontsizemonitor_test.html -END -xml.js -K 25 -svn:wc:ra_dav:version-url -V 48 -/svn/!svn/ver/1123/trunk/closure/goog/dom/xml.js -END -a11y_test.html -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/1472/trunk/closure/goog/dom/a11y_test.html -END -dom_quirks_test.html -K 25 -svn:wc:ra_dav:version-url -V 62 -/svn/!svn/ver/1341/trunk/closure/goog/dom/dom_quirks_test.html -END -savedrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 61 -/svn/!svn/ver/850/trunk/closure/goog/dom/savedrange_test.html -END -abstractrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/dom/abstractrange_test.html -END -viewportsizemonitor_test.html -K 25 -svn:wc:ra_dav:version-url -V 70 -/svn/!svn/ver/850/trunk/closure/goog/dom/viewportsizemonitor_test.html -END -textrangeiterator.js -K 25 -svn:wc:ra_dav:version-url -V 62 -/svn/!svn/ver/1302/trunk/closure/goog/dom/textrangeiterator.js -END -dataset_test.html -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/dom/dataset_test.html -END -tagiterator_test.html -K 25 -svn:wc:ra_dav:version-url -V 62 -/svn/!svn/ver/850/trunk/closure/goog/dom/tagiterator_test.html -END -dom.js -K 25 -svn:wc:ra_dav:version-url -V 48 -/svn/!svn/ver/1472/trunk/closure/goog/dom/dom.js -END -abstractrange.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/dom/abstractrange.js -END -viewportsizemonitor.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/1472/trunk/closure/goog/dom/viewportsizemonitor.js -END -range_test.html -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/850/trunk/closure/goog/dom/range_test.html -END -savedcaretrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/850/trunk/closure/goog/dom/savedcaretrange_test.html -END -selection.js -K 25 -svn:wc:ra_dav:version-url -V 53 -/svn/!svn/ver/850/trunk/closure/goog/dom/selection.js -END -nodeiterator_test.html -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/850/trunk/closure/goog/dom/nodeiterator_test.html -END -abstractmultirange.js -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/1302/trunk/closure/goog/dom/abstractmultirange.js -END -range.js -K 25 -svn:wc:ra_dav:version-url -V 50 -/svn/!svn/ver/1002/trunk/closure/goog/dom/range.js -END -rangeendpoint.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/dom/rangeendpoint.js -END -controlrange.js -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/1302/trunk/closure/goog/dom/controlrange.js -END -classes.js -K 25 -svn:wc:ra_dav:version-url -V 51 -/svn/!svn/ver/850/trunk/closure/goog/dom/classes.js -END -savedcaretrange.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/dom/savedcaretrange.js -END -textrange.js -K 25 -svn:wc:ra_dav:version-url -V 54 -/svn/!svn/ver/1302/trunk/closure/goog/dom/textrange.js -END -textrangeiterator_test.html -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/850/trunk/closure/goog/dom/textrangeiterator_test.html -END -iframe.js -K 25 -svn:wc:ra_dav:version-url -V 51 -/svn/!svn/ver/1472/trunk/closure/goog/dom/iframe.js -END -iter.js -K 25 -svn:wc:ra_dav:version-url -V 49 -/svn/!svn/ver/1302/trunk/closure/goog/dom/iter.js -END -tagname_test.html -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/dom/tagname_test.html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/entries b/contexts/data/lib/closure-library/closure/goog/dom/.svn/entries deleted file mode 100644 index 0ddde59..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/entries +++ /dev/null @@ -1,1836 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/dom -http://closure-library.googlecode.com/svn - - - -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -dom_test.html -file - - - - -2011-12-23T22:42:28.672332Z -7b062dcb22ac7e7b9665fed86e47bcdd -2011-10-14T19:29:33.000000Z -1341 -jlistf@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2750 - -multirange.js -file - - - - -2011-12-23T22:42:28.673332Z -c04834a7cc4e1625ee6b218eea2f9e83 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -13685 - -fontsizemonitor.js -file - - - - -2011-12-23T22:42:28.674332Z -5beba024091462fd3dd4cb5668533c1e -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5302 - -annotate.js -file - - - - -2011-12-23T22:42:28.674332Z -f88392798e3b0e4db4fd6d27612b3f90 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -13002 - -a11y.js -file - - - - -2011-12-23T22:42:28.675332Z -ff3ff6286d7e2c05e344521206f0380e -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -16319 - -tagname.js -file - - - - -2011-12-23T22:42:28.676333Z -4233973d7080aa9ebe32260f9ba8d132 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2553 - -selection_test.html -file - - - - -2011-12-23T22:42:28.676333Z -6d38910a8441c5577eaaaa3287def716 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -10754 - -forms_test.html -file - - - - -2011-12-23T22:42:28.677333Z -aaff6c76cd04a2701a69c8d25f76f089 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -14267 - -dom_test.js -file - - - - -2011-12-23T22:42:28.678333Z -b0291fb32a82d340734d2b6feb23960a -2011-12-12T21:19:39.000000Z -1471 -gaal@google.com -has-props - - - - - - - - - - - - - - - - - - - - -48734 - -savedrange.js -file - - - - -2011-12-23T22:42:28.679333Z -4a25966d5e929a8addd0adae34b52b5f -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2094 - -nodeoffset_test.html -file - - - - -2011-12-23T22:42:28.679333Z -44202aed776f298d4e672eccaec570f0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2545 - -classes_test.html -file - - - - -2011-12-23T22:42:28.680333Z -8d640460d4ddea031123ce863720bbb8 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7090 - -controlrange_test.html -file - - - - -2011-12-23T22:42:28.681333Z -c4467cd1968e88fd23d8163b019a279c -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7818 - -dataset.js -file - - - - -2011-12-23T22:42:28.682333Z -349661ed2164224a71487f9695417af4 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3120 - -tagiterator.js -file - - - - -2011-12-23T22:42:28.681333Z -4a56d128648034fd70324de0e3569a51 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -10829 - -browserrange -dir - -forms.js -file - - - - -2011-12-23T22:42:28.683333Z -d91858a31c151f3ee12865b9b8fe03b3 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -11335 - -xml_test.html -file - - - - -2011-12-23T22:42:28.683333Z -0c7ab3ffcf1efcd545094397006c5045 -2011-07-14T15:15:32.000000Z -1123 -pallosp@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2993 - -textrange_test.html -file - - - - -2011-12-23T22:42:28.684333Z -c215dbaed05c17a39ae8f9db44eb19af -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4651 - -iframe_test.html -file - - - - -2011-12-23T22:42:28.685333Z -07710717a09b7d0998797628ca0fecd9 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2501 - -iter_test.html -file - - - - -2011-12-23T22:42:28.684333Z -ecdf1ff81ce8ce6a47c36753ef4eb975 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2634 - -nodeoffset.js -file - - - - -2011-12-23T22:42:28.686333Z -f20ca38661d115911894e4e5290080cf -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3137 - -multirange_test.html -file - - - - -2011-12-23T22:42:28.686333Z -8c97f696bc3fa0f0faec4b06d2e49d09 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1897 - -nodeiterator.js -file - - - - -2011-12-23T22:42:28.687333Z -31d7158470d6117ce5d3f22cdc178b04 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2868 - -browserfeature.js -file - - - - -2011-12-23T22:42:28.687333Z -98392ff4818aabe10ca5e80e9856c4d8 -2011-12-12T21:19:39.000000Z -1471 -gaal@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2236 - -annotate_test.html -file - - - - -2011-12-23T22:42:28.688333Z -badc6f550e531cc3e6a86c9913e45939 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6771 - -fontsizemonitor_test.html -file - - - - -2011-12-23T22:42:28.687333Z -06f6393ed91eaa831a1d1982f7d53957 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -8643 - -xml.js -file - - - - -2011-12-23T22:42:28.687333Z -3736d7c3bf3392908211a4b43056d580 -2011-07-14T15:15:32.000000Z -1123 -pallosp@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6899 - -a11y_test.html -file - - - - -2011-12-23T22:42:28.688333Z -a82e500df6f20c306ba04d2b14b2127f -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4647 - -pattern -dir - -dom_quirks_test.html -file - - - - -2011-12-23T22:42:28.688333Z -7745e462af25e40891fa469e96651610 -2011-10-14T19:29:33.000000Z -1341 -jlistf@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2751 - -savedrange_test.html -file - - - - -2011-12-23T22:42:28.689333Z -894e7fb6ee7e41e43e4b34325eaa5730 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1881 - -abstractrange_test.html -file - - - - -2011-12-23T22:42:28.689333Z -e8475b92cacf260eb2cdb268c02559ae -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2619 - -viewportsizemonitor_test.html -file - - - - -2011-12-23T22:42:28.689333Z -4d151d0c8a7ed8d1b0c4cc1eb9f20500 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5321 - -textrangeiterator.js -file - - - - -2011-12-23T22:42:28.689333Z -c9a4c29109ea281dc34f99d48f41054e -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7015 - -dataset_test.html -file - - - - -2011-12-23T22:42:28.690333Z -4400d1abf35f244e0fbc72747bdf87f7 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3237 - -tagiterator_test.html -file - - - - -2011-12-23T22:42:28.690333Z -babf612357f91f002753c92d80a09ba4 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -15776 - -dom.js -file - - - - -2011-12-23T22:42:28.690333Z -f02058de5922f7b9702f542b9c920398 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -82832 - -abstractrange.js -file - - - - -2011-12-23T22:42:28.690333Z -bb77b99623bc2db37ba2be5c9b9cb7a9 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -16014 - -viewportsizemonitor.js -file - - - - -2011-12-23T22:42:28.691333Z -ff858bb6471c2c9cef44e75350c20ff4 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7011 - -range_test.html -file - - - - -2011-12-23T22:42:28.691333Z -dc1eccca8359d489f582cb403d35b13e -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -26493 - -savedcaretrange_test.html -file - - - - -2011-12-23T22:42:28.691333Z -b02a9f5b12b64fe24e8b2753dddd76eb -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7073 - -selection.js -file - - - - -2011-12-23T22:42:28.692333Z -1ce2f7d72ce492e7b217186c19636eb3 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -17608 - -nodeiterator_test.html -file - - - - -2011-12-23T22:42:28.692333Z -18d5a131d33e3e83008a13304f5533fc -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1407 - -abstractmultirange.js -file - - - - -2011-12-23T22:42:28.692333Z -071c26effad172534001fe7612e183a0 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2357 - -range.js -file - - - - -2011-12-23T22:42:28.692333Z -1c018a4de043d2f0f16d3500799f4047 -2011-06-03T23:41:53.000000Z -1002 -gboyer@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7961 - -rangeendpoint.js -file - - - - -2011-12-23T22:42:28.692333Z -ccf5c03a042375fdd7dae176dc72b547 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -899 - -controlrange.js -file - - - - -2011-12-23T22:42:28.693333Z -58b4da66be4cab5f653353aa008aed7b -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -12866 - -classes.js -file - - - - -2011-12-23T22:42:28.693333Z -7057cb16ab133452e16583e297e4c8c0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7460 - -savedcaretrange.js -file - - - - -2011-12-23T22:42:28.693333Z -a1aeadd290b3d3b0608553a7f08de6c4 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6527 - -textrange.js -file - - - - -2011-12-23T22:42:28.693333Z -6ad32025552e699e6281ffc9ddaaf0d0 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -17437 - -textrangeiterator_test.html -file - - - - -2011-12-23T22:42:28.694333Z -b5ab2c7f4707b892030e79c1abdd71e7 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4413 - -iframe.js -file - - - - -2011-12-23T22:42:28.694333Z -35246f87be47d3ea957e8a27b7afb6f0 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4595 - -iter.js -file - - - - -2011-12-23T22:42:28.694333Z -9e3afc08b72440a9f45c22b5c0edcf52 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3531 - -tagname_test.html -file - - - - -2011-12-23T22:42:28.694333Z -5e9c050b6e38e5cd7be148e3ee3f7d87 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -819 - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/a11y_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractmultirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractmultirange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractmultirange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/abstractrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/annotate_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/browserfeature.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/browserfeature.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/browserfeature.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/classes_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/controlrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset.js.svn-base deleted file mode 100644 index 7febff5..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 22 -application/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dataset_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_quirks_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_quirks_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_quirks_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/dom_test.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/fontsizemonitor_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/forms_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iframe_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/iter_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/multirange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeiterator_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/nodeoffset_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/range_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/rangeendpoint.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/rangeendpoint.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/rangeendpoint.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedcaretrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/savedrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/selection_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagiterator_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/tagname_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/textrangeiterator_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/viewportsizemonitor_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/prop-base/xml_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base deleted file mode 100644 index 1ee6463..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base +++ /dev/null @@ -1,541 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting ARIA roles - * as defined by W3C ARIA Working Draft: - * http://www.w3.org/TR/2010/WD-wai-aria-20100916/ - * All modern browsers have some form of ARIA support, so no browser checks are - * performed when adding ARIA to components. - * - */ -goog.provide('goog.dom.a11y'); -goog.provide('goog.dom.a11y.Announcer'); -goog.provide('goog.dom.a11y.LivePriority'); -goog.provide('goog.dom.a11y.Role'); -goog.provide('goog.dom.a11y.State'); - -goog.require('goog.Disposable'); -goog.require('goog.dom'); -goog.require('goog.object'); - - -/** - * Enumeration of ARIA states and properties. - * @enum {string} - */ -goog.dom.a11y.State = { - // ARIA property for setting the currently active descendant of an element, - // for example the selected item in a list box. Value: ID of an element. - ACTIVEDESCENDANT: 'activedescendant', - - // ARIA property that, if true, indicates that all of a changed region should - // be presented, instead of only parts. Value: one of {true, false}. - ATOMIC: 'atomic', - - // ARIA property to specify that input completion is provided. Value: - // one of {'inline', 'list', 'both', 'none'}. - AUTOCOMPLETE: 'autocomplete', - - // ARIA state to indicate that an element and its subtree are being updated. - // Value: one of {true, false}. - BUSY: 'busy', - - // ARIA state for a checked item. Value: one of {'true', 'false', 'mixed', - // undefined}. - CHECKED: 'checked', - - // ARIA property that identifies the element or elements whose contents or - // presence are controlled by this element. Value: space-separated IDs of - // other elements. - CONTROLS: 'controls', - - // ARIA property that identifies the element or elements that describe - // this element. Value: space-separated IDs of other elements. - DESCRIBEDBY: 'describedby', - - // ARIA state for a disabled item. Value: one of {true, false}. - DISABLED: 'disabled', - - // ARIA property that indicates what functions can be performed when a - // dragged object is released on the drop target. Value: one of - // {'copy', 'move', 'link', 'execute', 'popup', 'none'}. - DROPEFFECT: 'dropeffect', - - // ARIA state for setting whether the element like a tree node is expanded. - // Value: one of {true, false, undefined}. - EXPANDED: 'expanded', - - // ARIA property that identifies the next element (or elements) in the - // recommended reading order of content. Value: space-separated ids of - // elements to flow to. - FLOWTO: 'flowto', - - // ARIA state that indicates an element's "grabbed" state in drag-and-drop. - // Value: one of {true, false, undefined}. - GRABBED: 'grabbed', - - // ARIA property indicating whether the element has a popup. Value: one of - // {true, false}. - HASPOPUP: 'haspopup', - - // ARIA state indicating that the element is not visible or perceivable - // to any user. Value: one of {true, false}. - HIDDEN: 'hidden', - - // ARIA state indicating that the entered value does not conform. Value: - // one of {false, true, 'grammar', 'spelling'} - INVALID: 'invalid', - - // ARIA property that provides a label to override any other text, value, or - // contents used to describe this element. Value: string. - LABEL: 'label', - - // ARIA property for setting the element which labels another element. - // Value: space-separated IDs of elements. - LABELLEDBY: 'labelledby', - - // ARIA property for setting the level of an element in the hierarchy. - // Value: integer. - LEVEL: 'level', - - // ARIA property indicating that an element will be updated, and - // describes the types of updates the user agents, assistive technologies, - // and user can expect from the live region. Value: one of {'off', 'polite', - // 'assertive'}. - LIVE: 'live', - - // ARIA property indicating whether a text box can accept multiline input. - // Value: one of {true, false}. - MULTILINE: 'multiline', - - // ARIA property indicating if the user may select more than one item. - // Value: one of {true, false}. - MULTISELECTABLE: 'multiselectable', - - // ARIA property indicating if the element is horizontal or vertical. - // Value: one of {'vertical', 'horizontal'}. - ORIENTATION: 'orientation', - - // ARIA property creating a visual, functional, or contextual parent/child - // relationship when the DOM hierarchy can't be used to represent it. - // Value: Space-separated IDs of elements. - OWNS: 'owns', - - // ARIA property that defines an element's number of position in a list. - // Value: integer. - POSINSET: 'posinset', - - // ARIA state for a pressed item. Value: one of {true, false, undefined, - // 'mixed'}. - PRESSED: 'pressed', - - // ARIA property indicating that an element is not editable. Value: - // one of {true, false}. - READONLY: 'readonly', - - // ARIA property indicating that change notifications within this subtree - // of a live region should be announced. Value: one of {'additions', - // 'removals', 'text', 'all', 'additions text'}. - RELEVANT: 'relevant', - - // ARIA property indicating that user input is required on this element - // before a form may be submitted. Value: one of {true, false}. - REQUIRED: 'required', - - // ARIA state for setting the currently selected item in the list. - // Value: one of {true, false, undefined}. - SELECTED: 'selected', - - // ARIA property defining the number of items in a list. Value: integer. - SETSIZE: 'setsize', - - // ARIA property indicating if items are sorted. Value: one of {'ascending', - // 'descending', 'none', 'other'}. - SORT: 'sort', - - // ARIA property for slider maximum value. Value: number. - VALUEMAX: 'valuemax', - - // ARIA property for slider minimum value. Value: number. - VALUEMIN: 'valuemin', - - // ARIA property for slider active value. Value: number. - VALUENOW: 'valuenow', - - // ARIA property for slider active value represented as text. Value: string. - VALUETEXT: 'valuetext' -}; - - -/** - * Enumeration of ARIA roles. - * @enum {string} - */ -goog.dom.a11y.Role = { - // ARIA role for an alert element that doesn't need to be explicitly closed. - ALERT: 'alert', - - // ARIA role for an alert dialog element that takes focus and must be closed. - ALERTDIALOG: 'alertdialog', - - // ARIA role for an application that implements its own keyboard navigation. - APPLICATION: 'application', - - // ARIA role for an article. - ARTICLE: 'article', - - // ARIA role for a banner containing mostly site content, not page content. - BANNER: 'banner', - - // ARIA role for a button element. - BUTTON: 'button', - - // ARIA role for a checkbox button element; use with the CHECKED state. - CHECKBOX: 'checkbox', - - // ARIA role for a column header of a table or grid. - COLUMNHEADER: 'columnheader', - - // ARIA role for a combo box element. - COMBOBOX: 'combobox', - - // ARIA role for a supporting section of the document. - COMPLEMENTARY: 'complementary', - - // ARIA role for a dialog, some descendant must take initial focus. - DIALOG: 'dialog', - - // ARIA role for a directory, like a table of contents. - DIRECTORY: 'directory', - - // ARIA role for a part of a page that's a document, not a web application. - DOCUMENT: 'document', - - // ARIA role for a landmark region logically considered one form. - FORM: 'form', - - // ARIA role for an interactive control of tabular data. - GRID: 'grid', - - // ARIA role for a cell in a grid. - GRIDCELL: 'gridcell', - - // ARIA role for a group of related elements like tree item siblings. - GROUP: 'group', - - // ARIA role for a heading element. - HEADING: 'heading', - - // ARIA role for a container of elements that together comprise one image. - IMG: 'img', - - // ARIA role for a link. - LINK: 'link', - - // ARIA role for a list of non-interactive list items. - LIST: 'list', - - // ARIA role for a listbox. - LISTBOX: 'listbox', - - // ARIA role for a list item. - LISTITEM: 'listitem', - - // ARIA role for a live region where new information is added. - LOG: 'log', - - // ARIA landmark role for the main content in a document. Use only once. - MAIN: 'main', - - // ARIA role for a live region of non-essential information that changes. - MARQUEE: 'marquee', - - // ARIA role for a mathematical expression. - MATH: 'math', - - // ARIA role for a popup menu. - MENU: 'menu', - - // ARIA role for a menubar element containing menu elements. - MENUBAR: 'menubar', - - // ARIA role for menu item elements. - MENU_ITEM: 'menuitem', - - // ARIA role for a checkbox box element inside a menu. - MENU_ITEM_CHECKBOX: 'menuitemcheckbox', - - // ARIA role for a radio button element inside a menu. - MENU_ITEM_RADIO: 'menuitemradio', - - // ARIA landmark role for a collection of navigation links. - NAVIGATION: 'navigation', - - // ARIA role for a section ancillary to the main content. - NOTE: 'note', - - // ARIA role for option items that are children of combobox, listbox, menu, - // radiogroup, or tree elements. - OPTION: 'option', - - // ARIA role for ignorable cosmetic elements with no semantic significance. - PRESENTATION: 'presentation', - - // ARIA role for a progress bar element. - PROGRESSBAR: 'progressbar', - - // ARIA role for a radio button element. - RADIO: 'radio', - - // ARIA role for a group of connected radio button elements. - RADIOGROUP: 'radiogroup', - - // ARIA role for an important region of the page. - REGION: 'region', - - // ARIA role for a row of cells in a grid. - ROW: 'row', - - // ARIA role for a group of one or more rows in a grid. - ROWGROUP: 'rowgroup', - - // ARIA role for a row header of a table or grid. - ROWHEADER: 'rowheader', - - // ARIA role for a scrollbar element. - SCROLLBAR: 'scrollbar', - - // ARIA landmark role for a part of the page providing search functionality. - SEARCH: 'search', - - // ARIA role for a menu separator. - SEPARATOR: 'separator', - - // ARIA role for a slider. - SLIDER: 'slider', - - // ARIA role for a spin button. - SPINBUTTON: 'spinbutton', - - // ARIA role for a live region with advisory info less severe than an alert. - STATUS: 'status', - - // ARIA role for a tab button. - TAB: 'tab', - - // ARIA role for a tab bar (i.e. a list of tab buttons). - TAB_LIST: 'tablist', - - // ARIA role for a tab page (i.e. the element holding tab contents). - TAB_PANEL: 'tabpanel', - - // ARIA role for a textbox element. - TEXTBOX: 'textbox', - - // ARIA role for an element displaying elapsed time or time remaining. - TIMER: 'timer', - - // ARIA role for a toolbar element. - TOOLBAR: 'toolbar', - - // ARIA role for a tooltip element. - TOOLTIP: 'tooltip', - - // ARIA role for a tree. - TREE: 'tree', - - // ARIA role for a grid whose rows can be expanded and collapsed like a tree. - TREEGRID: 'treegrid', - - // ARIA role for a tree item that sometimes may be expanded or collapsed. - TREEITEM: 'treeitem' -}; - - -/** - * Enumeration of ARIA state values for live regions. - * - * See http://www.w3.org/TR/wai-aria/states_and_properties#aria-live - * for more information. - * @enum {string} - */ -goog.dom.a11y.LivePriority = { - /** - * Default value. Used for live regions that should never be spoken. - */ - OFF: 'off', - /** - * Spoke only when the user is idle. Best option in most cases. - */ - POLITE: 'polite', - /** - * Spoken as soon as possible, which means that the information has a - * higher priority than normal, but does not necessarily interrupt - * immediately. - */ - ASSERTIVE: 'assertive' -}; - - -/** - * Sets the role of an element. - * @param {Element} element DOM node to set role of. - * @param {string} roleName role name(s). - */ -goog.dom.a11y.setRole = function(element, roleName) { - element.setAttribute('role', roleName); - element.roleName = roleName; -}; - - -/** - * Gets role of an element. - * @param {Element} element DOM node to get role of. - * @return {string} rolename. - */ -goog.dom.a11y.getRole = function(element) { - return element.roleName || ''; -}; - - -/** - * Sets the state or property of an element. - * @param {Element} element DOM node where we set state. - * @param {string} state State attribute being set. Automatically adds prefix - * 'aria-' to the state name. - * @param {string|boolean|number} value Value for the state attribute. - */ -goog.dom.a11y.setState = function(element, state, value) { - element.setAttribute('aria-' + state, value); -}; - - -/** - * Gets value of specified state or property. - * @param {Element} element DOM node to get state from. - * @param {string} stateName State name. - * @return {string} Value of the state attribute. - */ -goog.dom.a11y.getState = function(element, stateName) { - var attrb = - /** @type {string|number|boolean} */(element.getAttribute('aria-' + - stateName)); - // Check for multiple representations - attrb might - // be a boolean or a string - if ((attrb === true) || (attrb === false)) { - return attrb ? 'true' : 'false'; - } else if (!attrb) { - return ''; - } else { - return String(attrb); - } -}; - - -/** - * Gets the activedescendant of the given element. - * @param {Element} element DOM node to get activedescendant from. - * @return {Element} DOM node of the activedescendant. - */ -goog.dom.a11y.getActiveDescendant = function(element) { - var id = goog.dom.a11y.getState( - element, goog.dom.a11y.State.ACTIVEDESCENDANT); - return goog.dom.getOwnerDocument(element).getElementById(id); -}; - - -/** - * Sets the activedescendant value for an element. - * @param {Element} element DOM node to set activedescendant to. - * @param {Element} activeElement DOM node being set as activedescendant. - */ -goog.dom.a11y.setActiveDescendant = function(element, activeElement) { - goog.dom.a11y.setState(element, goog.dom.a11y.State.ACTIVEDESCENDANT, - activeElement ? activeElement.id : ''); -}; - - - -/** - * Class that allows messages to be spoken by assistive technologies that the - * user may have active. - * - * @param {goog.dom.DomHelper} domHelper DOM helper. - * @constructor - * @extends {goog.Disposable} - */ -goog.dom.a11y.Announcer = function(domHelper) { - goog.base(this); - - /** - * @type {goog.dom.DomHelper} - * @private - */ - this.domHelper_ = domHelper; - - /** - * Map of priority to live region elements to use for communicating updates. - * Elements are created on demand. - * @type {Object.<goog.dom.a11y.LivePriority, Element>} - * @private - */ - this.liveRegions_ = {}; -}; -goog.inherits(goog.dom.a11y.Announcer, goog.Disposable); - - -/** @override */ -goog.dom.a11y.Announcer.prototype.disposeInternal = function() { - goog.object.forEach( - this.liveRegions_, this.domHelper_.removeNode, this.domHelper_); - this.liveRegions_ = null; - this.domHelper_ = null; - goog.base(this, 'disposeInternal'); -}; - - -/** - * Announce a message to be read by any assistive technologies the user may - * have active. - * @param {string} message The message to announce to screen readers. - * @param {goog.dom.a11y.LivePriority=} opt_priority The priority of the - * message. Defaults to POLITE. - */ -goog.dom.a11y.Announcer.prototype.say = function(message, opt_priority) { - goog.dom.setTextContent(this.getLiveRegion_( - opt_priority || goog.dom.a11y.LivePriority.POLITE), message); -}; - - -/** - * Returns an aria-live region that can be used to communicate announcements. - * @param {goog.dom.a11y.LivePriority} priority The required priority. - * @return {Element} A live region of the requested priority. - * @private - */ -goog.dom.a11y.Announcer.prototype.getLiveRegion_ = function(priority) { - if (this.liveRegions_[priority]) { - return this.liveRegions_[priority]; - } - var liveRegion; - liveRegion = this.domHelper_.createElement('div'); - liveRegion.style.position = 'absolute'; - liveRegion.style.top = '-1000px'; - goog.dom.a11y.setState(liveRegion, 'live', priority); - goog.dom.a11y.setState(liveRegion, 'atomic', 'true'); - this.domHelper_.getDocument().body.appendChild(liveRegion); - this.liveRegions_[priority] = liveRegion; - return liveRegion; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base deleted file mode 100644 index 9d7daba..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base +++ /dev/null @@ -1,140 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: attila@google.com (Attila Bodis) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Closure Unit Tests - goog.dom.a11y</title> - <script src="../base.js"></script> - <script> - goog.require('goog.dom'); - goog.require('goog.dom.a11y'); - goog.require('goog.dom.a11y.Announcer'); - goog.require('goog.dom.a11y.LivePriority'); - goog.require('goog.dom.a11y.Role'); - goog.require('goog.dom.a11y.State'); - goog.require('goog.dom.iframe'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); - </script> -</head> -<body> - <div id="sandbox"></div> - <script> - var sandbox = goog.dom.getElement('sandbox'); - var someDiv; - var someSpan; - - function setUp() { - someDiv = goog.dom.createDom('div', {id: 'someDiv'}, 'DIV'); - someSpan = goog.dom.createDom('span', {id: 'someSpan'}, 'SPAN'); - sandbox.appendChild(someDiv); - someDiv.appendChild(someSpan); - } - - function tearDown() { - sandbox.innerHTML = ''; - someDiv = null; - someSpan = null; - } - - function testGetSetRole() { - assertEquals('someDiv\'s role should be the empty string', - '', goog.dom.a11y.getRole(someDiv)); - assertEquals('someSpan\'s role should be the empty string', - '', goog.dom.a11y.getRole(someSpan)); - - goog.dom.a11y.setRole(someDiv, goog.dom.a11y.Role.MENU); - goog.dom.a11y.setRole(someSpan, goog.dom.a11y.Role.MENU_ITEM); - - assertEquals('someDiv\'s role should be MENU', - goog.dom.a11y.Role.MENU, goog.dom.a11y.getRole(someDiv)); - assertEquals('someSpan\'s role should be MENU_ITEM', - goog.dom.a11y.Role.MENU_ITEM, goog.dom.a11y.getRole(someSpan)); - } - - function testGetSetState() { - assertEquals('someDiv\'s state should be the empty string', - '', goog.dom.a11y.getState(someDiv)); - - goog.dom.a11y.setState(someDiv, goog.dom.a11y.State.LABELLEDBY, - 'someSpan'); - - assertEquals( - 'someDiv\'s labelledby state should be "someSpan"', - 'someSpan', - goog.dom.a11y.getState(someDiv, goog.dom.a11y.State.LABELLEDBY)); - } - - function testGetSetActiveDescendant() { - goog.dom.a11y.setActiveDescendant(someDiv, null); - assertNull('someDiv\'s activedescendant should be null', - goog.dom.a11y.getActiveDescendant(someDiv)); - - goog.dom.a11y.setActiveDescendant(someDiv, someSpan); - - assertEquals( - 'someDiv\'s active descendant should be "someSpan"', - someSpan, - goog.dom.a11y.getActiveDescendant(someDiv)); - } - - function testAnnouncerAndDispose() { - var text = 'test content'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text); - checkLiveRegionContains(text, 'polite'); - goog.dispose(announcer); - } - - function testAnnouncerTwice() { - var text = 'test content1'; - var text2 = 'test content2'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text); - announcer.say(text2); - checkLiveRegionContains(text2, 'polite'); - goog.dispose(announcer); - } - - function testAnnouncerAssertive() { - var text = 'test content'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text, goog.dom.a11y.LivePriority.ASSERTIVE); - checkLiveRegionContains(text, 'assertive'); - goog.dispose(announcer); - } - - function testAnnouncerInIframe() { - var text = 'test content'; - var frame = goog.dom.iframe.createWithContent(sandbox); - var helper = goog.dom.getDomHelper( - goog.dom.getFrameContentDocument(frame).body); - var announcer = new goog.dom.a11y.Announcer(helper); - announcer.say(text, 'polite', helper); - checkLiveRegionContains(text, 'polite', helper); - goog.dispose(announcer); - } - - function checkLiveRegionContains(text, priority, opt_domHelper) { - var dom = opt_domHelper || goog.dom.getDomHelper(); - var divs = dom.getElementsByTagNameAndClass('div', null); - var liveRegions = []; - goog.array.forEach(divs, function(div) { - if (goog.dom.a11y.getState(div, 'live') == priority) { - liveRegions.push(div); - } - }); - assertEquals(1, liveRegions.length); - assertEquals(text, goog.dom.getTextContent(liveRegions[0])); - } - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base deleted file mode 100644 index 58d8c74..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with ranges comprised of multiple - * sub-ranges. - * - * @author robbyw@google.com (Robby Walker) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.AbstractMultiRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); - - - -/** - * Creates a new multi range with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractRange} - */ -goog.dom.AbstractMultiRange = function() { -}; -goog.inherits(goog.dom.AbstractMultiRange, goog.dom.AbstractRange); - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.containsRange = function( - otherRange, opt_allowPartial) { - // TODO(user): This will incorrectly return false if two (or more) adjacent - // elements are both in the control range, and are also in the text range - // being compared to. - var ranges = this.getTextRanges(); - var otherRanges = otherRange.getTextRanges(); - - var fn = opt_allowPartial ? goog.array.some : goog.array.every; - return fn(otherRanges, function(otherRange) { - return goog.array.some(ranges, function(range) { - return range.containsRange(otherRange, opt_allowPartial); - }); - }); -}; - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.insertNode = function(node, before) { - if (before) { - goog.dom.insertSiblingBefore(node, this.getStartNode()); - } else { - goog.dom.insertSiblingAfter(node, this.getEndNode()); - } - return node; -}; - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.surroundWithNodes = function(startNode, - endNode) { - this.insertNode(startNode, true); - this.insertNode(endNode, false); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base deleted file mode 100644 index d3e2c89..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base +++ /dev/null @@ -1,514 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Interface definitions for working with ranges - * in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.AbstractRange'); -goog.provide('goog.dom.RangeIterator'); -goog.provide('goog.dom.RangeType'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.SavedCaretRange'); -goog.require('goog.dom.TagIterator'); -goog.require('goog.userAgent'); - - -/** - * Types of ranges. - * @enum {string} - */ -goog.dom.RangeType = { - TEXT: 'text', - CONTROL: 'control', - MULTI: 'mutli' -}; - - - -/** - * Creates a new selection with no properties. Do not use this constructor - - * use one of the goog.dom.Range.from* methods instead. - * @constructor - */ -goog.dom.AbstractRange = function() { -}; - - -/** - * Gets the browser native selection object from the given window. - * @param {Window} win The window to get the selection object from. - * @return {Object} The browser native selection object, or null if it could - * not be retrieved. - */ -goog.dom.AbstractRange.getBrowserSelectionForWindow = function(win) { - if (win.getSelection) { - // W3C - return win.getSelection(); - } else { - // IE - var doc = win.document; - var sel = doc.selection; - if (sel) { - // IE has a bug where it sometimes returns a selection from the wrong - // document. Catching these cases now helps us avoid problems later. - try { - var range = sel.createRange(); - // Only TextRanges have a parentElement method. - if (range.parentElement) { - if (range.parentElement().document != doc) { - return null; - } - } else if (!range.length || range.item(0).document != doc) { - // For ControlRanges, check that the range has items, and that - // the first item in the range is in the correct document. - return null; - } - } catch (e) { - // If the selection is in the wrong document, and the wrong document is - // in a different domain, IE will throw an exception. - return null; - } - // TODO(user|robbyw) Sometimes IE 6 returns a selection instance - // when there is no selection. This object has a 'type' property equals - // to 'None' and a typeDetail property bound to undefined. Ideally this - // function should not return this instance. - return sel; - } - return null; - } -}; - - -/** - * Tests if the given Object is a controlRange. - * @param {Object} range The range object to test. - * @return {boolean} Whether the given Object is a controlRange. - */ -goog.dom.AbstractRange.isNativeControlRange = function(range) { - // For now, tests for presence of a control range function. - return !!range && !!range.addElement; -}; - - -/** - * @return {goog.dom.AbstractRange} A clone of this range. - */ -goog.dom.AbstractRange.prototype.clone = goog.abstractMethod; - - -/** - * @return {goog.dom.RangeType} The type of range represented by this object. - */ -goog.dom.AbstractRange.prototype.getType = goog.abstractMethod; - - -/** - * @return {Range|TextRange} The native browser range object. - */ -goog.dom.AbstractRange.prototype.getBrowserRangeObject = goog.abstractMethod; - - -/** - * Sets the native browser range object, overwriting any state this range was - * storing. - * @param {Range|TextRange} nativeRange The native browser range object. - * @return {boolean} Whether the given range was accepted. If not, the caller - * will need to call goog.dom.Range.createFromBrowserRange to create a new - * range object. - */ -goog.dom.AbstractRange.prototype.setBrowserRangeObject = function(nativeRange) { - return false; -}; - - -/** - * @return {number} The number of text ranges in this range. - */ -goog.dom.AbstractRange.prototype.getTextRangeCount = goog.abstractMethod; - - -/** - * Get the i-th text range in this range. The behavior is undefined if - * i >= getTextRangeCount or i < 0. - * @param {number} i The range number to retrieve. - * @return {goog.dom.TextRange} The i-th text range. - */ -goog.dom.AbstractRange.prototype.getTextRange = goog.abstractMethod; - - -/** - * Gets an array of all text ranges this range is comprised of. For non-multi - * ranges, returns a single element array containing this. - * @return {Array.<goog.dom.TextRange>} Array of text ranges. - */ -goog.dom.AbstractRange.prototype.getTextRanges = function() { - var output = []; - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - output.push(this.getTextRange(i)); - } - return output; -}; - - -/** - * @return {Node} The deepest node that contains the entire range. - */ -goog.dom.AbstractRange.prototype.getContainer = goog.abstractMethod; - - -/** - * Returns the deepest element in the tree that contains the entire range. - * @return {Element} The deepest element that contains the entire range. - */ -goog.dom.AbstractRange.prototype.getContainerElement = function() { - var node = this.getContainer(); - return /** @type {Element} */ ( - node.nodeType == goog.dom.NodeType.ELEMENT ? node : node.parentNode); -}; - - -/** - * @return {Node} The element or text node the range starts in. For text - * ranges, the range comprises all text between the start and end position. - * For other types of range, start and end give bounds of the range but - * do not imply all nodes in those bounds are selected. - */ -goog.dom.AbstractRange.prototype.getStartNode = goog.abstractMethod; - - -/** - * @return {number} The offset into the node the range starts in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getStartOffset = goog.abstractMethod; - - -/** - * @return {Node} The element or text node the range ends in. - */ -goog.dom.AbstractRange.prototype.getEndNode = goog.abstractMethod; - - -/** - * @return {number} The offset into the node the range ends in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getEndOffset = goog.abstractMethod; - - -/** - * @return {Node} The element or text node the range is anchored at. - */ -goog.dom.AbstractRange.prototype.getAnchorNode = function() { - return this.isReversed() ? this.getEndNode() : this.getStartNode(); -}; - - -/** - * @return {number} The offset into the node the range is anchored at. For - * text nodes, this is an offset into the node value. For elements, this - * is an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getAnchorOffset = function() { - return this.isReversed() ? this.getEndOffset() : this.getStartOffset(); -}; - - -/** - * @return {Node} The element or text node the range is focused at - i.e. where - * the cursor is. - */ -goog.dom.AbstractRange.prototype.getFocusNode = function() { - return this.isReversed() ? this.getStartNode() : this.getEndNode(); -}; - - -/** - * @return {number} The offset into the node the range is focused at - i.e. - * where the cursor is. For text nodes, this is an offset into the node - * value. For elements, this is an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getFocusOffset = function() { - return this.isReversed() ? this.getStartOffset() : this.getEndOffset(); -}; - - -/** - * @return {boolean} Whether the selection is reversed. - */ -goog.dom.AbstractRange.prototype.isReversed = function() { - return false; -}; - - -/** - * @return {Document} The document this selection is a part of. - */ -goog.dom.AbstractRange.prototype.getDocument = function() { - // Using start node in IE was crashing the browser in some cases so use - // getContainer for that browser. It's also faster for IE, but still slower - // than start node for other browsers so we continue to use getStartNode when - // it is not problematic. See bug 1687309. - return goog.dom.getOwnerDocument(goog.userAgent.IE ? - this.getContainer() : this.getStartNode()); -}; - - -/** - * @return {Window} The window this selection is a part of. - */ -goog.dom.AbstractRange.prototype.getWindow = function() { - return goog.dom.getWindow(this.getDocument()); -}; - - -/** - * Tests if this range contains the given range. - * @param {goog.dom.AbstractRange} range The range to test. - * @param {boolean=} opt_allowPartial If true, the range can be partially - * contained in the selection, otherwise the range must be entirely - * contained. - * @return {boolean} Whether this range contains the given range. - */ -goog.dom.AbstractRange.prototype.containsRange = goog.abstractMethod; - - -/** - * Tests if this range contains the given node. - * @param {Node} node The node to test for. - * @param {boolean=} opt_allowPartial If not set or false, the node must be - * entirely contained in the selection for this function to return true. - * @return {boolean} Whether this range contains the given node. - */ -goog.dom.AbstractRange.prototype.containsNode = function(node, - opt_allowPartial) { - return this.containsRange(goog.dom.Range.createFromNodeContents(node), - opt_allowPartial); -}; - - -/** - * Tests whether this range is valid (i.e. whether its endpoints are still in - * the document). A range becomes invalid when, after this object was created, - * either one or both of its endpoints are removed from the document. Use of - * an invalid range can lead to runtime errors, particularly in IE. - * @return {boolean} Whether the range is valid. - */ -goog.dom.AbstractRange.prototype.isRangeInDocument = goog.abstractMethod; - - -/** - * @return {boolean} Whether the range is collapsed. - */ -goog.dom.AbstractRange.prototype.isCollapsed = goog.abstractMethod; - - -/** - * @return {string} The text content of the range. - */ -goog.dom.AbstractRange.prototype.getText = goog.abstractMethod; - - -/** - * Returns the HTML fragment this range selects. This is slow on all browsers. - * The HTML fragment may not be valid HTML, for instance if the user selects - * from a to b inclusively in the following html: - * - * >div<a>/div<b - * - * This method will return - * - * a</div>b - * - * If you need valid HTML, use {@link #getValidHtml} instead. - * - * @return {string} HTML fragment of the range, does not include context - * containing elements. - */ -goog.dom.AbstractRange.prototype.getHtmlFragment = goog.abstractMethod; - - -/** - * Returns valid HTML for this range. This is fast on IE, and semi-fast on - * other browsers. - * @return {string} Valid HTML of the range, including context containing - * elements. - */ -goog.dom.AbstractRange.prototype.getValidHtml = goog.abstractMethod; - - -/** - * Returns pastable HTML for this range. This guarantees that any child items - * that must have specific ancestors will have them, for instance all TDs will - * be contained in a TR in a TBODY in a TABLE and all LIs will be contained in - * a UL or OL as appropriate. This is semi-fast on all browsers. - * @return {string} Pastable HTML of the range, including context containing - * elements. - */ -goog.dom.AbstractRange.prototype.getPastableHtml = goog.abstractMethod; - - -/** - * Returns a RangeIterator over the contents of the range. Regardless of the - * direction of the range, the iterator will move in document order. - * @param {boolean=} opt_keys Unused for this iterator. - * @return {goog.dom.RangeIterator} An iterator over tags in the range. - */ -goog.dom.AbstractRange.prototype.__iterator__ = goog.abstractMethod; - - -// RANGE ACTIONS - - -/** - * Sets this range as the selection in its window. - */ -goog.dom.AbstractRange.prototype.select = goog.abstractMethod; - - -/** - * Removes the contents of the range from the document. - */ -goog.dom.AbstractRange.prototype.removeContents = goog.abstractMethod; - - -/** - * Inserts a node before (or after) the range. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Node} node The node to insert. - * @param {boolean} before True to insert before, false to insert after. - * @return {Node} The node added to the document. This may be different - * than the node parameter because on IE we have to clone it. - */ -goog.dom.AbstractRange.prototype.insertNode = goog.abstractMethod; - - -/** - * Replaces the range contents with (possibly a copy of) the given node. The - * range may be disrupted beyond recovery because of the way this splits nodes. - * @param {Node} node The node to insert. - * @return {Node} The node added to the document. This may be different - * than the node parameter because on IE we have to clone it. - */ -goog.dom.AbstractRange.prototype.replaceContentsWithNode = function(node) { - if (!this.isCollapsed()) { - this.removeContents(); - } - - return this.insertNode(node, true); -}; - - -/** - * Surrounds this range with the two given nodes. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Element} startNode The node to insert at the start. - * @param {Element} endNode The node to insert at the end. - */ -goog.dom.AbstractRange.prototype.surroundWithNodes = goog.abstractMethod; - - -// SAVE/RESTORE - - -/** - * Saves the range so that if the start and end nodes are left alone, it can - * be restored. - * @return {goog.dom.SavedRange} A range representation that can be restored - * as long as the endpoint nodes of the selection are not modified. - */ -goog.dom.AbstractRange.prototype.saveUsingDom = goog.abstractMethod; - - -/** - * Saves the range using HTML carets. As long as the carets remained in the - * HTML, the range can be restored...even when the HTML is copied across - * documents. - * @return {goog.dom.SavedCaretRange?} A range representation that can be - * restored as long as carets are not removed. Returns null if carets - * could not be created. - */ -goog.dom.AbstractRange.prototype.saveUsingCarets = function() { - return (this.getStartNode() && this.getEndNode()) ? - new goog.dom.SavedCaretRange(this) : null; -}; - - -// RANGE MODIFICATION - - -/** - * Collapses the range to one of its boundary points. - * @param {boolean} toAnchor Whether to collapse to the anchor of the range. - */ -goog.dom.AbstractRange.prototype.collapse = goog.abstractMethod; - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * @param {Node} node The node to start traversal at. When null, creates an - * empty iterator. - * @param {boolean=} opt_reverse Whether to traverse nodes in reverse. - * @constructor - * @extends {goog.dom.TagIterator} - */ -goog.dom.RangeIterator = function(node, opt_reverse) { - goog.dom.TagIterator.call(this, node, opt_reverse, true); -}; -goog.inherits(goog.dom.RangeIterator, goog.dom.TagIterator); - - -/** - * @return {number} The offset into the current node, or -1 if the current node - * is not a text node. - */ -goog.dom.RangeIterator.prototype.getStartTextOffset = goog.abstractMethod; - - -/** - * @return {number} The end offset into the current node, or -1 if the current - * node is not a text node. - */ -goog.dom.RangeIterator.prototype.getEndTextOffset = goog.abstractMethod; - - -/** - * @return {Node} node The iterator's start node. - */ -goog.dom.RangeIterator.prototype.getStartNode = goog.abstractMethod; - - -/** - * @return {Node} The iterator's end node. - */ -goog.dom.RangeIterator.prototype.getEndNode = goog.abstractMethod; - - -/** - * @return {boolean} Whether a call to next will fail. - */ -goog.dom.RangeIterator.prototype.isLast = goog.abstractMethod; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base deleted file mode 100644 index 8b8a409..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base +++ /dev/null @@ -1,73 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.abstractrange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.AbstractRange'); - goog.require('goog.dom.Range'); - - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<iframe src="javascript:"<html><body contenteditable>asdf"" - id="a"> -</iframe> -<iframe src="javascript:"<html><body contenteditable>asdf"" - id="b"> -</iframe> -<iframe src="javascript:"<html><body contenteditable><img>"" - id="c"> -</iframe> -<script> - function testCorrectDocument() { - var a = goog.dom.getElement('a').contentWindow; - var b = goog.dom.getElement('b').contentWindow; - - a.document.body.focus(); - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(a); - assertNotNull('Selection must not be null', selection); - var range = goog.dom.Range.createFromBrowserSelection(selection); - assertEquals('getBrowserSelectionForWindow must return selection in the ' + - 'correct document', a.document, range.getDocument()); - - // This is intended to trip up Internet Explorer -- - // see http://b/2048934 - b.document.body.focus(); - selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(a); - // Some (non-IE) browsers keep a separate selection state for each document - // in the same browser window. That's fine, as long as the selection object - // requested from the window object is correctly associated with that - // window's document. - if (selection) { - range = goog.dom.Range.createFromBrowserSelection(selection); - assertEquals('getBrowserSelectionForWindow must return selection in ' + - 'the correct document', a.document, range.getDocument()); - } else { - assertNull(selection); - } - } - - function testSelectionIsControlRange() { - var c = goog.dom.getElement('c').contentWindow; - // Only IE supports control ranges - if (c.document.body.createControlRange) { - var controlRange = c.document.body.createControlRange(); - controlRange.add(c.document.getElementsByTagName('img')[0]); - controlRange.select(); - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(c); - assertNotNull('Selection must not be null', selection); - } - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base deleted file mode 100644 index 1f5c7fc..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Methods for annotating occurrences of query terms in text or - * in a DOM tree. Adapted from Gmail code. - * - */ - -goog.provide('goog.dom.annotate'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.string'); - - -/** - * Calls {@code annotateFn} for each occurrence of a search term in text nodes - * under {@code node}. Returns the number of hits. - * - * @param {Node} node A DOM node. - * @param {Array} terms An array of [searchTerm, matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn A function that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*=} opt_ignoreCase Whether to ignore the case of the query - * terms when looking for matches. - * @param {Array.<string>=} opt_classesToSkip Nodes with one of these CSS class - * names (and its descendants) will be skipped. - * @param {number=} opt_maxMs Number of milliseconds after which this function, - * if still annotating, should stop and return. - * - * @return {boolean} Whether any terms were annotated. - */ -goog.dom.annotate.annotateTerms = function(node, terms, annotateFn, - opt_ignoreCase, - opt_classesToSkip, - opt_maxMs) { - var stopTime = opt_maxMs > 0 ? goog.now() + opt_maxMs : 0; - - return goog.dom.annotate.annotateTermsInNode_( - node, terms, annotateFn, opt_ignoreCase, opt_classesToSkip || [], - stopTime, 0); -}; - - -/** - * The maximum recursion depth allowed. Any DOM nodes deeper than this are - * ignored. - * @type {number} - * @private - */ -goog.dom.annotate.MAX_RECURSION_ = 200; - - -/** - * The node types whose descendants should not be affected by annotation. - * @type {Array} - * @private - */ -goog.dom.annotate.NODES_TO_SKIP_ = ['SCRIPT', 'STYLE', 'TEXTAREA']; - - -/** - * Recursive helper function. - * - * @param {Node} node A DOM node. - * @param {Array} terms An array of [searchTerm, matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn function(number, string) : string A function - * that takes : - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*} ignoreCase Whether to ignore the case of the query terms - * when looking for matches. - * @param {Array.<string>} classesToSkip Nodes with one of these CSS class - * names will be skipped (as will their descendants). - * @param {number} stopTime Deadline for annotation operation (ignored if 0). - * @param {number} recursionLevel How deep this recursive call is; pass the - * value 0 in the initial call. - * @return {boolean} Whether any terms were annotated. - * @private - */ -goog.dom.annotate.annotateTermsInNode_ = - function(node, terms, annotateFn, ignoreCase, classesToSkip, - stopTime, recursionLevel) { - if ((stopTime > 0 && goog.now() >= stopTime) || - recursionLevel > goog.dom.annotate.MAX_RECURSION_) { - return false; - } - - var annotated = false; - - if (node.nodeType == goog.dom.NodeType.TEXT) { - var html = goog.dom.annotate.helpAnnotateText_(node.nodeValue, terms, - annotateFn, ignoreCase); - if (html != null) { - // Replace the text with the annotated html. First we put the html into - // a temporary node, to get its DOM structure. To avoid adding a wrapper - // element as a side effect, we'll only actually use the temporary node's - // children. - var tempNode = goog.dom.getOwnerDocument(node).createElement('SPAN'); - tempNode.innerHTML = html; - - var parentNode = node.parentNode; - var nodeToInsert; - while ((nodeToInsert = tempNode.firstChild) != null) { - // Each parentNode.insertBefore call removes the inserted node from - // tempNode's list of children. - parentNode.insertBefore(nodeToInsert, node); - } - - parentNode.removeChild(node); - annotated = true; - } - } else if (node.hasChildNodes() && - !goog.array.contains(goog.dom.annotate.NODES_TO_SKIP_, - node.tagName)) { - var classes = node.className.split(/\s+/); - var skip = goog.array.some(classes, function(className) { - return goog.array.contains(classesToSkip, className); - }); - - if (!skip) { - ++recursionLevel; - var curNode = node.firstChild; - var numTermsAnnotated = 0; - while (curNode) { - var nextNode = curNode.nextSibling; - var curNodeAnnotated = goog.dom.annotate.annotateTermsInNode_( - curNode, terms, annotateFn, ignoreCase, classesToSkip, - stopTime, recursionLevel); - annotated = annotated || curNodeAnnotated; - curNode = nextNode; - } - } - } - - return annotated; -}; - - -/** - * Regular expression that matches non-word characters. - * - * Performance note: Testing a one-character string using this regex is as fast - * as the equivalent string test ("a-zA-Z0-9_".indexOf(c) < 0), give or take a - * few percent. (The regex is about 5% faster in IE 6 and about 4% slower in - * Firefox 1.5.) If performance becomes critical, it may be better to convert - * the character to a numerical char code and check whether it falls in the - * word character ranges. A quick test suggests that could be 33% faster. - * - * @type {RegExp} - * @private - */ -goog.dom.annotate.NONWORD_RE_ = /\W/; - - -/** - * Annotates occurrences of query terms in plain text. This process consists of - * identifying all occurrences of all query terms, calling a provided function - * to get the appropriate replacement HTML for each occurrence, and - * HTML-escaping all the text. - * - * @param {string} text The plain text to be searched. - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn {function(number, string) : string} A function - * that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*=} opt_ignoreCase Whether to ignore the case of the query - * terms when looking for matches. - * @return {?string} The HTML equivalent of {@code text} with terms - * annotated, or null if the text did not contain any of the terms. - */ -goog.dom.annotate.annotateText = function(text, terms, annotateFn, - opt_ignoreCase) { - if (opt_ignoreCase) { - terms = goog.dom.annotate.lowercaseTerms_(terms); - } - return goog.dom.annotate.helpAnnotateText_(text, terms, annotateFn, - opt_ignoreCase); -}; - - -/** - * Annotates occurrences of query terms in plain text. This process consists of - * identifying all occurrences of all query terms, calling a provided function - * to get the appropriate replacement HTML for each occurrence, and - * HTML-escaping all the text. - * - * @param {string} text The plain text to be searched. - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * If {@code ignoreCase} is true, each search term must already be lowercase. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn {function(number, string) : string} A function - * that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*} ignoreCase Whether to ignore the case of the query terms - * when looking for matches. - * @return {?string} The HTML equivalent of {@code text} with terms - * annotated, or null if the text did not contain any of the terms. - * @private - */ -goog.dom.annotate.helpAnnotateText_ = function(text, terms, annotateFn, - ignoreCase) { - var hit = false; - var resultHtml = null; - var textToSearch = ignoreCase ? text.toLowerCase() : text; - var textLen = textToSearch.length; - var numTerms = terms.length; - - // Each element will be an array of hit positions for the term. - var termHits = new Array(numTerms); - - // First collect all the hits into allHits. - for (var i = 0; i < numTerms; i++) { - var term = terms[i]; - var hits = []; - var termText = term[0]; - if (termText != '') { - var matchWholeWordOnly = term[1]; - var termLen = termText.length; - var pos = 0; - // Find each hit for term t and append to termHits. - while (pos < textLen) { - var hitPos = textToSearch.indexOf(termText, pos); - if (hitPos == -1) { - break; - } else { - var prevCharPos = hitPos - 1; - var nextCharPos = hitPos + termLen; - if (!matchWholeWordOnly || - ((prevCharPos < 0 || - goog.dom.annotate.NONWORD_RE_.test( - textToSearch.charAt(prevCharPos))) && - (nextCharPos >= textLen || - goog.dom.annotate.NONWORD_RE_.test( - textToSearch.charAt(nextCharPos))))) { - hits.push(hitPos); - hit = true; - } - pos = hitPos + termLen; - } - } - } - termHits[i] = hits; - } - - if (hit) { - var html = []; - var pos = 0; - - while (true) { - // First determine which of the n terms is the next hit. - var termIndexOfNextHit; - var posOfNextHit = -1; - - for (var i = 0; i < numTerms; i++) { - var hits = termHits[i]; - // pull off the position of the next hit of term t - // (it's always the first in the array because we're shifting - // hits off the front of the array as we process them) - // this is the next candidate to consider for the next overall hit - if (!goog.array.isEmpty(hits)) { - var hitPos = hits[0]; - - // Discard any hits embedded in the previous hit. - while (hitPos >= 0 && hitPos < pos) { - hits.shift(); - hitPos = goog.array.isEmpty(hits) ? -1 : hits[0]; - } - - if (hitPos >= 0 && (posOfNextHit < 0 || hitPos < posOfNextHit)) { - termIndexOfNextHit = i; - posOfNextHit = hitPos; - } - } - } - - // Quit if there are no more hits. - if (posOfNextHit < 0) break; - - // Remove the next hit from our hit list. - termHits[termIndexOfNextHit].shift(); - - // Append everything from the end of the last hit up to this one. - html.push(goog.string.htmlEscape(text.substr(pos, posOfNextHit - pos))); - - // Append the annotated term. - var termLen = terms[termIndexOfNextHit][0].length; - var termHtml = goog.string.htmlEscape(text.substr(posOfNextHit, termLen)); - html.push(annotateFn(termIndexOfNextHit, termHtml)); - - pos = posOfNextHit + termLen; - } - - // Append everything after the last hit. - html.push(goog.string.htmlEscape(text.substr(pos))); - return html.join(''); - } else { - return null; - } -}; - - -/** - * Converts terms to lowercase. - * - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * @return {Array} An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * @private - */ -goog.dom.annotate.lowercaseTerms_ = function(terms) { - var lowercaseTerms = []; - for (var i = 0; i < terms.length; ++i) { - var term = terms[i]; - lowercaseTerms[i] = [term[0].toLowerCase(), term[1]]; - } - return lowercaseTerms; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base deleted file mode 100644 index c666494..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base +++ /dev/null @@ -1,187 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.annotate</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.annotate'); - goog.require('goog.testing.jsunit'); -</script> -<style type="text/css"> - .c0 {background-color:#ff0} - .c1 {background-color:#0ff} -</style> -</head> -<body> -<span id="p">Tom & Jerry</span> -<table> - <tr id="q"> - <td>This <b>little</b> piggy</td> - <td class="s">That little <i>pig</i>gy</td> - </tr> - <tr id="r"> - <td>This <b>little</b> piggy</td> - <td class="s">That little <i>pig</i>gy</td> - </tr> -</table> - -<div id="o"> -<object classid="clsid:SAMPLE-UNRECOGNIZED-ID" width="100" height="50"> - <param name="BorderStyle" value="1" /> - <param name="MousePointer" value="0" /> - <param name="Enabled" value="1" /> - <param name="Min" value="0" /> - <param name="Max" value="10" /> - Your browser cannot display this object. -</object> -</div> - -<script id="script">var variable;</script> -<style id="style" type="text/css">.orange{color:orange}</style> -<span id="comment"><!-- note --></span> - -<script> - var $ = goog.dom.getElement; - - var TEXT = 'This little piggy cried "Wee! Wee! Wee!" all the way home.'; - - function doAnnotation(termIndex, termHtml) { - return '<span class="c' + termIndex + '">' + termHtml + '</span>'; - } - - // goog.dom.annotate.annotateText tests - - function testAnnotateText() { - var terms = [['pig', true]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals(null, html); - - terms = [['pig', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little <span class="c0">pig</span>gy cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - - terms = [[' piggy ', true]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals(null, html); - - terms = [[' piggy ', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little<span class="c0"> piggy </span>cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - - terms = [['goose', true], ['piggy', true]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little <span class="c1">piggy</span> cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - } - - function testAnnotateTextHtmlEscaping() { - var terms = [['a', false]]; - var html = goog.dom.annotate.annotateText('&a', terms, doAnnotation) - assertEquals('&<span class="c0">a</span>', html); - - terms = [['a', false]]; - html = goog.dom.annotate.annotateText('a&', terms, doAnnotation) - assertEquals('<span class="c0">a</span>&', html); - - terms = [['&', false]]; - html = goog.dom.annotate.annotateText('&', terms, doAnnotation) - assertEquals('<span class="c0">&</span>', html); - } - - function testAnnotateTextIgnoreCase() { - var terms = [['wEe', true]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation, true); - assertEquals('This little piggy cried "<span class="c0">Wee</span>! ' + - '<span class="c0">Wee</span>! <span class="c0">Wee</span>!' + - '" all the way home.', html); - - terms = [['WEE!', true], ['HE', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation, true); - assertEquals('This little piggy cried "<span class="c0">Wee!</span> ' + - '<span class="c0">Wee!</span> <span class="c0">Wee!</span>' + - '" all t<span class="c1">he</span> way home.', html); - } - - function testAnnotateTextOverlappingTerms() { - var terms = [['tt', false], ['little', false]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This <span class="c1">little</span> piggy cried "Wee! ' + - 'Wee! Wee!" all the way home.', html); - } - - // goog.dom.annotate.annotateTerms tests - - function testAnnotateTerms() { - var terms = [['pig', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('p'), terms, doAnnotation)); - assertEquals('Tom & Jerry', $('p').innerHTML); - - terms = [['Tom', true]]; - assertTrue(goog.dom.annotate.annotateTerms($('p'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('p')); - assertEquals(1, spans.length); - assertEquals('Tom', spans[0].innerHTML); - assertEquals(' & Jerry', spans[0].nextSibling.nodeValue); - } - - function testAnnotateTermsInTable() { - var terms = [['pig', false]]; - assertTrue(goog.dom.annotate.annotateTerms($('q'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('q')); - assertEquals(2, spans.length); - assertEquals('pig', spans[0].innerHTML); - assertEquals('gy', spans[0].nextSibling.nodeValue); - assertEquals('pig', spans[1].innerHTML); - assertEquals('I', spans[1].parentNode.tagName); - } - - function testAnnotateTermsWithClassExclusions() { - var terms = [['pig', false]]; - var classesToIgnore = ['s']; - assertTrue(goog.dom.annotate.annotateTerms($('r'), terms, doAnnotation, - false, classesToIgnore)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('r')); - assertEquals(1, spans.length); - assertEquals('pig', spans[0].innerHTML); - assertEquals('gy', spans[0].nextSibling.nodeValue); - } - - function testAnnotateTermsInObject() { - var terms = [['object', true]]; - assertTrue(goog.dom.annotate.annotateTerms($('o'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('o')); - assertEquals(1, spans.length); - assertEquals('object', spans[0].innerHTML); - } - - function testAnnotateTermsInScript() { - var terms = [['variable', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('script'), terms, - doAnnotation)); - } - - function testAnnotateTermsInStyle() { - var terms = [['color', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('style'), terms, - doAnnotation)); - } - - function testAnnotateTermsInHtmlComment() { - var terms = [['note', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('comment'), terms, - doAnnotation)); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base deleted file mode 100644 index ea921a1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Browser capability checks for the dom package. - * - */ - - -goog.provide('goog.dom.BrowserFeature'); - -goog.require('goog.userAgent'); - - -/** - * Enum of browser capabilities. - * @enum {boolean} - */ -goog.dom.BrowserFeature = { - /** - * Whether attributes 'name' and 'type' can be added to an element after it's - * created. False in Internet Explorer prior to version 9. - */ - CAN_ADD_NAME_OR_TYPE_ATTRIBUTES: !goog.userAgent.IE || - goog.userAgent.isDocumentMode(9), - - /** - * Whether we can use element.children to access an element's Element - * children. Available since Gecko 1.9.1, IE 9. (IE<9 also includes comment - * nodes in the collection.) - */ - CAN_USE_CHILDREN_ATTRIBUTE: !goog.userAgent.GECKO && !goog.userAgent.IE || - goog.userAgent.IE && goog.userAgent.isDocumentMode(9) || - goog.userAgent.GECKO && goog.userAgent.isVersion('1.9.1'), - - /** - * Opera, Safari 3, and Internet Explorer 9 all support innerText but they - * include text nodes in script and style tags. Not document-mode-dependent. - */ - CAN_USE_INNER_TEXT: goog.userAgent.IE && !goog.userAgent.isVersion('9'), - - /** - * MSIE, Opera, and Safari>=4 support element.parentElement to access an - * element's parent if it is an Element. - */ - CAN_USE_PARENT_ELEMENT_PROPERTY: goog.userAgent.IE || goog.userAgent.OPERA || - goog.userAgent.WEBKIT, - - /** - * Whether NoScope elements need a scoped element written before them in - * innerHTML. - * MSDN: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx#1 - */ - INNER_HTML_NEEDS_SCOPED_ELEMENT: goog.userAgent.IE -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base deleted file mode 100644 index d1e7b14..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting classes. - * - */ - - -goog.provide('goog.dom.classes'); - -goog.require('goog.array'); - - -/** - * Sets the entire class name of an element. - * @param {Node} element DOM node to set class of. - * @param {string} className Class name(s) to apply to element. - */ -goog.dom.classes.set = function(element, className) { - element.className = className; -}; - - -/** - * Gets an array of class names on an element - * @param {Node} element DOM node to get class of. - * @return {Array} Class names on {@code element}. - */ -goog.dom.classes.get = function(element) { - var className = element.className; - // Some types of elements don't have a className in IE (e.g. iframes). - // Furthermore, in Firefox, className is not a string when the element is - // an SVG element. - return className && typeof className.split == 'function' ? - className.split(/\s+/) : []; -}; - - -/** - * Adds a class or classes to an element. Does not add multiples of class names. - * @param {Node} element DOM node to add class to. - * @param {...string} var_args Class names to add. - * @return {boolean} Whether class was added (or all classes were added). - */ -goog.dom.classes.add = function(element, var_args) { - var classes = goog.dom.classes.get(element); - var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.add_(classes, args); - element.className = classes.join(' '); - - return b; -}; - - -/** - * Removes a class or classes from an element. - * @param {Node} element DOM node to remove class from. - * @param {...string} var_args Class name(s) to remove. - * @return {boolean} Whether all classes in {@code var_args} were found and - * removed. - */ -goog.dom.classes.remove = function(element, var_args) { - var classes = goog.dom.classes.get(element); - var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.remove_(classes, args); - element.className = classes.join(' '); - - return b; -}; - - -/** - * Helper method for {@link goog.dom.classes.add} and - * {@link goog.dom.classes.addRemove}. Adds one or more classes to the supplied - * classes array. - * @param {Array.<string>} classes All class names for the element, will be - * updated to have the classes supplied in {@code args} added. - * @param {Array.<string>} args Class names to add. - * @return {boolean} Whether all classes in were added. - * @private - */ -goog.dom.classes.add_ = function(classes, args) { - var rv = 0; - for (var i = 0; i < args.length; i++) { - if (!goog.array.contains(classes, args[i])) { - classes.push(args[i]); - rv++; - } - } - return rv == args.length; -}; - - -/** - * Helper method for {@link goog.dom.classes.remove} and - * {@link goog.dom.classes.addRemove}. Removes one or more classes from the - * supplied classes array. - * @param {Array.<string>} classes All class names for the element, will be - * updated to have the classes supplied in {@code args} removed. - * @param {Array.<string>} args Class names to remove. - * @return {boolean} Whether all classes in were found and removed. - * @private - */ -goog.dom.classes.remove_ = function(classes, args) { - var rv = 0; - for (var i = 0; i < classes.length; i++) { - if (goog.array.contains(args, classes[i])) { - goog.array.splice(classes, i--, 1); - rv++; - } - } - return rv == args.length; -}; - - -/** - * Switches a class on an element from one to another without disturbing other - * classes. If the fromClass isn't removed, the toClass won't be added. - * @param {Node} element DOM node to swap classes on. - * @param {string} fromClass Class to remove. - * @param {string} toClass Class to add. - * @return {boolean} Whether classes were switched. - */ -goog.dom.classes.swap = function(element, fromClass, toClass) { - var classes = goog.dom.classes.get(element); - - var removed = false; - for (var i = 0; i < classes.length; i++) { - if (classes[i] == fromClass) { - goog.array.splice(classes, i--, 1); - removed = true; - } - } - - if (removed) { - classes.push(toClass); - element.className = classes.join(' '); - } - - return removed; -}; - - -/** - * Adds zero or more classes to an element and removes zero or more as a single - * operation. Unlike calling {@link goog.dom.classes.add} and - * {@link goog.dom.classes.remove} separately, this is more efficient as it only - * parses the class property once. - * - * If a class is in both the remove and add lists, it will be added. Thus, - * you can use this instead of {@link goog.dom.classes.swap} when you have - * more than two class names that you want to swap. - * - * @param {Node} element DOM node to swap classes on. - * @param {string|Array.<string>|null} classesToRemove Class or classes to - * remove, if null no classes are removed. - * @param {string|Array.<string>|null} classesToAdd Class or classes to add, if - * null no classes are added. - */ -goog.dom.classes.addRemove = function(element, classesToRemove, classesToAdd) { - var classes = goog.dom.classes.get(element); - if (goog.isString(classesToRemove)) { - goog.array.remove(classes, classesToRemove); - } else if (goog.isArray(classesToRemove)) { - goog.dom.classes.remove_(classes, classesToRemove); - } - - if (goog.isString(classesToAdd) && - !goog.array.contains(classes, classesToAdd)) { - classes.push(classesToAdd); - } else if (goog.isArray(classesToAdd)) { - goog.dom.classes.add_(classes, classesToAdd); - } - - element.className = classes.join(' '); -}; - - -/** - * Returns true if an element has a class. - * @param {Node} element DOM node to test. - * @param {string} className Class name to test for. - * @return {boolean} Whether element has the class. - */ -goog.dom.classes.has = function(element, className) { - return goog.array.contains(goog.dom.classes.get(element), className); -}; - - -/** - * Adds or removes a class depending on the enabled argument. - * @param {Node} element DOM node to add or remove the class on. - * @param {string} className Class name to add or remove. - * @param {boolean} enabled Whether to add or remove the class (true adds, - * false removes). - */ -goog.dom.classes.enable = function(element, className, enabled) { - if (enabled) { - goog.dom.classes.add(element, className); - } else { - goog.dom.classes.remove(element, className); - } -}; - - -/** - * Removes a class if an element has it, and adds it the element doesn't have - * it. Won't affect other classes on the node. - * @param {Node} element DOM node to toggle class on. - * @param {string} className Class to toggle. - * @return {boolean} True if class was added, false if it was removed - * (in other words, whether element has the class after this function has - * been called). - */ -goog.dom.classes.toggle = function(element, className) { - var add = !goog.dom.classes.has(element, className); - goog.dom.classes.enable(element, className, add); - return add; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base deleted file mode 100644 index 9368795..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base +++ /dev/null @@ -1,228 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.classes</title>= -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.classes'); - goog.require('goog.testing.jsunit'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <span id="span1" class="test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1"></span> - <span id="span6"></span> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - <p id="p3" class="someclass - otherclass"> - h - </p> - <iframe name="frame" src="../math/math_test.html"></iframe> - -<script> - - var $ = goog.dom.getElement; - var classes = goog.dom.classes; - - function testSetAddHasRemove() { - var el = $('p1'); - classes.set(el, 'someclass'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - - classes.set(el, 'otherclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have someclass', classes.has(el, 'someclass')); - - classes.add(el, 'wooclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - - classes.add(el, 'aclass', 'bclass', 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertTrue('Should have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertFalse('Should not have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'aclass', 'bclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertFalse('Should not have aclass', classes.has(el, 'aclass')); - assertFalse('Should not have bclass', classes.has(el, 'bclass')); - } - - function testSwap() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - - classes.swap(el, 'first', 'second'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertTrue('Should have second class', classes.has(el, 'second')); - - classes.swap(el, 'second', 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - } - - function testEnable() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', false); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', true); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testToggle() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testAddNotAddingMultiples() { - var el = $('span6'); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'b', 'b'); - assertEquals('a b', el.className); - } - - function testAddRemoveString() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, 'a', 'b'); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, null, 'c'); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, 'c', 'd'); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, 'd', null); - assertEquals('b', el.className); - } - - function testAddRemoveArray() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b']); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, [], ['c']); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, ['c'], ['d']); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, ['d'], []); - assertEquals('b', el.className); - } - - function testAddRemoveMultiple() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b', 'c', 'd']); - assertEquals('b c d', el.className); - - goog.dom.classes.addRemove(el, [], ['e', 'f']); - assertEquals('b c d e f', el.className); - - goog.dom.classes.addRemove(el, ['c', 'e'], []); - assertEquals('b d f', el.className); - - goog.dom.classes.addRemove(el, ['b'], ['g']); - assertEquals('d f g', el.className); - } - - function testHasWithNewlines() { - var el = $('p3'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - assertTrue('Should also have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have weirdclass', classes.has(el, 'weirdclass')); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base deleted file mode 100644 index 1bced30..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base +++ /dev/null @@ -1,511 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with IE control ranges. - * - * @author robbyw@google.com (Robby Walker) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.ControlRange'); -goog.provide('goog.dom.ControlRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractMultiRange'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagWalkType'); -goog.require('goog.dom.TextRange'); -goog.require('goog.iter.StopIteration'); -goog.require('goog.userAgent'); - - - -/** - * Create a new control selection with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractMultiRange} - */ -goog.dom.ControlRange = function() { -}; -goog.inherits(goog.dom.ControlRange, goog.dom.AbstractMultiRange); - - -/** - * Create a new range wrapper from the given browser range object. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Object} controlRange The browser range object. - * @return {goog.dom.ControlRange} A range wrapper object. - */ -goog.dom.ControlRange.createFromBrowserRange = function(controlRange) { - var range = new goog.dom.ControlRange(); - range.range_ = controlRange; - return range; -}; - - -/** - * Create a new range wrapper that selects the given element. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {...Element} var_args The element(s) to select. - * @return {goog.dom.ControlRange} A range wrapper object. - */ -goog.dom.ControlRange.createFromElements = function(var_args) { - var range = goog.dom.getOwnerDocument(arguments[0]).body.createControlRange(); - for (var i = 0, len = arguments.length; i < len; i++) { - range.addElement(arguments[i]); - } - return goog.dom.ControlRange.createFromBrowserRange(range); -}; - - -/** - * The IE control range obejct. - * @type {Object} - * @private - */ -goog.dom.ControlRange.prototype.range_ = null; - - -/** - * Cached list of elements. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRange.prototype.elements_ = null; - - -/** - * Cached sorted list of elements. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRange.prototype.sortedElements_ = null; - - -// Method implementations - - -/** - * Clear cached values. - * @private - */ -goog.dom.ControlRange.prototype.clearCachedValues_ = function() { - this.elements_ = null; - this.sortedElements_ = null; -}; - - -/** - * @return {goog.dom.ControlRange} A clone of this range. - */ -goog.dom.ControlRange.prototype.clone = function() { - return goog.dom.ControlRange.createFromElements.apply(this, - this.getElements()); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getType = function() { - return goog.dom.RangeType.CONTROL; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getBrowserRangeObject = function() { - return this.range_ || document.body.createControlRange(); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.setBrowserRangeObject = function(nativeRange) { - if (!goog.dom.AbstractRange.isNativeControlRange(nativeRange)) { - return false; - } - this.range_ = nativeRange; - return true; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getTextRangeCount = function() { - return this.range_ ? this.range_.length : 0; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getTextRange = function(i) { - return goog.dom.TextRange.createFromNodeContents(this.range_.item(i)); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getContainer = function() { - return goog.dom.findCommonAncestor.apply(null, this.getElements()); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getStartNode = function() { - return this.getSortedElements()[0]; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getStartOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getEndNode = function() { - var sorted = this.getSortedElements(); - var startsLast = /** @type {Node} */ (goog.array.peek(sorted)); - return /** @type {Node} */ (goog.array.find(sorted, function(el) { - return goog.dom.contains(el, startsLast); - })); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getEndOffset = function() { - return this.getEndNode().childNodes.length; -}; - - -// TODO(robbyw): Figure out how to unify getElements with TextRange API. -/** - * @return {Array.<Element>} Array of elements in the control range. - */ -goog.dom.ControlRange.prototype.getElements = function() { - if (!this.elements_) { - this.elements_ = []; - if (this.range_) { - for (var i = 0; i < this.range_.length; i++) { - this.elements_.push(this.range_.item(i)); - } - } - } - - return this.elements_; -}; - - -/** - * @return {Array.<Element>} Array of elements comprising the control range, - * sorted by document order. - */ -goog.dom.ControlRange.prototype.getSortedElements = function() { - if (!this.sortedElements_) { - this.sortedElements_ = this.getElements().concat(); - this.sortedElements_.sort(function(a, b) { - return a.sourceIndex - b.sourceIndex; - }); - } - - return this.sortedElements_; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.isRangeInDocument = function() { - var returnValue = false; - - try { - returnValue = goog.array.every(this.getElements(), function(element) { - // On IE, this throws an exception when the range is detached. - return goog.userAgent.IE ? - element.parentNode : - goog.dom.contains(element.ownerDocument.body, element); - }); - } catch (e) { - // IE sometimes throws Invalid Argument errors for detached elements. - // Note: trying to return a value from the above try block can cause IE - // to crash. It is necessary to use the local returnValue. - } - - return returnValue; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.isCollapsed = function() { - return !this.range_ || !this.range_.length; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getText = function() { - // TODO(robbyw): What about for table selections? Should those have text? - return ''; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getHtmlFragment = function() { - return goog.array.map(this.getSortedElements(), goog.dom.getOuterHtml). - join(''); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getValidHtml = function() { - return this.getHtmlFragment(); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getPastableHtml = - goog.dom.ControlRange.prototype.getValidHtml; - - -/** @override */ -goog.dom.ControlRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.ControlRangeIterator(this); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.ControlRange.prototype.select = function() { - if (this.range_) { - this.range_.select(); - } -}; - - -/** @override */ -goog.dom.ControlRange.prototype.removeContents = function() { - // TODO(robbyw): Test implementing with execCommand('Delete') - if (this.range_) { - var nodes = []; - for (var i = 0, len = this.range_.length; i < len; i++) { - nodes.push(this.range_.item(i)); - } - goog.array.forEach(nodes, goog.dom.removeNode); - - this.collapse(false); - } -}; - - -/** @override */ -goog.dom.ControlRange.prototype.replaceContentsWithNode = function(node) { - // Control selections have to have the node inserted before removing the - // selection contents because a collapsed control range doesn't have start or - // end nodes. - var result = this.insertNode(node, true); - - if (!this.isCollapsed()) { - this.removeContents(); - } - - return result; -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.ControlRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedControlRange_(this); -}; - - -// RANGE MODIFICATION - - -/** @override */ -goog.dom.ControlRange.prototype.collapse = function(toAnchor) { - // TODO(robbyw): Should this return a text range? If so, API needs to change. - this.range_ = null; - this.clearCachedValues_(); -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.ControlRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedControlRange_ = function(range) { - /** - * The element list. - * @type {Array.<Element>} - * @private - */ - this.elements_ = range.getElements(); -}; -goog.inherits(goog.dom.DomSavedControlRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.ControlRange} The restored range. - */ -goog.dom.DomSavedControlRange_.prototype.restoreInternal = function() { - var doc = this.elements_.length ? - goog.dom.getOwnerDocument(this.elements_[0]) : document; - var controlRange = doc.body.createControlRange(); - for (var i = 0, len = this.elements_.length; i < len; i++) { - controlRange.addElement(this.elements_[i]); - } - return goog.dom.ControlRange.createFromBrowserRange(controlRange); -}; - - -/** @override */ -goog.dom.DomSavedControlRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedControlRange_.superClass_.disposeInternal.call(this); - delete this.elements_; -}; - - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {goog.dom.ControlRange?} range The range to traverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.ControlRangeIterator = function(range) { - if (range) { - this.elements_ = range.getSortedElements(); - this.startNode_ = this.elements_.shift(); - this.endNode_ = /** @type {Node} */ (goog.array.peek(this.elements_)) || - this.startNode_; - } - - goog.dom.RangeIterator.call(this, this.startNode_, false); -}; -goog.inherits(goog.dom.ControlRangeIterator, goog.dom.RangeIterator); - - -/** - * The first node in the selection. - * @type {Node} - * @private - */ -goog.dom.ControlRangeIterator.prototype.startNode_ = null; - - -/** - * The last node in the selection. - * @type {Node} - * @private - */ -goog.dom.ControlRangeIterator.prototype.endNode_ = null; - - -/** - * The list of elements left to traverse. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRangeIterator.prototype.elements_ = null; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getStartTextOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getEndTextOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getStartNode = function() { - return this.startNode_; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getEndNode = function() { - return this.endNode_; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.isLast = function() { - return !this.depth && !this.elements_.length; -}; - - -/** - * Move to the next position in the selection. - * Throws {@code goog.iter.StopIteration} when it passes the end of the range. - * @return {Node} The node at the next position. - */ -goog.dom.ControlRangeIterator.prototype.next = function() { - // Iterate over each element in the range, and all of its children. - if (this.isLast()) { - throw goog.iter.StopIteration; - } else if (!this.depth) { - var el = this.elements_.shift(); - this.setPosition(el, - goog.dom.TagWalkType.START_TAG, - goog.dom.TagWalkType.START_TAG); - return el; - } - - // Call the super function. - return goog.dom.ControlRangeIterator.superClass_.next.call(this); -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.ControlRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.ControlRangeIterator.prototype.copyFrom = function(other) { - this.elements_ = other.elements_; - this.startNode_ = other.startNode_; - this.endNode_ = other.endNode_; - - goog.dom.ControlRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.ControlRangeIterator} An identical iterator. - */ -goog.dom.ControlRangeIterator.prototype.clone = function() { - var copy = new goog.dom.ControlRangeIterator(null); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base deleted file mode 100644 index 99ecd11..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base +++ /dev/null @@ -1,246 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.ControlRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.ControlRange'); - goog.require('goog.dom.TextRange'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1"></div> - <div id="test2"> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - </div> - <!-- Omit whitespace here to ensure no extra text nodes are included. --> - <table id="table"><tbody id="tbody"><tr id="tr1"><td id="td11">a</td - ><td id="td12">b</td></tr><tr id="tr2"><td id="td21">c</td><td id="td22" - >d</td></tr></tbody></table> - <table id="table2"> - <tr> - <td>moof</td> - </tr> - <tr> - <td id="table2td"> - foo - <img id="logo2" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - bar - </td> - </tr> - </table> - - -<script> - var logo = goog.dom.getElement('logo'); - var table = goog.dom.getElement('table'); - - function testCreateFromElement() { - if (!goog.userAgent.IE) { - return; - } - assertNotNull('Control range object can be created for element', - goog.dom.ControlRange.createFromElements(logo)); - } - - function testCreateFromRange() { - if (!goog.userAgent.IE) { - return; - } - var range = document.body.createControlRange(); - range.addElement(table); - assertNotNull('Control range object can be created for element', - goog.dom.ControlRange.createFromBrowserRange(range)); - } - - function testSelect() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(table); - range.select(); - - assertEquals('Control range should be selected', 'Control', - document.selection.type); - assertEquals('Control range should have length 1', 1, - document.selection.createRange().length); - assertEquals('Control range should select table', table, - document.selection.createRange().item(0)); - } - - function testControlRangeIterator() { - if (!goog.userAgent.IE) { - return; - } - var range = goog.dom.ControlRange.createFromElements(logo, table); - // Each node is included twice - once as a start tag, once as an end. - goog.testing.dom.assertNodesMatch(range, ['#logo', '#logo', '#table', - '#tbody', '#tr1', '#td11', 'a', '#td11', '#td12', 'b', '#td12', '#tr1', - '#tr2', '#td21', 'c', '#td21', '#td22', 'd', '#td22', '#tr2', '#tbody', - '#table']); - } - - function testBounds() { - if (!goog.userAgent.IE) { - return; - } - - // Initialize in both orders. - helpTestBounds(goog.dom.ControlRange.createFromElements(logo, table)); - helpTestBounds(goog.dom.ControlRange.createFromElements(table, logo)); - } - - function helpTestBounds(range) { - assertEquals('Start node is logo', logo, range.getStartNode()); - assertEquals('Start offset is 0', 0, range.getStartOffset()); - assertEquals('End node is table', table, range.getEndNode()); - assertEquals('End offset is 1', 1, range.getEndOffset()); - } - - function testCollapse() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo, table); - assertFalse('Not initially collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Successfully collapsed', range.isCollapsed()); - } - - function testGetContainer() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo); - assertEquals('Single element range is contained by itself', logo, - range.getContainer()); - - range = goog.dom.ControlRange.createFromElements(logo, table); - assertEquals('Two element range is contained by body', document.body, - range.getContainer()); - } - - function testSave() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo, table); - var savedRange = range.saveUsingDom(); - - range.collapse(); - assertTrue('Successfully collapsed', range.isCollapsed()); - - range = savedRange.restore(); - assertEquals('Restored a control range', goog.dom.RangeType.CONTROL, - range.getType()); - assertFalse('Not collapsed after restore', range.isCollapsed()); - helpTestBounds(range); - } - - function testRemoveContents() { - if (!goog.userAgent.IE) { - return; - } - - var img = goog.dom.createDom('IMG'); - img.src = logo.src; - - var div = goog.dom.getElement('test1'); - div.innerHTML = ''; - div.appendChild(img); - assertEquals('Div has 1 child', 1, div.childNodes.length); - - var range = goog.dom.ControlRange.createFromElements(img); - range.removeContents(); - assertEquals('Div has 0 children', 0, div.childNodes.length); - assertTrue('Range is collapsed', range.isCollapsed()); - } - - function testReplaceContents() { - // Test a control range. - if (!goog.userAgent.IE) { - return; - } - - var outer = goog.dom.getElement('test1'); - outer.innerHTML = - '<div contentEditable="true">' + - 'Hello <input type="text" value="World">' + - '</div>'; - range = goog.dom.ControlRange.createFromElements( - outer.getElementsByTagName(goog.dom.TagName.INPUT)[0]); - goog.dom.ControlRange.createFromElements(table) - range.replaceContentsWithNode(goog.dom.createTextNode('World')); - assertEquals('Hello World', outer.firstChild.innerHTML); - } - - function testContainsRange() { - if (!goog.userAgent.IE) { - return; - } - - var table2 = goog.dom.getElement('table2'); - var table2td = goog.dom.getElement('table2td'); - var logo2 = goog.dom.getElement('logo2'); - - var range = goog.dom.ControlRange.createFromElements(logo, table); - var range2 = goog.dom.ControlRange.createFromElements(logo); - assertTrue('Control range contains the other control range', - range.containsRange(range2)); - assertTrue('Control range partially contains the other control range', - range2.containsRange(range, true)); - - range2 = goog.dom.ControlRange.createFromElements(table2); - assertFalse('Control range does not contain the other control range', - range.containsRange(range2)); - - range = goog.dom.ControlRange.createFromElements(table2); - range2 = goog.dom.TextRange.createFromNodeContents(table2td); - assertTrue('Control range contains text range', - range.containsRange(range2)); - - range2 = goog.dom.TextRange.createFromNodeContents(table); - assertFalse('Control range does not contain text range', - range.containsRange(range2)); - - range = goog.dom.ControlRange.createFromElements(logo2); - range2 = goog.dom.TextRange.createFromNodeContents(table2); - assertFalse('Control range does not fully contain text range', - range.containsRange(range2, false)); - - range2 = goog.dom.ControlRange.createFromElements(table2); - assertTrue('Control range contains the other control range (2)', - range2.containsRange(range)); - } - - function testCloneRange() { - if (!goog.userAgent.IE) { - return; - } - var range = goog.dom.ControlRange.createFromElements(logo); - assertNotNull('Control range object created for element', range); - - var cloneRange = range.clone(); - assertNotNull('Cloned control range object', cloneRange); - assertArrayEquals('Control range and clone have same elements', - range.getElements(), cloneRange.getElements()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base deleted file mode 100644 index 5f9b821..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting values in - * an Element's dataset. - * See {@link http://www.w3.org/TR/html5/Overview.html#dom-dataset}. - * - */ - -goog.provide('goog.dom.dataset'); - -goog.require('goog.string'); - - -/** - * Sets a custom data attribute on an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to set the custom data attribute on. - * @param {string} key Key for the custom data attribute. - * @param {string} value Value for the custom data attribute. - */ -goog.dom.dataset.set = function(element, key, value) { - if (element.dataset) { - element.dataset[key] = value; - } else { - element.setAttribute('data-' + goog.string.toSelectorCase(key), value); - } -}; - - -/** - * Gets a custom data attribute from an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - * @return {?string} The attribute value, if it exists. - */ -goog.dom.dataset.get = function(element, key) { - if (element.dataset) { - return element.dataset[key]; - } else { - return element.getAttribute('data-' + goog.string.toSelectorCase(key)); - } -}; - - -/** - * Removes a custom data attribute from an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - */ -goog.dom.dataset.remove = function(element, key) { - if (element.dataset) { - delete element.dataset[key]; - } else { - element.removeAttribute('data-' + goog.string.toSelectorCase(key)); - } -}; - - -/** - * Checks whether custom data attribute exists on an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - * @return {boolean} Whether the attibute exists. - */ -goog.dom.dataset.has = function(element, key) { - if (element.dataset) { - return key in element.dataset; - } else if (element.hasAttribute) { - return element.hasAttribute('data-' + goog.string.toSelectorCase(key)); - } else { - return !!(element.getAttribute('data-' + goog.string.toSelectorCase(key))); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base deleted file mode 100644 index 0030aa6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base +++ /dev/null @@ -1,104 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2011 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.dataset</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.dataset'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <span id="el1" data-basic-key="basic" - data--unusual-key1="unusual1" - data-unusual--key2="unusual2" - data---bizarre---key="bizarre"></span> - <span id="el2"></span> -<script> - - -var $ = goog.dom.getElement; -var dataset = goog.dom.dataset; - - -function setUp() { - var el = $('el2'); - el.setAttribute('data-dynamic-key', 'dynamic'); -} - - -function testHas() { - var el = $('el1'); - - assertTrue('Dataset should have an existing key', - dataset.has(el, 'basicKey')); - assertTrue('Dataset should have an existing (unusual) key', - dataset.has(el, 'UnusualKey1')); - assertTrue('Dataset should have an existing (unusual) key', - dataset.has(el, 'unusual-Key2')); - assertTrue('Dataset should have an existing (bizarre) key', - dataset.has(el, '-Bizarre--Key')); - assertFalse('Dataset should not have a non-existent key', - dataset.has(el, 'bogusKey')); -} - - -function testGet() { - var el = $('el1'); - - assertEquals('Dataset should return the proper value for an existing key', - dataset.get(el, 'basicKey'), 'basic'); - assertEquals('Dataset should have an existing (unusual) key', - dataset.get(el, 'UnusualKey1'), 'unusual1'); - assertEquals('Dataset should have an existing (unusual) key', - dataset.get(el, 'unusual-Key2'), 'unusual2'); - assertEquals('Dataset should have an existing (bizarre) key', - dataset.get(el, '-Bizarre--Key'), 'bizarre'); - assertFalse('Dataset should return null or an empty string for a non-existent key', - !!dataset.get(el, 'bogusKey')); - - el = $('el2'); - assertEquals('Dataset should return the proper value for an existing key', - dataset.get(el, 'dynamicKey'), 'dynamic'); -} - - -function testSet() { - var el = $('el2'); - - dataset.set(el, 'newKey', 'newValue'); - assertTrue('Dataset should have a newly created key', - dataset.has(el, 'newKey')); - assertEquals('Dataset should return the proper value for a newly created key', - dataset.get(el, 'newKey'), 'newValue'); - - dataset.set(el, 'dynamicKey', 'customValue'); - assertTrue('Dataset should have a modified, existing key', - dataset.has(el, 'dynamicKey')); - assertEquals('Dataset should return the proper value for a modified key', - dataset.get(el, 'dynamicKey'), 'customValue'); -} - - -function testRemove() { - var el = $('el2'); - - dataset.remove(el, 'dynamicKey'); - assertFalse('Dataset should not have a removed key', - dataset.has(el, 'dynamicKey')); - assertFalse('Dataset should return null or an empty string for removed key', - !!dataset.get(el, 'dynamicKey')); -} - - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base deleted file mode 100644 index dc78f3f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base +++ /dev/null @@ -1,2534 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for manipulating the browser's Document Object Model - * Inspiration taken *heavily* from mochikit (http://mochikit.com/). - * - * You can use {@link goog.dom.DomHelper} to create new dom helpers that refer - * to a different document object. This is useful if you are working with - * frames or multiple windows. - * - */ - - -// TODO(arv): Rename/refactor getTextContent and getRawTextContent. The problem -// is that getTextContent should mimic the DOM3 textContent. We should add a -// getInnerText (or getText) which tries to return the visible text, innerText. - - -goog.provide('goog.dom'); -goog.provide('goog.dom.DomHelper'); -goog.provide('goog.dom.NodeType'); - -goog.require('goog.array'); -goog.require('goog.dom.BrowserFeature'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.classes'); -goog.require('goog.math.Coordinate'); -goog.require('goog.math.Size'); -goog.require('goog.object'); -goog.require('goog.string'); -goog.require('goog.userAgent'); - - -/** - * @define {boolean} Whether we know at compile time that the browser is in - * quirks mode. - */ -goog.dom.ASSUME_QUIRKS_MODE = false; - - -/** - * @define {boolean} Whether we know at compile time that the browser is in - * standards compliance mode. - */ -goog.dom.ASSUME_STANDARDS_MODE = false; - - -/** - * Whether we know the compatibility mode at compile time. - * @type {boolean} - * @private - */ -goog.dom.COMPAT_MODE_KNOWN_ = - goog.dom.ASSUME_QUIRKS_MODE || goog.dom.ASSUME_STANDARDS_MODE; - - -/** - * Enumeration for DOM node types (for reference) - * @enum {number} - */ -goog.dom.NodeType = { - ELEMENT: 1, - ATTRIBUTE: 2, - TEXT: 3, - CDATA_SECTION: 4, - ENTITY_REFERENCE: 5, - ENTITY: 6, - PROCESSING_INSTRUCTION: 7, - COMMENT: 8, - DOCUMENT: 9, - DOCUMENT_TYPE: 10, - DOCUMENT_FRAGMENT: 11, - NOTATION: 12 -}; - - -/** - * Gets the DomHelper object for the document where the element resides. - * @param {Node|Window=} opt_element If present, gets the DomHelper for this - * element. - * @return {!goog.dom.DomHelper} The DomHelper. - */ -goog.dom.getDomHelper = function(opt_element) { - return opt_element ? - new goog.dom.DomHelper(goog.dom.getOwnerDocument(opt_element)) : - (goog.dom.defaultDomHelper_ || - (goog.dom.defaultDomHelper_ = new goog.dom.DomHelper())); -}; - - -/** - * Cached default DOM helper. - * @type {goog.dom.DomHelper} - * @private - */ -goog.dom.defaultDomHelper_; - - -/** - * Gets the document object being used by the dom library. - * @return {!Document} Document object. - */ -goog.dom.getDocument = function() { - return document; -}; - - -/** - * Alias for getElementById. If a DOM node is passed in then we just return - * that. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - */ -goog.dom.getElement = function(element) { - return goog.isString(element) ? - document.getElementById(element) : element; -}; - - -/** - * Alias for getElement. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - * @deprecated Use {@link goog.dom.getElement} instead. - */ -goog.dom.$ = goog.dom.getElement; - - -/** - * Looks up elements by both tag and class name, using browser native functions - * ({@code querySelectorAll}, {@code getElementsByTagName} or - * {@code getElementsByClassName}) where possible. This function - * is a useful, if limited, way of collecting a list of DOM elements - * with certain characteristics. {@code goog.dom.query} offers a - * more powerful and general solution which allows matching on CSS3 - * selector expressions, but at increased cost in code size. If all you - * need is particular tags belonging to a single class, this function - * is fast and sleek. - * - * @see {goog.dom.query} - * - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) { - return goog.dom.getElementsByTagNameAndClass_(document, opt_tag, opt_class, - opt_el); -}; - - -/** - * Returns an array of all the elements with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } The items found with the class name provided. - */ -goog.dom.getElementsByClass = function(className, opt_el) { - var parent = opt_el || document; - if (goog.dom.canUseQuerySelector_(parent)) { - return parent.querySelectorAll('.' + className); - } else if (parent.getElementsByClassName) { - return parent.getElementsByClassName(className); - } - return goog.dom.getElementsByTagNameAndClass_( - document, '*', className, opt_el); -}; - - -/** - * Returns the first element with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return {Element} The first item with the class name provided. - */ -goog.dom.getElementByClass = function(className, opt_el) { - var parent = opt_el || document; - var retVal = null; - if (goog.dom.canUseQuerySelector_(parent)) { - retVal = parent.querySelector('.' + className); - } else { - retVal = goog.dom.getElementsByClass(className, opt_el)[0]; - } - return retVal || null; -}; - - -/** - * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and - * fast W3C Selectors API. However, the version of WebKit that shipped with - * Safari 3.1 and Chrome has a bug where it will not correctly match mixed- - * case class name selectors in quirks mode. - * @param {!Element|Document} parent The parent document object. - * @return {boolean} whether or not we can use parent.querySelector* APIs. - * @private - */ -goog.dom.canUseQuerySelector_ = function(parent) { - return parent.querySelectorAll && - parent.querySelector && - (!goog.userAgent.WEBKIT || goog.dom.isCss1CompatMode_(document) || - goog.userAgent.isVersion('528')); -}; - - -/** - * Helper for {@code getElementsByTagNameAndClass}. - * @param {!Document} doc The document to get the elements in. - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - * @private - */ -goog.dom.getElementsByTagNameAndClass_ = function(doc, opt_tag, opt_class, - opt_el) { - var parent = opt_el || doc; - var tagName = (opt_tag && opt_tag != '*') ? opt_tag.toUpperCase() : ''; - - if (goog.dom.canUseQuerySelector_(parent) && - (tagName || opt_class)) { - var query = tagName + (opt_class ? '.' + opt_class : ''); - return parent.querySelectorAll(query); - } - - // Use the native getElementsByClassName if available, under the assumption - // that even when the tag name is specified, there will be fewer elements to - // filter through when going by class than by tag name - if (opt_class && parent.getElementsByClassName) { - var els = parent.getElementsByClassName(opt_class); - - if (tagName) { - var arrayLike = {}; - var len = 0; - - // Filter for specific tags if requested. - for (var i = 0, el; el = els[i]; i++) { - if (tagName == el.nodeName) { - arrayLike[len++] = el; - } - } - arrayLike.length = len; - - return arrayLike; - } else { - return els; - } - } - - var els = parent.getElementsByTagName(tagName || '*'); - - if (opt_class) { - var arrayLike = {}; - var len = 0; - for (var i = 0, el; el = els[i]; i++) { - var className = el.className; - // Check if className has a split function since SVG className does not. - if (typeof className.split == 'function' && - goog.array.contains(className.split(/\s+/), opt_class)) { - arrayLike[len++] = el; - } - } - arrayLike.length = len; - return arrayLike; - } else { - return els; - } -}; - - -/** - * Alias for {@code getElementsByTagNameAndClass}. - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - * @deprecated Use {@link goog.dom.getElementsByTagNameAndClass} instead. - */ -goog.dom.$$ = goog.dom.getElementsByTagNameAndClass; - - -/** - * Sets multiple properties on a node. - * @param {Element} element DOM node to set properties on. - * @param {Object} properties Hash of property:value pairs. - */ -goog.dom.setProperties = function(element, properties) { - goog.object.forEach(properties, function(val, key) { - if (key == 'style') { - element.style.cssText = val; - } else if (key == 'class') { - element.className = val; - } else if (key == 'for') { - element.htmlFor = val; - } else if (key in goog.dom.DIRECT_ATTRIBUTE_MAP_) { - element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val); - } else if (goog.string.startsWith(key, 'aria-')) { - element.setAttribute(key, val); - } else { - element[key] = val; - } - }); -}; - - -/** - * Map of attributes that should be set using - * element.setAttribute(key, val) instead of element[key] = val. Used - * by goog.dom.setProperties. - * - * @type {Object} - * @private - */ -goog.dom.DIRECT_ATTRIBUTE_MAP_ = { - 'cellpadding': 'cellPadding', - 'cellspacing': 'cellSpacing', - 'colspan': 'colSpan', - 'rowspan': 'rowSpan', - 'valign': 'vAlign', - 'height': 'height', - 'width': 'width', - 'usemap': 'useMap', - 'frameborder': 'frameBorder', - 'maxlength': 'maxLength', - 'type': 'type' -}; - - -/** - * Gets the dimensions of the viewport. - * - * Gecko Standards mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of body element. - * - * docEl.clientHeight Height of viewport excluding scrollbar. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of document. - * - * Gecko Backwards compatible mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight Height of document. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of viewport excluding scrollbar. - * - * IE6/7 Standards mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Undefined. - * body.clientWidth Width of body element. - * - * docEl.clientHeight Height of viewport excluding scrollbar. - * win.innerHeight Undefined. - * body.clientHeight Height of document element. - * - * IE5 + IE6/7 Backwards compatible mode: - * docEl.clientWidth 0. - * win.innerWidth Undefined. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight 0. - * win.innerHeight Undefined. - * body.clientHeight Height of viewport excluding scrollbar. - * - * Opera 9 Standards and backwards compatible mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight Height of document. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of viewport excluding scrollbar. - * - * WebKit: - * Safari 2 - * docEl.clientHeight Same as scrollHeight. - * docEl.clientWidth Same as innerWidth. - * win.innerWidth Width of viewport excluding scrollbar. - * win.innerHeight Height of the viewport including scrollbar. - * frame.innerHeight Height of the viewport exluding scrollbar. - * - * Safari 3 (tested in 522) - * - * docEl.clientWidth Width of viewport excluding scrollbar. - * docEl.clientHeight Height of viewport excluding scrollbar in strict mode. - * body.clientHeight Height of viewport excluding scrollbar in quirks mode. - * - * @param {Window=} opt_window Optional window element to test. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - */ -goog.dom.getViewportSize = function(opt_window) { - // TODO(arv): This should not take an argument - return goog.dom.getViewportSize_(opt_window || window); -}; - - -/** - * Helper for {@code getViewportSize}. - * @param {Window} win The window to get the view port size for. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - * @private - */ -goog.dom.getViewportSize_ = function(win) { - var doc = win.document; - - if (goog.userAgent.WEBKIT && !goog.userAgent.isVersion('500') && - !goog.userAgent.MOBILE) { - // TODO(user): Sometimes we get something that isn't a valid window - // object. In this case we just revert to the current window. We need to - // figure out when this happens and find a real fix for it. - // See the comments on goog.dom.getWindow. - if (typeof win.innerHeight == 'undefined') { - win = window; - } - var innerHeight = win.innerHeight; - var scrollHeight = win.document.documentElement.scrollHeight; - - if (win == win.top) { - if (scrollHeight < innerHeight) { - innerHeight -= 15; // Scrollbars are 15px wide on Mac - } - } - return new goog.math.Size(win.innerWidth, innerHeight); - } - - var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body; - - return new goog.math.Size(el.clientWidth, el.clientHeight); -}; - - -/** - * Calculates the height of the document. - * - * @return {number} The height of the current document. - */ -goog.dom.getDocumentHeight = function() { - return goog.dom.getDocumentHeight_(window); -}; - - -/** - * Calculates the height of the document of the given window. - * - * Function code copied from the opensocial gadget api: - * gadgets.window.adjustHeight(opt_height) - * - * @private - * @param {Window} win The window whose document height to retrieve. - * @return {number} The height of the document of the given window. - */ -goog.dom.getDocumentHeight_ = function(win) { - // NOTE(eae): This method will return the window size rather than the document - // size in webkit quirks mode. - var doc = win.document; - var height = 0; - - if (doc) { - // Calculating inner content height is hard and different between - // browsers rendering in Strict vs. Quirks mode. We use a combination of - // three properties within document.body and document.documentElement: - // - scrollHeight - // - offsetHeight - // - clientHeight - // These values differ significantly between browsers and rendering modes. - // But there are patterns. It just takes a lot of time and persistence - // to figure out. - - // Get the height of the viewport - var vh = goog.dom.getViewportSize_(win).height; - var body = doc.body; - var docEl = doc.documentElement; - if (goog.dom.isCss1CompatMode_(doc) && docEl.scrollHeight) { - // In Strict mode: - // The inner content height is contained in either: - // document.documentElement.scrollHeight - // document.documentElement.offsetHeight - // Based on studying the values output by different browsers, - // use the value that's NOT equal to the viewport height found above. - height = docEl.scrollHeight != vh ? - docEl.scrollHeight : docEl.offsetHeight; - } else { - // In Quirks mode: - // documentElement.clientHeight is equal to documentElement.offsetHeight - // except in IE. In most browsers, document.documentElement can be used - // to calculate the inner content height. - // However, in other browsers (e.g. IE), document.body must be used - // instead. How do we know which one to use? - // If document.documentElement.clientHeight does NOT equal - // document.documentElement.offsetHeight, then use document.body. - var sh = docEl.scrollHeight; - var oh = docEl.offsetHeight; - if (docEl.clientHeight != oh) { - sh = body.scrollHeight; - oh = body.offsetHeight; - } - - // Detect whether the inner content height is bigger or smaller - // than the bounding box (viewport). If bigger, take the larger - // value. If smaller, take the smaller value. - if (sh > vh) { - // Content is larger - height = sh > oh ? sh : oh; - } else { - // Content is smaller - height = sh < oh ? sh : oh; - } - } - } - - return height; -}; - - -/** - * Gets the page scroll distance as a coordinate object. - * - * @param {Window=} opt_window Optional window element to test. - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - * @deprecated Use {@link goog.dom.getDocumentScroll} instead. - */ -goog.dom.getPageScroll = function(opt_window) { - var win = opt_window || goog.global || window; - return goog.dom.getDomHelper(win.document).getDocumentScroll(); -}; - - -/** - * Gets the document scroll distance as a coordinate object. - * - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - */ -goog.dom.getDocumentScroll = function() { - return goog.dom.getDocumentScroll_(document); -}; - - -/** - * Helper for {@code getDocumentScroll}. - * - * @param {!Document} doc The document to get the scroll for. - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - * @private - */ -goog.dom.getDocumentScroll_ = function(doc) { - var el = goog.dom.getDocumentScrollElement_(doc); - var win = goog.dom.getWindow_(doc); - return new goog.math.Coordinate(win.pageXOffset || el.scrollLeft, - win.pageYOffset || el.scrollTop); -}; - - -/** - * Gets the document scroll element. - * @return {Element} Scrolling element. - */ -goog.dom.getDocumentScrollElement = function() { - return goog.dom.getDocumentScrollElement_(document); -}; - - -/** - * Helper for {@code getDocumentScrollElement}. - * @param {!Document} doc The document to get the scroll element for. - * @return {Element} Scrolling element. - * @private - */ -goog.dom.getDocumentScrollElement_ = function(doc) { - // Safari (2 and 3) needs body.scrollLeft in both quirks mode and strict mode. - return !goog.userAgent.WEBKIT && goog.dom.isCss1CompatMode_(doc) ? - doc.documentElement : doc.body; -}; - - -/** - * Gets the window object associated with the given document. - * - * @param {Document=} opt_doc Document object to get window for. - * @return {!Window} The window associated with the given document. - */ -goog.dom.getWindow = function(opt_doc) { - // TODO(arv): This should not take an argument. - return opt_doc ? goog.dom.getWindow_(opt_doc) : window; -}; - - -/** - * Helper for {@code getWindow}. - * - * @param {!Document} doc Document object to get window for. - * @return {!Window} The window associated with the given document. - * @private - */ -goog.dom.getWindow_ = function(doc) { - return doc.parentWindow || doc.defaultView; -}; - - -/** - * Returns a dom node with a set of attributes. This function accepts varargs - * for subsequent nodes to be added. Subsequent nodes will be added to the - * first node as childNodes. - * - * So: - * <code>createDom('div', null, createDom('p'), createDom('p'));</code> - * would return a div with two child paragraphs - * - * @param {string} tagName Tag to create. - * @param {Object|Array.<string>|string=} opt_attributes If object, then a map - * of name-value pairs for attributes. If a string, then this is the - * className of the new element. If an array, the elements will be joined - * together as the className of the new element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array or NodeList,i - * its elements will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - */ -goog.dom.createDom = function(tagName, opt_attributes, var_args) { - return goog.dom.createDom_(document, arguments); -}; - - -/** - * Helper for {@code createDom}. - * @param {!Document} doc The document to create the DOM in. - * @param {!Arguments} args Argument object passed from the callers. See - * {@code goog.dom.createDom} for details. - * @return {!Element} Reference to a DOM node. - * @private - */ -goog.dom.createDom_ = function(doc, args) { - var tagName = args[0]; - var attributes = args[1]; - - // Internet Explorer is dumb: http://msdn.microsoft.com/workshop/author/ - // dhtml/reference/properties/name_2.asp - // Also does not allow setting of 'type' attribute on 'input' or 'button'. - if (!goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES && attributes && - (attributes.name || attributes.type)) { - var tagNameArr = ['<', tagName]; - if (attributes.name) { - tagNameArr.push(' name="', goog.string.htmlEscape(attributes.name), - '"'); - } - if (attributes.type) { - tagNameArr.push(' type="', goog.string.htmlEscape(attributes.type), - '"'); - - // Clone attributes map to remove 'type' without mutating the input. - var clone = {}; - goog.object.extend(clone, attributes); - attributes = clone; - delete attributes.type; - } - tagNameArr.push('>'); - tagName = tagNameArr.join(''); - } - - var element = doc.createElement(tagName); - - if (attributes) { - if (goog.isString(attributes)) { - element.className = attributes; - } else if (goog.isArray(attributes)) { - goog.dom.classes.add.apply(null, [element].concat(attributes)); - } else { - goog.dom.setProperties(element, attributes); - } - } - - if (args.length > 2) { - goog.dom.append_(doc, element, args, 2); - } - - return element; -}; - - -/** - * Appends a node with text or other nodes. - * @param {!Document} doc The document to create new nodes in. - * @param {!Node} parent The node to append nodes to. - * @param {!Arguments} args The values to add. See {@code goog.dom.append}. - * @param {number} startIndex The index of the array to start from. - * @private - */ -goog.dom.append_ = function(doc, parent, args, startIndex) { - function childHandler(child) { - // TODO(user): More coercion, ala MochiKit? - if (child) { - parent.appendChild(goog.isString(child) ? - doc.createTextNode(child) : child); - } - } - - for (var i = startIndex; i < args.length; i++) { - var arg = args[i]; - // TODO(attila): Fix isArrayLike to return false for a text node. - if (goog.isArrayLike(arg) && !goog.dom.isNodeLike(arg)) { - // If the argument is a node list, not a real array, use a clone, - // because forEach can't be used to mutate a NodeList. - goog.array.forEach(goog.dom.isNodeList(arg) ? - goog.array.clone(arg) : arg, - childHandler); - } else { - childHandler(arg); - } - } -}; - - -/** - * Alias for {@code createDom}. - * @param {string} tagName Tag to create. - * @param {string|Object=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array, its - * children will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - * @deprecated Use {@link goog.dom.createDom} instead. - */ -goog.dom.$dom = goog.dom.createDom; - - -/** - * Creates a new element. - * @param {string} name Tag name. - * @return {!Element} The new element. - */ -goog.dom.createElement = function(name) { - return document.createElement(name); -}; - - -/** - * Creates a new text node. - * @param {string} content Content. - * @return {!Text} The new text node. - */ -goog.dom.createTextNode = function(content) { - return document.createTextNode(content); -}; - - -/** - * Create a table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - */ -goog.dom.createTable = function(rows, columns, opt_fillWithNbsp) { - return goog.dom.createTable_(document, rows, columns, !!opt_fillWithNbsp); -}; - - -/** - * Create a table. - * @param {!Document} doc Document object to use to create the table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean} fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - * @private - */ -goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) { - var rowHtml = ['<tr>']; - for (var i = 0; i < columns; i++) { - rowHtml.push(fillWithNbsp ? '<td> </td>' : '<td></td>'); - } - rowHtml.push('</tr>'); - rowHtml = rowHtml.join(''); - var totalHtml = ['<table>']; - for (i = 0; i < rows; i++) { - totalHtml.push(rowHtml); - } - totalHtml.push('</table>'); - - var elem = doc.createElement(goog.dom.TagName.DIV); - elem.innerHTML = totalHtml.join(''); - return /** @type {!Element} */ (elem.removeChild(elem.firstChild)); -}; - - -/** - * Converts an HTML string into a document fragment. - * - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting document fragment. - */ -goog.dom.htmlToDocumentFragment = function(htmlString) { - return goog.dom.htmlToDocumentFragment_(document, htmlString); -}; - - -/** - * Helper for {@code htmlToDocumentFragment}. - * - * @param {!Document} doc The document. - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting document fragment. - * @private - */ -goog.dom.htmlToDocumentFragment_ = function(doc, htmlString) { - var tempDiv = doc.createElement('div'); - if (goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT) { - tempDiv.innerHTML = '<br>' + htmlString; - tempDiv.removeChild(tempDiv.firstChild); - } else { - tempDiv.innerHTML = htmlString; - } - if (tempDiv.childNodes.length == 1) { - return /** @type {!Node} */ (tempDiv.removeChild(tempDiv.firstChild)); - } else { - var fragment = doc.createDocumentFragment(); - while (tempDiv.firstChild) { - fragment.appendChild(tempDiv.firstChild); - } - return fragment; - } -}; - - -/** - * Returns the compatMode of the document. - * @return {string} The result is either CSS1Compat or BackCompat. - * @deprecated use goog.dom.isCss1CompatMode instead. - */ -goog.dom.getCompatMode = function() { - return goog.dom.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat'; -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @return {boolean} True if in CSS1-compatible mode. - */ -goog.dom.isCss1CompatMode = function() { - return goog.dom.isCss1CompatMode_(document); -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @param {Document} doc The document to check. - * @return {boolean} True if in CSS1-compatible mode. - * @private - */ -goog.dom.isCss1CompatMode_ = function(doc) { - if (goog.dom.COMPAT_MODE_KNOWN_) { - return goog.dom.ASSUME_STANDARDS_MODE; - } - - return doc.compatMode == 'CSS1Compat'; -}; - - -/** - * Determines if the given node can contain children, intended to be used for - * HTML generation. - * - * IE natively supports node.canHaveChildren but has inconsistent behavior. - * Prior to IE8 the base tag allows children and in IE9 all nodes return true - * for canHaveChildren. - * - * In practice all non-IE browsers allow you to add children to any node, but - * the behavior is inconsistent: - * - * <pre> - * var a = document.createElement('br'); - * a.appendChild(document.createTextNode('foo')); - * a.appendChild(document.createTextNode('bar')); - * console.log(a.childNodes.length); // 2 - * console.log(a.innerHTML); // Chrome: "", IE9: "foobar", FF3.5: "foobar" - * </pre> - * - * TODO(user): Rename shouldAllowChildren() ? - * - * @param {Node} node The node to check. - * @return {boolean} Whether the node can contain children. - */ -goog.dom.canHaveChildren = function(node) { - if (node.nodeType != goog.dom.NodeType.ELEMENT) { - return false; - } - switch (node.tagName) { - case goog.dom.TagName.APPLET: - case goog.dom.TagName.AREA: - case goog.dom.TagName.BASE: - case goog.dom.TagName.BR: - case goog.dom.TagName.COL: - case goog.dom.TagName.FRAME: - case goog.dom.TagName.HR: - case goog.dom.TagName.IMG: - case goog.dom.TagName.INPUT: - case goog.dom.TagName.IFRAME: - case goog.dom.TagName.ISINDEX: - case goog.dom.TagName.LINK: - case goog.dom.TagName.NOFRAMES: - case goog.dom.TagName.NOSCRIPT: - case goog.dom.TagName.META: - case goog.dom.TagName.OBJECT: - case goog.dom.TagName.PARAM: - case goog.dom.TagName.SCRIPT: - case goog.dom.TagName.STYLE: - return false; - } - return true; -}; - - -/** - * Appends a child to a node. - * @param {Node} parent Parent. - * @param {Node} child Child. - */ -goog.dom.appendChild = function(parent, child) { - parent.appendChild(child); -}; - - -/** - * Appends a node with text or other nodes. - * @param {!Node} parent The node to append nodes to. - * @param {...goog.dom.Appendable} var_args The things to append to the node. - * If this is a Node it is appended as is. - * If this is a string then a text node is appended. - * If this is an array like object then fields 0 to length - 1 are appended. - */ -goog.dom.append = function(parent, var_args) { - goog.dom.append_(goog.dom.getOwnerDocument(parent), parent, arguments, 1); -}; - - -/** - * Removes all the child nodes on a DOM node. - * @param {Node} node Node to remove children from. - */ -goog.dom.removeChildren = function(node) { - // Note: Iterations over live collections can be slow, this is the fastest - // we could find. The double parenthesis are used to prevent JsCompiler and - // strict warnings. - var child; - while ((child = node.firstChild)) { - node.removeChild(child); - } -}; - - -/** - * Inserts a new node before an existing reference node (i.e. as the previous - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert before. - */ -goog.dom.insertSiblingBefore = function(newNode, refNode) { - if (refNode.parentNode) { - refNode.parentNode.insertBefore(newNode, refNode); - } -}; - - -/** - * Inserts a new node after an existing reference node (i.e. as the next - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert after. - */ -goog.dom.insertSiblingAfter = function(newNode, refNode) { - if (refNode.parentNode) { - refNode.parentNode.insertBefore(newNode, refNode.nextSibling); - } -}; - - -/** - * Insert a child at a given index. If index is larger than the number of child - * nodes that the parent currently has, the node is inserted as the last child - * node. - * @param {Element} parent The element into which to insert the child. - * @param {Node} child The element to insert. - * @param {number} index The index at which to insert the new child node. Must - * not be negative. - */ -goog.dom.insertChildAt = function(parent, child, index) { - // Note that if the second argument is null, insertBefore - // will append the child at the end of the list of children. - parent.insertBefore(child, parent.childNodes[index] || null); -}; - - -/** - * Removes a node from its parent. - * @param {Node} node The node to remove. - * @return {Node} The node removed if removed; else, null. - */ -goog.dom.removeNode = function(node) { - return node && node.parentNode ? node.parentNode.removeChild(node) : null; -}; - - -/** - * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no - * parent. - * @param {Node} newNode Node to insert. - * @param {Node} oldNode Node to replace. - */ -goog.dom.replaceNode = function(newNode, oldNode) { - var parent = oldNode.parentNode; - if (parent) { - parent.replaceChild(newNode, oldNode); - } -}; - - -/** - * Flattens an element. That is, removes it and replace it with its children. - * Does nothing if the element is not in the document. - * @param {Element} element The element to flatten. - * @return {Element|undefined} The original element, detached from the document - * tree, sans children; or undefined, if the element was not in the - * document to begin with. - */ -goog.dom.flattenElement = function(element) { - var child, parent = element.parentNode; - if (parent && parent.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT) { - // Use IE DOM method (supported by Opera too) if available - if (element.removeNode) { - return /** @type {Element} */ (element.removeNode(false)); - } else { - // Move all children of the original node up one level. - while ((child = element.firstChild)) { - parent.insertBefore(child, element); - } - - // Detach the original element. - return /** @type {Element} */ (goog.dom.removeNode(element)); - } - } -}; - - -/** - * Returns an array containing just the element children of the given element. - * @param {Element} element The element whose element children we want. - * @return {Array|NodeList} An array or array-like list of just the element - * children of the given element. - */ -goog.dom.getChildren = function(element) { - // We check if the children attribute is supported for child elements - // since IE8 misuses the attribute by also including comments. - if (goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE && - element.children != undefined) { - return element.children; - } - // Fall back to manually filtering the element's child nodes. - return goog.array.filter(element.childNodes, function(node) { - return node.nodeType == goog.dom.NodeType.ELEMENT; - }); -}; - - -/** - * Returns the first child node that is an element. - * @param {Node} node The node to get the first child element of. - * @return {Element} The first child node of {@code node} that is an element. - */ -goog.dom.getFirstElementChild = function(node) { - if (node.firstElementChild != undefined) { - return /** @type {Element} */(node).firstElementChild; - } - return goog.dom.getNextElementNode_(node.firstChild, true); -}; - - -/** - * Returns the last child node that is an element. - * @param {Node} node The node to get the last child element of. - * @return {Element} The last child node of {@code node} that is an element. - */ -goog.dom.getLastElementChild = function(node) { - if (node.lastElementChild != undefined) { - return /** @type {Element} */(node).lastElementChild; - } - return goog.dom.getNextElementNode_(node.lastChild, false); -}; - - -/** - * Returns the first next sibling that is an element. - * @param {Node} node The node to get the next sibling element of. - * @return {Element} The next sibling of {@code node} that is an element. - */ -goog.dom.getNextElementSibling = function(node) { - if (node.nextElementSibling != undefined) { - return /** @type {Element} */(node).nextElementSibling; - } - return goog.dom.getNextElementNode_(node.nextSibling, true); -}; - - -/** - * Returns the first previous sibling that is an element. - * @param {Node} node The node to get the previous sibling element of. - * @return {Element} The first previous sibling of {@code node} that is - * an element. - */ -goog.dom.getPreviousElementSibling = function(node) { - if (node.previousElementSibling != undefined) { - return /** @type {Element} */(node).previousElementSibling; - } - return goog.dom.getNextElementNode_(node.previousSibling, false); -}; - - -/** - * Returns the first node that is an element in the specified direction, - * starting with {@code node}. - * @param {Node} node The node to get the next element from. - * @param {boolean} forward Whether to look forwards or backwards. - * @return {Element} The first element. - * @private - */ -goog.dom.getNextElementNode_ = function(node, forward) { - while (node && node.nodeType != goog.dom.NodeType.ELEMENT) { - node = forward ? node.nextSibling : node.previousSibling; - } - - return /** @type {Element} */ (node); -}; - - -/** - * Returns the next node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The next node in the DOM tree, or null if this was the last - * node. - */ -goog.dom.getNextNode = function(node) { - if (!node) { - return null; - } - - if (node.firstChild) { - return node.firstChild; - } - - while (node && !node.nextSibling) { - node = node.parentNode; - } - - return node ? node.nextSibling : null; -}; - - -/** - * Returns the previous node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The previous node in the DOM tree, or null if this was the - * first node. - */ -goog.dom.getPreviousNode = function(node) { - if (!node) { - return null; - } - - if (!node.previousSibling) { - return node.parentNode; - } - - node = node.previousSibling; - while (node && node.lastChild) { - node = node.lastChild; - } - - return node; -}; - - -/** - * Whether the object looks like a DOM node. - * @param {*} obj The object being tested for node likeness. - * @return {boolean} Whether the object looks like a DOM node. - */ -goog.dom.isNodeLike = function(obj) { - return goog.isObject(obj) && obj.nodeType > 0; -}; - - -/** - * Whether the object looks like an Element. - * @param {*} obj The object being tested for Element likeness. - * @return {boolean} Whether the object looks like an Element. - */ -goog.dom.isElement = function(obj) { - return goog.isObject(obj) && obj.nodeType == goog.dom.NodeType.ELEMENT; -}; - - -/** - * Returns true if the specified value is a Window object. This includes the - * global window for HTML pages, and iframe windows. - * @param {*} obj Variable to test. - * @return {boolean} Whether the variable is a window. - */ -goog.dom.isWindow = function(obj) { - return goog.isObject(obj) && obj['window'] == obj; -}; - - -/** - * Returns an element's parent, if it's an Element. - * @param {Element} element The DOM element. - * @return {Element} The parent, or null if not an Element. - */ -goog.dom.getParentElement = function(element) { - if (goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY) { - return element.parentElement; - } - var parent = element.parentNode; - return goog.dom.isElement(parent) ? (/** @type {!Element} */ parent) : null; -}; - - -/** - * Whether a node contains another node. - * @param {Node} parent The node that should contain the other node. - * @param {Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendent node. - */ -goog.dom.contains = function(parent, descendant) { - // We use browser specific methods for this if available since it is faster - // that way. - - // IE DOM - if (parent.contains && descendant.nodeType == goog.dom.NodeType.ELEMENT) { - return parent == descendant || parent.contains(descendant); - } - - // W3C DOM Level 3 - if (typeof parent.compareDocumentPosition != 'undefined') { - return parent == descendant || - Boolean(parent.compareDocumentPosition(descendant) & 16); - } - - // W3C DOM Level 1 - while (descendant && parent != descendant) { - descendant = descendant.parentNode; - } - return descendant == parent; -}; - - -/** - * Compares the document order of two nodes, returning 0 if they are the same - * node, a negative number if node1 is before node2, and a positive number if - * node2 is before node1. Note that we compare the order the tags appear in the - * document so in the tree <b><i>text</i></b> the B node is considered to be - * before the I node. - * - * @param {Node} node1 The first node to compare. - * @param {Node} node2 The second node to compare. - * @return {number} 0 if the nodes are the same node, a negative number if node1 - * is before node2, and a positive number if node2 is before node1. - */ -goog.dom.compareNodeOrder = function(node1, node2) { - // Fall out quickly for equality. - if (node1 == node2) { - return 0; - } - - // Use compareDocumentPosition where available - if (node1.compareDocumentPosition) { - // 4 is the bitmask for FOLLOWS. - return node1.compareDocumentPosition(node2) & 2 ? 1 : -1; - } - - // Process in IE using sourceIndex - we check to see if the first node has - // a source index or if its parent has one. - if ('sourceIndex' in node1 || - (node1.parentNode && 'sourceIndex' in node1.parentNode)) { - var isElement1 = node1.nodeType == goog.dom.NodeType.ELEMENT; - var isElement2 = node2.nodeType == goog.dom.NodeType.ELEMENT; - - if (isElement1 && isElement2) { - return node1.sourceIndex - node2.sourceIndex; - } else { - var parent1 = node1.parentNode; - var parent2 = node2.parentNode; - - if (parent1 == parent2) { - return goog.dom.compareSiblingOrder_(node1, node2); - } - - if (!isElement1 && goog.dom.contains(parent1, node2)) { - return -1 * goog.dom.compareParentsDescendantNodeIe_(node1, node2); - } - - - if (!isElement2 && goog.dom.contains(parent2, node1)) { - return goog.dom.compareParentsDescendantNodeIe_(node2, node1); - } - - return (isElement1 ? node1.sourceIndex : parent1.sourceIndex) - - (isElement2 ? node2.sourceIndex : parent2.sourceIndex); - } - } - - // For Safari, we compare ranges. - var doc = goog.dom.getOwnerDocument(node1); - - var range1, range2; - range1 = doc.createRange(); - range1.selectNode(node1); - range1.collapse(true); - - range2 = doc.createRange(); - range2.selectNode(node2); - range2.collapse(true); - - return range1.compareBoundaryPoints(goog.global['Range'].START_TO_END, - range2); -}; - - -/** - * Utility function to compare the position of two nodes, when - * {@code textNode}'s parent is an ancestor of {@code node}. If this entry - * condition is not met, this function will attempt to reference a null object. - * @param {Node} textNode The textNode to compare. - * @param {Node} node The node to compare. - * @return {number} -1 if node is before textNode, +1 otherwise. - * @private - */ -goog.dom.compareParentsDescendantNodeIe_ = function(textNode, node) { - var parent = textNode.parentNode; - if (parent == node) { - // If textNode is a child of node, then node comes first. - return -1; - } - var sibling = node; - while (sibling.parentNode != parent) { - sibling = sibling.parentNode; - } - return goog.dom.compareSiblingOrder_(sibling, textNode); -}; - - -/** - * Utility function to compare the position of two nodes known to be non-equal - * siblings. - * @param {Node} node1 The first node to compare. - * @param {Node} node2 The second node to compare. - * @return {number} -1 if node1 is before node2, +1 otherwise. - * @private - */ -goog.dom.compareSiblingOrder_ = function(node1, node2) { - var s = node2; - while ((s = s.previousSibling)) { - if (s == node1) { - // We just found node1 before node2. - return -1; - } - } - - // Since we didn't find it, node1 must be after node2. - return 1; -}; - - -/** - * Find the deepest common ancestor of the given nodes. - * @param {...Node} var_args The nodes to find a common ancestor of. - * @return {Node} The common ancestor of the nodes, or null if there is none. - * null will only be returned if two or more of the nodes are from different - * documents. - */ -goog.dom.findCommonAncestor = function(var_args) { - var i, count = arguments.length; - if (!count) { - return null; - } else if (count == 1) { - return arguments[0]; - } - - var paths = []; - var minLength = Infinity; - for (i = 0; i < count; i++) { - // Compute the list of ancestors. - var ancestors = []; - var node = arguments[i]; - while (node) { - ancestors.unshift(node); - node = node.parentNode; - } - - // Save the list for comparison. - paths.push(ancestors); - minLength = Math.min(minLength, ancestors.length); - } - var output = null; - for (i = 0; i < minLength; i++) { - var first = paths[0][i]; - for (var j = 1; j < count; j++) { - if (first != paths[j][i]) { - return output; - } - } - output = first; - } - return output; -}; - - -/** - * Returns the owner document for a node. - * @param {Node|Window} node The node to get the document for. - * @return {!Document} The document owning the node. - */ -goog.dom.getOwnerDocument = function(node) { - // TODO(arv): Remove IE5 code. - // IE5 uses document instead of ownerDocument - return /** @type {!Document} */ ( - node.nodeType == goog.dom.NodeType.DOCUMENT ? node : - node.ownerDocument || node.document); -}; - - -/** - * Cross-browser function for getting the document element of a frame or iframe. - * @param {Element} frame Frame element. - * @return {!Document} The frame content document. - */ -goog.dom.getFrameContentDocument = function(frame) { - var doc = frame.contentDocument || frame.contentWindow.document; - return doc; -}; - - -/** - * Cross-browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. - * @return {Window} The window associated with the given frame. - */ -goog.dom.getFrameContentWindow = function(frame) { - return frame.contentWindow || - goog.dom.getWindow_(goog.dom.getFrameContentDocument(frame)); -}; - - -/** - * Cross-browser function for setting the text content of an element. - * @param {Element} element The element to change the text content of. - * @param {string} text The string that should replace the current element - * content. - */ -goog.dom.setTextContent = function(element, text) { - if ('textContent' in element) { - element.textContent = text; - } else if (element.firstChild && - element.firstChild.nodeType == goog.dom.NodeType.TEXT) { - // If the first child is a text node we just change its data and remove the - // rest of the children. - while (element.lastChild != element.firstChild) { - element.removeChild(element.lastChild); - } - element.firstChild.data = text; - } else { - goog.dom.removeChildren(element); - var doc = goog.dom.getOwnerDocument(element); - element.appendChild(doc.createTextNode(text)); - } -}; - - -/** - * Gets the outerHTML of a node, which islike innerHTML, except that it - * actually contains the HTML of the node itself. - * @param {Element} element The element to get the HTML of. - * @return {string} The outerHTML of the given element. - */ -goog.dom.getOuterHtml = function(element) { - // IE, Opera and WebKit all have outerHTML. - if ('outerHTML' in element) { - return element.outerHTML; - } else { - var doc = goog.dom.getOwnerDocument(element); - var div = doc.createElement('div'); - div.appendChild(element.cloneNode(true)); - return div.innerHTML; - } -}; - - -/** - * Finds the first descendant node that matches the filter function, using - * a depth first search. This function offers the most general purpose way - * of finding a matching element. You may also wish to consider - * {@code goog.dom.query} which can express many matching criteria using - * CSS selector expressions. These expressions often result in a more - * compact representation of the desired result. - * @see goog.dom.query - * - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Node|undefined} The found node or undefined if none is found. - */ -goog.dom.findNode = function(root, p) { - var rv = []; - var found = goog.dom.findNodes_(root, p, rv, true); - return found ? rv[0] : undefined; -}; - - -/** - * Finds all the descendant nodes that match the filter function, using a - * a depth first search. This function offers the most general-purpose way - * of finding a set of matching elements. You may also wish to consider - * {@code goog.dom.query} which can express many matching criteria using - * CSS selector expressions. These expressions often result in a more - * compact representation of the desired result. - - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Array.<Node>} The found nodes or an empty array if none are found. - */ -goog.dom.findNodes = function(root, p) { - var rv = []; - goog.dom.findNodes_(root, p, rv, false); - return rv; -}; - - -/** - * Finds the first or all the descendant nodes that match the filter function, - * using a depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @param {Array.<Node>} rv The found nodes are added to this array. - * @param {boolean} findOne If true we exit after the first found node. - * @return {boolean} Whether the search is complete or not. True in case findOne - * is true and the node is found. False otherwise. - * @private - */ -goog.dom.findNodes_ = function(root, p, rv, findOne) { - if (root != null) { - var child = root.firstChild; - while (child) { - if (p(child)) { - rv.push(child); - if (findOne) { - return true; - } - } - if (goog.dom.findNodes_(child, p, rv, findOne)) { - return true; - } - child = child.nextSibling; - } - } - return false; -}; - - -/** - * Map of tags whose content to ignore when calculating text length. - * @type {Object} - * @private - */ -goog.dom.TAGS_TO_IGNORE_ = { - 'SCRIPT': 1, - 'STYLE': 1, - 'HEAD': 1, - 'IFRAME': 1, - 'OBJECT': 1 -}; - - -/** - * Map of tags which have predefined values with regard to whitespace. - * @type {Object} - * @private - */ -goog.dom.PREDEFINED_TAG_VALUES_ = {'IMG': ' ', 'BR': '\n'}; - - -/** - * Returns true if the element has a tab index that allows it to receive - * keyboard focus (tabIndex >= 0), false otherwise. Note that form elements - * natively support keyboard focus, even if they have no tab index. - * @param {Element} element Element to check. - * @return {boolean} Whether the element has a tab index that allows keyboard - * focus. - * @see http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ - */ -goog.dom.isFocusableTabIndex = function(element) { - // IE returns 0 for an unset tabIndex, so we must use getAttributeNode(), - // which returns an object with a 'specified' property if tabIndex is - // specified. This works on other browsers, too. - var attrNode = element.getAttributeNode('tabindex'); // Must be lowercase! - if (attrNode && attrNode.specified) { - var index = element.tabIndex; - // NOTE: IE9 puts tabIndex in 16-bit int, e.g. -2 is 65534. - return goog.isNumber(index) && index >= 0 && index < 32768; - } - return false; -}; - - -/** - * Enables or disables keyboard focus support on the element via its tab index. - * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true - * (or elements that natively support keyboard focus, like form elements) can - * receive keyboard focus. See http://go/tabindex for more info. - * @param {Element} element Element whose tab index is to be changed. - * @param {boolean} enable Whether to set or remove a tab index on the element - * that supports keyboard focus. - */ -goog.dom.setFocusableTabIndex = function(element, enable) { - if (enable) { - element.tabIndex = 0; - } else { - // Set tabIndex to -1 first, then remove it. This is a workaround for - // Safari (confirmed in version 4 on Windows). When removing the attribute - // without setting it to -1 first, the element remains keyboard focusable - // despite not having a tabIndex attribute anymore. - element.tabIndex = -1; - element.removeAttribute('tabIndex'); // Must be camelCase! - } -}; - - -/** - * Returns the text content of the current node, without markup and invisible - * symbols. New lines are stripped and whitespace is collapsed, - * such that each character would be visible. - * - * In browsers that support it, innerText is used. Other browsers attempt to - * simulate it via node traversal. Line breaks are canonicalized in IE. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The text content. - */ -goog.dom.getTextContent = function(node) { - var textContent; - // Note(arv): IE9, Opera, and Safari 3 support innerText but they include - // text nodes in script tags. So we revert to use a user agent test here. - if (goog.dom.BrowserFeature.CAN_USE_INNER_TEXT && ('innerText' in node)) { - textContent = goog.string.canonicalizeNewlines(node.innerText); - // Unfortunately .innerText() returns text with ­ symbols - // We need to filter it out and then remove duplicate whitespaces - } else { - var buf = []; - goog.dom.getTextContent_(node, buf, true); - textContent = buf.join(''); - } - - // Strip ­ entities. goog.format.insertWordBreaks inserts them in Opera. - textContent = textContent.replace(/ \xAD /g, ' ').replace(/\xAD/g, ''); - // Strip ​ entities. goog.format.insertWordBreaks inserts them in IE8. - textContent = textContent.replace(/\u200B/g, ''); - - // Skip this replacement on old browsers with working innerText, which - // automatically turns into ' ' and / +/ into ' ' when reading - // innerText. - if (!goog.dom.BrowserFeature.CAN_USE_INNER_TEXT) { - textContent = textContent.replace(/ +/g, ' '); - } - if (textContent != ' ') { - textContent = textContent.replace(/^\s*/, ''); - } - - return textContent; -}; - - -/** - * Returns the text content of the current node, without markup. - * - * Unlike {@code getTextContent} this method does not collapse whitespaces - * or normalize lines breaks. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The raw text content. - */ -goog.dom.getRawTextContent = function(node) { - var buf = []; - goog.dom.getTextContent_(node, buf, false); - - return buf.join(''); -}; - - -/** - * Recursive support function for text content retrieval. - * - * @param {Node} node The node from which we are getting content. - * @param {Array} buf string buffer. - * @param {boolean} normalizeWhitespace Whether to normalize whitespace. - * @private - */ -goog.dom.getTextContent_ = function(node, buf, normalizeWhitespace) { - if (node.nodeName in goog.dom.TAGS_TO_IGNORE_) { - // ignore certain tags - } else if (node.nodeType == goog.dom.NodeType.TEXT) { - if (normalizeWhitespace) { - buf.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, '')); - } else { - buf.push(node.nodeValue); - } - } else if (node.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { - buf.push(goog.dom.PREDEFINED_TAG_VALUES_[node.nodeName]); - } else { - var child = node.firstChild; - while (child) { - goog.dom.getTextContent_(child, buf, normalizeWhitespace); - child = child.nextSibling; - } - } -}; - - -/** - * Returns the text length of the text contained in a node, without markup. This - * is equivalent to the selection length if the node was selected, or the number - * of cursor movements to traverse the node. Images & BRs take one space. New - * lines are ignored. - * - * @param {Node} node The node whose text content length is being calculated. - * @return {number} The length of {@code node}'s text content. - */ -goog.dom.getNodeTextLength = function(node) { - return goog.dom.getTextContent(node).length; -}; - - -/** - * Returns the text offset of a node relative to one of its ancestors. The text - * length is the same as the length calculated by goog.dom.getNodeTextLength. - * - * @param {Node} node The node whose offset is being calculated. - * @param {Node=} opt_offsetParent The node relative to which the offset will - * be calculated. Defaults to the node's owner document's body. - * @return {number} The text offset. - */ -goog.dom.getNodeTextOffset = function(node, opt_offsetParent) { - var root = opt_offsetParent || goog.dom.getOwnerDocument(node).body; - var buf = []; - while (node && node != root) { - var cur = node; - while ((cur = cur.previousSibling)) { - buf.unshift(goog.dom.getTextContent(cur)); - } - node = node.parentNode; - } - // Trim left to deal with FF cases when there might be line breaks and empty - // nodes at the front of the text - return goog.string.trimLeft(buf.join('')).replace(/ +/g, ' ').length; -}; - - -/** - * Returns the node at a given offset in a parent node. If an object is - * provided for the optional third parameter, the node and the remainder of the - * offset will stored as properties of this object. - * @param {Node} parent The parent node. - * @param {number} offset The offset into the parent node. - * @param {Object=} opt_result Object to be used to store the return value. The - * return value will be stored in the form {node: Node, remainder: number} - * if this object is provided. - * @return {Node} The node at the given offset. - */ -goog.dom.getNodeAtOffset = function(parent, offset, opt_result) { - var stack = [parent], pos = 0, cur; - while (stack.length > 0 && pos < offset) { - cur = stack.pop(); - if (cur.nodeName in goog.dom.TAGS_TO_IGNORE_) { - // ignore certain tags - } else if (cur.nodeType == goog.dom.NodeType.TEXT) { - var text = cur.nodeValue.replace(/(\r\n|\r|\n)/g, '').replace(/ +/g, ' '); - pos += text.length; - } else if (cur.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { - pos += goog.dom.PREDEFINED_TAG_VALUES_[cur.nodeName].length; - } else { - for (var i = cur.childNodes.length - 1; i >= 0; i--) { - stack.push(cur.childNodes[i]); - } - } - } - if (goog.isObject(opt_result)) { - opt_result.remainder = cur ? cur.nodeValue.length + offset - pos - 1 : 0; - opt_result.node = cur; - } - - return cur; -}; - - -/** - * Returns true if the object is a {@code NodeList}. To qualify as a NodeList, - * the object must have a numeric length property and an item function (which - * has type 'string' on IE for some reason). - * @param {Object} val Object to test. - * @return {boolean} Whether the object is a NodeList. - */ -goog.dom.isNodeList = function(val) { - // TODO(attila): Now the isNodeList is part of goog.dom we can use - // goog.userAgent to make this simpler. - // A NodeList must have a length property of type 'number' on all platforms. - if (val && typeof val.length == 'number') { - // A NodeList is an object everywhere except Safari, where it's a function. - if (goog.isObject(val)) { - // A NodeList must have an item function (on non-IE platforms) or an item - // property of type 'string' (on IE). - return typeof val.item == 'function' || typeof val.item == 'string'; - } else if (goog.isFunction(val)) { - // On Safari, a NodeList is a function with an item property that is also - // a function. - return typeof val.item == 'function'; - } - } - - // Not a NodeList. - return false; -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * tag name and/or class name. If the passed element matches the specified - * criteria, the element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) { - var tagName = opt_tag ? opt_tag.toUpperCase() : null; - return goog.dom.getAncestor(element, - function(node) { - return (!tagName || node.nodeName == tagName) && - (!opt_class || goog.dom.classes.has(node, opt_class)); - }, true); -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * class name. If the passed element matches the specified criteria, the - * element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.getAncestorByClass = function(element, opt_class) { - return goog.dom.getAncestorByTagNameAndClass(element, null, opt_class); -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that passes the - * matcher function. - * @param {Node} element The DOM node to start with. - * @param {function(Node) : boolean} matcher A function that returns true if the - * passed node matches the desired criteria. - * @param {boolean=} opt_includeNode If true, the node itself is included in - * the search (the first call to the matcher will pass startElement as - * the node to test). - * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the - * dom. - * @return {Node} DOM node that matched the matcher, or null if there was - * no match. - */ -goog.dom.getAncestor = function( - element, matcher, opt_includeNode, opt_maxSearchSteps) { - if (!opt_includeNode) { - element = element.parentNode; - } - var ignoreSearchSteps = opt_maxSearchSteps == null; - var steps = 0; - while (element && (ignoreSearchSteps || steps <= opt_maxSearchSteps)) { - if (matcher(element)) { - return element; - } - element = element.parentNode; - steps++; - } - // Reached the root of the DOM without a match - return null; -}; - - -/** - * Determines the active element in the given document. - * @param {Document} doc The document to look in. - * @return {Element} The active element. - */ -goog.dom.getActiveElement = function(doc) { - try { - return doc && doc.activeElement; - } catch (e) { - // NOTE(nicksantos): Sometimes, evaluating document.activeElement in IE - // throws an exception. I'm not 100% sure why, but I suspect it chokes - // on document.activeElement if the activeElement has been recently - // removed from the DOM by a JS operation. - // - // We assume that an exception here simply means - // "there is no active element." - } - - return null; -}; - - - -/** - * Create an instance of a DOM helper with a new document object. - * @param {Document=} opt_document Document object to associate with this - * DOM helper. - * @constructor - */ -goog.dom.DomHelper = function(opt_document) { - /** - * Reference to the document object to use - * @type {!Document} - * @private - */ - this.document_ = opt_document || goog.global.document || document; -}; - - -/** - * Gets the dom helper object for the document where the element resides. - * @param {Node=} opt_node If present, gets the DomHelper for this node. - * @return {!goog.dom.DomHelper} The DomHelper. - */ -goog.dom.DomHelper.prototype.getDomHelper = goog.dom.getDomHelper; - - -/** - * Sets the document object. - * @param {!Document} document Document object. - */ -goog.dom.DomHelper.prototype.setDocument = function(document) { - this.document_ = document; -}; - - -/** - * Gets the document object being used by the dom library. - * @return {!Document} Document object. - */ -goog.dom.DomHelper.prototype.getDocument = function() { - return this.document_; -}; - - -/** - * Alias for {@code getElementById}. If a DOM node is passed in then we just - * return that. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - */ -goog.dom.DomHelper.prototype.getElement = function(element) { - if (goog.isString(element)) { - return this.document_.getElementById(element); - } else { - return element; - } -}; - - -/** - * Alias for {@code getElement}. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - * @deprecated Use {@link goog.dom.DomHelper.prototype.getElement} instead. - */ -goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement; - - -/** - * Looks up elements by both tag and class name, using browser native functions - * ({@code querySelectorAll}, {@code getElementsByTagName} or - * {@code getElementsByClassName}) where possible. The returned array is a live - * NodeList or a static list depending on the code path taken. - * - * @see goog.dom.query - * - * @param {?string=} opt_tag Element tag name or * for all tags. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.DomHelper.prototype.getElementsByTagNameAndClass = function(opt_tag, - opt_class, - opt_el) { - return goog.dom.getElementsByTagNameAndClass_(this.document_, opt_tag, - opt_class, opt_el); -}; - - -/** - * Returns an array of all the elements with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return { {length: number} } The items found with the class name provided. - */ -goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) { - var doc = opt_el || this.document_; - return goog.dom.getElementsByClass(className, doc); -}; - - -/** - * Returns the first element we find matching the provided class name. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return {Element} The first item found with the class name provided. - */ -goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) { - var doc = opt_el || this.document_; - return goog.dom.getElementByClass(className, doc); -}; - - -/** - * Alias for {@code getElementsByTagNameAndClass}. - * @deprecated Use DomHelper getElementsByTagNameAndClass. - * @see goog.dom.query - * - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.DomHelper.prototype.$$ = - goog.dom.DomHelper.prototype.getElementsByTagNameAndClass; - - -/** - * Sets a number of properties on a node. - * @param {Element} element DOM node to set properties on. - * @param {Object} properties Hash of property:value pairs. - */ -goog.dom.DomHelper.prototype.setProperties = goog.dom.setProperties; - - -/** - * Gets the dimensions of the viewport. - * @param {Window=} opt_window Optional window element to test. Defaults to - * the window of the Dom Helper. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - */ -goog.dom.DomHelper.prototype.getViewportSize = function(opt_window) { - // TODO(arv): This should not take an argument. That breaks the rule of a - // a DomHelper representing a single frame/window/document. - return goog.dom.getViewportSize(opt_window || this.getWindow()); -}; - - -/** - * Calculates the height of the document. - * - * @return {number} The height of the document. - */ -goog.dom.DomHelper.prototype.getDocumentHeight = function() { - return goog.dom.getDocumentHeight_(this.getWindow()); -}; - - -/** - * Typedef for use with goog.dom.createDom and goog.dom.append. - * @typedef {Object|string|Array|NodeList} - */ -goog.dom.Appendable; - - -/** - * Returns a dom node with a set of attributes. This function accepts varargs - * for subsequent nodes to be added. Subsequent nodes will be added to the - * first node as childNodes. - * - * So: - * <code>createDom('div', null, createDom('p'), createDom('p'));</code> - * would return a div with two child paragraphs - * - * An easy way to move all child nodes of an existing element to a new parent - * element is: - * <code>createDom('div', null, oldElement.childNodes);</code> - * which will remove all child nodes from the old element and add them as - * child nodes of the new DIV. - * - * @param {string} tagName Tag to create. - * @param {Object|string=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...goog.dom.Appendable} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array or - * NodeList, its elements will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - */ -goog.dom.DomHelper.prototype.createDom = function(tagName, - opt_attributes, - var_args) { - return goog.dom.createDom_(this.document_, arguments); -}; - - -/** - * Alias for {@code createDom}. - * @param {string} tagName Tag to create. - * @param {Object|string=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for - * text nodes. If one of the var_args is an array, its children will be - * added as childNodes instead. - * @return {!Element} Reference to a DOM node. - * @deprecated Use {@link goog.dom.DomHelper.prototype.createDom} instead. - */ -goog.dom.DomHelper.prototype.$dom = goog.dom.DomHelper.prototype.createDom; - - -/** - * Creates a new element. - * @param {string} name Tag name. - * @return {!Element} The new element. - */ -goog.dom.DomHelper.prototype.createElement = function(name) { - return this.document_.createElement(name); -}; - - -/** - * Creates a new text node. - * @param {string} content Content. - * @return {!Text} The new text node. - */ -goog.dom.DomHelper.prototype.createTextNode = function(content) { - return this.document_.createTextNode(content); -}; - - -/** - * Create a table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - */ -goog.dom.DomHelper.prototype.createTable = function(rows, columns, - opt_fillWithNbsp) { - return goog.dom.createTable_(this.document_, rows, columns, - !!opt_fillWithNbsp); -}; - - -/** - * Converts an HTML string into a node or a document fragment. A single Node - * is used if the {@code htmlString} only generates a single node. If the - * {@code htmlString} generates multiple nodes then these are put inside a - * {@code DocumentFragment}. - * - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting node. - */ -goog.dom.DomHelper.prototype.htmlToDocumentFragment = function(htmlString) { - return goog.dom.htmlToDocumentFragment_(this.document_, htmlString); -}; - - -/** - * Returns the compatMode of the document. - * @return {string} The result is either CSS1Compat or BackCompat. - * @deprecated use goog.dom.DomHelper.prototype.isCss1CompatMode instead. - */ -goog.dom.DomHelper.prototype.getCompatMode = function() { - return this.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat'; -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @return {boolean} True if in CSS1-compatible mode. - */ -goog.dom.DomHelper.prototype.isCss1CompatMode = function() { - return goog.dom.isCss1CompatMode_(this.document_); -}; - - -/** - * Gets the window object associated with the document. - * @return {!Window} The window associated with the given document. - */ -goog.dom.DomHelper.prototype.getWindow = function() { - return goog.dom.getWindow_(this.document_); -}; - - -/** - * Gets the document scroll element. - * @return {Element} Scrolling element. - */ -goog.dom.DomHelper.prototype.getDocumentScrollElement = function() { - return goog.dom.getDocumentScrollElement_(this.document_); -}; - - -/** - * Gets the document scroll distance as a coordinate object. - * @return {!goog.math.Coordinate} Object with properties 'x' and 'y'. - */ -goog.dom.DomHelper.prototype.getDocumentScroll = function() { - return goog.dom.getDocumentScroll_(this.document_); -}; - - -/** - * Appends a child to a node. - * @param {Node} parent Parent. - * @param {Node} child Child. - */ -goog.dom.DomHelper.prototype.appendChild = goog.dom.appendChild; - - -/** - * Appends a node with text or other nodes. - * @param {!Node} parent The node to append nodes to. - * @param {...goog.dom.Appendable} var_args The things to append to the node. - * If this is a Node it is appended as is. - * If this is a string then a text node is appended. - * If this is an array like object then fields 0 to length - 1 are appended. - */ -goog.dom.DomHelper.prototype.append = goog.dom.append; - - -/** - * Removes all the child nodes on a DOM node. - * @param {Node} node Node to remove children from. - */ -goog.dom.DomHelper.prototype.removeChildren = goog.dom.removeChildren; - - -/** - * Inserts a new node before an existing reference node (i.e., as the previous - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert before. - */ -goog.dom.DomHelper.prototype.insertSiblingBefore = goog.dom.insertSiblingBefore; - - -/** - * Inserts a new node after an existing reference node (i.e., as the next - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert after. - */ -goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter; - - -/** - * Removes a node from its parent. - * @param {Node} node The node to remove. - * @return {Node} The node removed if removed; else, null. - */ -goog.dom.DomHelper.prototype.removeNode = goog.dom.removeNode; - - -/** - * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no - * parent. - * @param {Node} newNode Node to insert. - * @param {Node} oldNode Node to replace. - */ -goog.dom.DomHelper.prototype.replaceNode = goog.dom.replaceNode; - - -/** - * Flattens an element. That is, removes it and replace it with its children. - * @param {Element} element The element to flatten. - * @return {Element|undefined} The original element, detached from the document - * tree, sans children, or undefined if the element was already not in the - * document. - */ -goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement; - - -/** - * Returns the first child node that is an element. - * @param {Node} node The node to get the first child element of. - * @return {Element} The first child node of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getFirstElementChild = - goog.dom.getFirstElementChild; - - -/** - * Returns the last child node that is an element. - * @param {Node} node The node to get the last child element of. - * @return {Element} The last child node of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getLastElementChild = goog.dom.getLastElementChild; - - -/** - * Returns the first next sibling that is an element. - * @param {Node} node The node to get the next sibling element of. - * @return {Element} The next sibling of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getNextElementSibling = - goog.dom.getNextElementSibling; - - -/** - * Returns the first previous sibling that is an element. - * @param {Node} node The node to get the previous sibling element of. - * @return {Element} The first previous sibling of {@code node} that is - * an element. - */ -goog.dom.DomHelper.prototype.getPreviousElementSibling = - goog.dom.getPreviousElementSibling; - - -/** - * Returns the next node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The next node in the DOM tree, or null if this was the last - * node. - */ -goog.dom.DomHelper.prototype.getNextNode = - goog.dom.getNextNode; - - -/** - * Returns the previous node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The previous node in the DOM tree, or null if this was the - * first node. - */ -goog.dom.DomHelper.prototype.getPreviousNode = - goog.dom.getPreviousNode; - - -/** - * Whether the object looks like a DOM node. - * @param {*} obj The object being tested for node likeness. - * @return {boolean} Whether the object looks like a DOM node. - */ -goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike; - - -/** - * Whether a node contains another node. - * @param {Node} parent The node that should contain the other node. - * @param {Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendent node. - */ -goog.dom.DomHelper.prototype.contains = goog.dom.contains; - - -/** - * Returns the owner document for a node. - * @param {Node} node The node to get the document for. - * @return {!Document} The document owning the node. - */ -goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument; - - -/** - * Cross browser function for getting the document element of an iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} iframe Iframe element. - * @return {!HTMLDocument} The frame content document. - */ -goog.dom.DomHelper.prototype.getFrameContentDocument = - goog.dom.getFrameContentDocument; - - -/** - * Cross browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. - * @return {Window} The window associated with the given frame. - */ -goog.dom.DomHelper.prototype.getFrameContentWindow = - goog.dom.getFrameContentWindow; - - -/** - * Cross browser function for setting the text content of an element. - * @param {Element} element The element to change the text content of. - * @param {string} text The string that should replace the current element - * content with. - */ -goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent; - - -/** - * Finds the first descendant node that matches the filter function. This does - * a depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {(Node, undefined)} The found node or undefined if none is found. - */ -goog.dom.DomHelper.prototype.findNode = goog.dom.findNode; - - -/** - * Finds all the descendant nodes that matches the filter function. This does a - * depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Array.<Node>} The found nodes or an empty array if none are found. - */ -goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes; - - -/** - * Returns the text contents of the current node, without markup. New lines are - * stripped and whitespace is collapsed, such that each character would be - * visible. - * - * In browsers that support it, innerText is used. Other browsers attempt to - * simulate it via node traversal. Line breaks are canonicalized in IE. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The text content. - */ -goog.dom.DomHelper.prototype.getTextContent = goog.dom.getTextContent; - - -/** - * Returns the text length of the text contained in a node, without markup. This - * is equivalent to the selection length if the node was selected, or the number - * of cursor movements to traverse the node. Images & BRs take one space. New - * lines are ignored. - * - * @param {Node} node The node whose text content length is being calculated. - * @return {number} The length of {@code node}'s text content. - */ -goog.dom.DomHelper.prototype.getNodeTextLength = goog.dom.getNodeTextLength; - - -/** - * Returns the text offset of a node relative to one of its ancestors. The text - * length is the same as the length calculated by - * {@code goog.dom.getNodeTextLength}. - * - * @param {Node} node The node whose offset is being calculated. - * @param {Node=} opt_offsetParent Defaults to the node's owner document's body. - * @return {number} The text offset. - */ -goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * tag name and/or class name. If the passed element matches the specified - * criteria, the element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass = - goog.dom.getAncestorByTagNameAndClass; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * class name. If the passed element matches the specified criteria, the - * element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.DomHelper.prototype.getAncestorByClass = - goog.dom.getAncestorByClass; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that passes the - * matcher function. - * @param {Node} element The DOM node to start with. - * @param {function(Node) : boolean} matcher A function that returns true if the - * passed node matches the desired criteria. - * @param {boolean=} opt_includeNode If true, the node itself is included in - * the search (the first call to the matcher will pass startElement as - * the node to test). - * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the - * dom. - * @return {Node} DOM node that matched the matcher, or null if there was - * no match. - */ -goog.dom.DomHelper.prototype.getAncestor = goog.dom.getAncestor; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base deleted file mode 100644 index 523179b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base +++ /dev/null @@ -1,108 +0,0 @@ -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - This is a copy of dom_test.html but without a doctype. Make sure these two - are in sync. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div> - abc <i>def</i> <s id="offsetParent1">g <b>h <i id="offsetTest1">ij</i> kl</b> mn</s> opq - </div> - - - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <!-- classbefore and classafter are for making sure that getElementsByClass - works when multiple classes are specified. --> - <div id="span-container"> - <span id="span1" class="classbefore test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1 classafter"></span> - </div> - - <div class="mixedCaseClass"></div> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - - <table id="testTable1"> - <tr> - <td> - </tr> - </table> - - <iframe name="frame" src="tagname_test.html"></iframe> - - <p id="order-test"></p> - - <div id="testAncestorDiv" class="ancestorClassA testAncestor"> - <p id="testAncestorP" class="ancestorClassB testAncestor"> - <b id="nestedElement">ancestorTest</b> - </p> - </div> - - <div id="noTabIndex">Test</div> - <div id="tabIndexNegative2" tabindex="-2">Test</div> - <div id="tabIndexNegative1" tabindex="-1">Test</div> - <div id="tabIndex0" tabindex="0">Test</div> - <div id="tabIndex1" tabindex="1">Test</div> - <div id="tabIndex2" tabindex="2">Test</div> - - <div id="toReplace">Replace Test</div> - - <iframe id="iframe"></iframe> - - <div id="myIframeDiv1" style="height:42px;font-size:1px;line-height:0;">hello world</div> - <div id="myIframeDiv2" style="height:23px;font-size:1px;line-height:0;">hello world</div> - - <iframe id="myIframe" style="width:400px;height:200px;"></iframe> - - <a id='link' href='foo.html'>Foo</a> - -<script src="dom_test.js"></script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base deleted file mode 100644 index d55c850..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base +++ /dev/null @@ -1,107 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - When changing this, make sure that dom_quirks_test.html is kept in sync. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div> - abc <i>def</i> <s id="offsetParent1">g <b>h <i id="offsetTest1">ij</i> kl</b> mn</s> opq - </div> - - - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <!-- classbefore and classafter are for making sure that getElementsByClass - works when multiple classes are specified. --> - <div id="span-container"> - <span id="span1" class="classbefore test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1 classafter"></span> - </div> - - <div class="mixedCaseClass"></div> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - - <table id="testTable1"> - <tr> - <td> - </tr> - </table> - - <iframe name="frame" src="tagname_test.html"></iframe> - - <p id="order-test"></p> - - <div id="testAncestorDiv" class="ancestorClassA testAncestor"> - <p id="testAncestorP" class="ancestorClassB testAncestor"> - <b id="nestedElement">ancestorTest</b> - </p> - </div> - - <div id="noTabIndex">Test</div> - <div id="tabIndexNegative2" tabindex="-2">Test</div> - <div id="tabIndexNegative1" tabindex="-1">Test</div> - <div id="tabIndex0" tabindex="0">Test</div> - <div id="tabIndex1" tabindex="1">Test</div> - <div id="tabIndex2" tabindex="2">Test</div> - - <div id="toReplace">Replace Test</div> - - <iframe id="iframe"></iframe> - - <div id="myIframeDiv1" style="height:42px;font-size:1px;line-height:0;">hello world</div> - <div id="myIframeDiv2" style="height:23px;font-size:1px;line-height:0;">hello world</div> - - <iframe id="myIframe" style="width:400px;height:200px;"></iframe> - - <a id='link' href='foo.html'>Foo</a> - -<script src="dom_test.js"></script></body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base deleted file mode 100644 index 614ff12..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base +++ /dev/null @@ -1,1349 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Shared code for dom_test.html and dom_quirks_test.html. - */ - -goog.provide('goog.dom.dom_test'); - -goog.require('goog.dom'); -goog.require('goog.dom.DomHelper'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.TagName'); -goog.require('goog.testing.asserts'); -goog.require('goog.userAgent'); -goog.require('goog.userAgent.product'); -goog.require('goog.userAgent.product.isVersion'); - -goog.setTestOnly('dom_test'); - -var $ = goog.dom.getElement; - -var divForTestingScrolling; -var myIframe; -var myIframeDoc; - -function setUpPage() { - divForTestingScrolling = document.createElement('div'); - divForTestingScrolling.style.width = '5000px'; - divForTestingScrolling.style.height = '5000px'; - document.body.appendChild(divForTestingScrolling); - - // Setup for the iframe - myIframe = $('myIframe'); - myIframeDoc = goog.dom.getFrameContentDocument( - /** @type {HTMLIFrameElement} */ (myIframe)); - - // Set up document for iframe: total height of elements in document is 65 - // If the elements are not create like below, IE will get a wrong height for - // the document. - myIframeDoc.open(); - // Make sure we progate the compat mode - myIframeDoc.write((goog.dom.isCss1CompatMode() ? '<!DOCTYPE html>' : '') + - '<style>body{margin:0;padding:0}</style>' + - '<div style="height:42px;font-size:1px;line-height:0;">' + - 'hello world</div>' + - '<div style="height:23px;font-size:1px;line-height:0;">' + - 'hello world</div>'); - myIframeDoc.close(); -} - -function tearDownPage() { - document.body.removeChild(divForTestingScrolling); -} - -function tearDown() { - window.scrollTo(0, 0); -} - -function testDom() { - assert('Dom library exists', typeof goog.dom != 'undefined'); -} - -function testGetElement() { - var el = $('testEl'); - assertEquals('Should be able to get id', el.id, 'testEl'); - - assertEquals($, goog.dom.getElement); - assertEquals(goog.dom.$, goog.dom.getElement); -} - -function testGetElementsByTagNameAndClass() { - assertEquals('Should get 6 spans', - goog.dom.getElementsByTagNameAndClass('span').length, 6); - assertEquals('Should get 6 spans', - goog.dom.getElementsByTagNameAndClass('SPAN').length, 6); - assertEquals('Should get 3 spans', - goog.dom.getElementsByTagNameAndClass('span', 'test1').length, 3); - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('span', 'test2').length, 1); - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('SPAN', 'test2').length, 1); - assertEquals('Should get lots of elements', - goog.dom.getElementsByTagNameAndClass().length, - document.getElementsByTagName('*').length); - - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('span', null, $('testEl')).length, - 1); - - // '*' as the tag name should be equivalent to all tags - var container = goog.dom.getElement('span-container'); - assertEquals(5, - goog.dom.getElementsByTagNameAndClass('*', undefined, container).length); - assertEquals(3, - goog.dom.getElementsByTagNameAndClass('*', 'test1', container).length); - assertEquals(1, - goog.dom.getElementsByTagNameAndClass('*', 'test2', container).length); - - // Some version of WebKit have problems with mixed-case class names - assertEquals(1, - goog.dom.getElementsByTagNameAndClass( - undefined, 'mixedCaseClass').length); - - // Make sure that out of bounds indices are OK - assertUndefined( - goog.dom.getElementsByTagNameAndClass(undefined, 'noSuchClass')[0]); - - assertEquals(goog.dom.getElementsByTagNameAndClass, - goog.dom.getElementsByTagNameAndClass); -} - -function testGetElementsByClass() { - assertEquals(3, goog.dom.getElementsByClass('test1').length); - assertEquals(1, goog.dom.getElementsByClass('test2').length); - assertEquals(0, goog.dom.getElementsByClass('nonexistant').length); - - var container = goog.dom.getElement('span-container'); - assertEquals(3, goog.dom.getElementsByClass('test1', container).length); -} - -function testGetElementByClass() { - assertNotNull(goog.dom.getElementByClass('test1')); - assertNotNull(goog.dom.getElementByClass('test2')); - // assertNull(goog.dom.getElementByClass('nonexistant')); - - var container = goog.dom.getElement('span-container'); - assertNotNull(goog.dom.getElementByClass('test1', container)); -} - -function testSetProperties() { - var attrs = { 'name': 'test3', 'title': 'A title', 'random': 'woop' }; - var el = $('testEl'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', el.name, 'test3'); - assertEquals('Should be equal', el.title, 'A title'); - assertEquals('Should be equal', el.random, 'woop'); -} - -function testSetPropertiesDirectAttributeMap() { - var attrs = {'usemap': '#myMap'}; - var el = goog.dom.createDom('img'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', '#myMap', el.getAttribute('usemap')); -} - -function testSetPropertiesAria() { - var attrs = { - 'aria-hidden': 'true', - 'aria-label': 'This is a label' - }; - var el = goog.dom.createDom('div'); - - goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', 'true', el.getAttribute('aria-hidden')); - assertEquals('Should be equal', - 'This is a label', el.getAttribute('aria-label')); -} - -function testSetTableProperties() { - var attrs = { - 'style': 'padding-left: 10px;', - 'class': 'mytestclass', - 'height': '101', - 'cellpadding': '15' - }; - var el = $('testTable1'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', el.style.paddingLeft, '10px'); - assertEquals('Should be equal', el.className, 'mytestclass'); - assertEquals('Should be equal', el.getAttribute('height'), '101'); - assertEquals('Should be equal', el.cellPadding, '15'); -} - -function testGetViewportSize() { - // TODO: This is failing in the test runner now, fix later. - //var dims = getViewportSize(); - //assertNotUndefined('Should be defined at least', dims.width); - //assertNotUndefined('Should be defined at least', dims.height); -} - -function testGetViewportSizeInIframe() { - var iframe = /** @type {HTMLIFrameElement} */ (goog.dom.getElement('iframe')); - var contentDoc = goog.dom.getFrameContentDocument(iframe); - contentDoc.write('<body></body>'); - - var outerSize = goog.dom.getViewportSize(); - var innerSize = (new goog.dom.DomHelper(contentDoc)).getViewportSize(); - assert('Viewport sizes must not match', - innerSize.width != outerSize.width); -} - -function testGetDocumentHeightInIframe() { - var doc = goog.dom.getDomHelper(myIframeDoc).getDocument(); - var height = goog.dom.getDomHelper(myIframeDoc).getDocumentHeight(); - - // Broken in webkit quirks mode and in IE8+ - if ((goog.dom.isCss1CompatMode_(doc) || !goog.userAgent.WEBKIT) && - !isIE8OrHigher()) { - assertEquals('height should be 65', 42 + 23, height); - } -} - -function testCreateDom() { - var el = goog.dom.$dom('div', - { - style: 'border: 1px solid black; width: 50%; background-color: #EEE;', - onclick: "alert('woo')" - }, - goog.dom.$dom('p', {style: 'font: normal 12px arial; color: red; '}, - 'Para 1'), - goog.dom.$dom('p', {style: 'font: bold 18px garamond; color: blue; '}, - 'Para 2'), - goog.dom.$dom('p', {style: 'font: normal 24px monospace; color: green'}, - 'Para 3 ', - goog.dom.$dom('a', { - name: 'link', href: 'http://bbc.co.uk' - }, - 'has a link'), - ', how cool is this?')); - - assertEquals('Tagname should be a DIV', 'DIV', el.tagName); - assertEquals('Style width should be 50%', '50%', el.style.width); - assertEquals('first child is a P tag', 'P', el.childNodes[0].tagName); - assertEquals('second child .innerHTML', 'Para 2', - el.childNodes[1].innerHTML); - - assertEquals(goog.dom.$dom, goog.dom.createDom); -} - -function testCreateDomNoChildren() { - var el; - - // Test unspecified children. - el = goog.dom.$dom('div'); - assertNull('firstChild should be null', el.firstChild); - - // Test null children. - el = goog.dom.$dom('div', null, null); - assertNull('firstChild should be null', el.firstChild); - - // Test empty array of children. - el = goog.dom.$dom('div', null, []); - assertNull('firstChild should be null', el.firstChild); -} - -function testCreateDomAcceptsArray() { - var items = [ - goog.dom.$dom('li', {}, 'Item 1'), - goog.dom.$dom('li', {}, 'Item 2') - ]; - var ul = goog.dom.$dom('ul', {}, items); - assertEquals('List should have two children', 2, ul.childNodes.length); - assertEquals('First child should be an LI tag', - 'LI', ul.firstChild.tagName); - assertEquals('Item 1', ul.childNodes[0].innerHTML); - assertEquals('Item 2', ul.childNodes[1].innerHTML); -} - -function testCreateDomStringArg() { - var el; - - // Test string arg. - el = goog.dom.$dom('div', null, 'Hello'); - assertEquals('firstChild should be a text node', goog.dom.NodeType.TEXT, - el.firstChild.nodeType); - assertEquals('firstChild should have node value "Hello"', 'Hello', - el.firstChild.nodeValue); - - // Test text node arg. - el = goog.dom.$dom('div', null, goog.dom.createTextNode('World')); - assertEquals('firstChild should be a text node', goog.dom.NodeType.TEXT, - el.firstChild.nodeType); - assertEquals('firstChild should have node value "World"', 'World', - el.firstChild.nodeValue); -} - -function testCreateDomNodeListArg() { - var el; - var emptyElem = goog.dom.$dom('div'); - var simpleElem = goog.dom.$dom('div', null, 'Hello, world!'); - var complexElem = goog.dom.$dom('div', null, 'Hello, ', - goog.dom.$dom('b', null, 'world'), - goog.dom.createTextNode('!')); - - // Test empty node list. - el = goog.dom.$dom('div', null, emptyElem.childNodes); - assertNull('emptyElem.firstChild should be null', emptyElem.firstChild); - assertNull('firstChild should be null', el.firstChild); - - // Test simple node list. - el = goog.dom.$dom('div', null, simpleElem.childNodes); - assertNull('simpleElem.firstChild should be null', simpleElem.firstChild); - assertEquals('firstChild should be a text node with value "Hello, world!"', - 'Hello, world!', el.firstChild.nodeValue); - - // Test complex node list. - el = goog.dom.$dom('div', null, complexElem.childNodes); - assertNull('complexElem.firstChild should be null', complexElem.firstChild); - assertEquals('Element should have 3 child nodes', 3, el.childNodes.length); - assertEquals('childNodes[0] should be a text node with value "Hello, "', - 'Hello, ', el.childNodes[0].nodeValue); - assertEquals('childNodes[1] should be an element node with tagName "B"', - 'B', el.childNodes[1].tagName); - assertEquals('childNodes[2] should be a text node with value "!"', '!', - el.childNodes[2].nodeValue); -} - -function testCreateDomWithTypeAttribute() { - var el = goog.dom.createDom('button', {'type': 'reset', 'id': 'cool-button'}, - 'Cool button'); - assertNotNull('Button with type attribute was created successfully', el); - assertEquals('Button has correct type attribute', 'reset', el.type); - assertEquals('Button has correct id', 'cool-button', el.id); -} - -function testCreateDomWithClassList() { - var el = goog.dom.createDom('div', ['foo', 'bar']); - assertEquals('foo bar', el.className); - - el = goog.dom.createDom('div', ['foo', 'foo']); - assertEquals('foo', el.className); -} - -function testContains() { - assertTrue('HTML should contain BODY', goog.dom.contains( - document.documentElement, document.body)); - assertTrue('Document should contain BODY', goog.dom.contains( - document, document.body)); - - var d = goog.dom.$dom('p', null, 'A paragraph'); - var t = d.firstChild; - assertTrue('Same element', goog.dom.contains(d, d)); - assertTrue('Same text', goog.dom.contains(t, t)); - assertTrue('Nested text', goog.dom.contains(d, t)); - assertFalse('Nested text, reversed', goog.dom.contains(t, d)); - assertFalse('Disconnected element', goog.dom.contains( - document, d)); - goog.dom.appendChild(document.body, d); - assertTrue('Connected element', goog.dom.contains( - document, d)); - goog.dom.removeNode(d); -} - -function testCreateDomWithClassName() { - var el = goog.dom.$dom('div', 'cls'); - assertNull('firstChild should be null', el.firstChild); - assertEquals('Tagname should be a DIV', 'DIV', el.tagName); - assertEquals('ClassName should be cls', 'cls', el.className); - - el = goog.dom.$dom('div', ''); - assertEquals('ClassName should be empty', '', el.className); -} - -function testCompareNodeOrder() { - var b1 = $('b1'); - var b2 = $('b2'); - var p2 = $('p2'); - - assertEquals('equal nodes should compare to 0', 0, - goog.dom.compareNodeOrder(b1, b1)); - - assertTrue('parent should come before child', - goog.dom.compareNodeOrder(p2, b1) < 0); - assertTrue('child should come after parent', - goog.dom.compareNodeOrder(b1, p2) > 0); - - assertTrue('parent should come before text child', - goog.dom.compareNodeOrder(b1, b1.firstChild) < 0); - assertTrue('text child should come after parent', goog.dom.compareNodeOrder( - b1.firstChild, b1) > 0); - - assertTrue('first sibling should come before second', - goog.dom.compareNodeOrder(b1, b2) < 0); - assertTrue('second sibling should come after first', - goog.dom.compareNodeOrder(b2, b1) > 0); - - assertTrue('text node after cousin element returns correct value', - goog.dom.compareNodeOrder(b1.nextSibling, b1) > 0); - assertTrue('text node before cousin element returns correct value', - goog.dom.compareNodeOrder(b1, b1.nextSibling) < 0); - - assertTrue('text node is before once removed cousin element', - goog.dom.compareNodeOrder(b1.firstChild, b2) < 0); - assertTrue('once removed cousin element is before text node', - goog.dom.compareNodeOrder(b2, b1.firstChild) > 0); - - assertTrue('text node is after once removed cousin text node', - goog.dom.compareNodeOrder(b1.nextSibling, b1.firstChild) > 0); - assertTrue('once removed cousin text node is before text node', - goog.dom.compareNodeOrder(b1.firstChild, b1.nextSibling) < 0); - - assertTrue('first text node is before second text node', - goog.dom.compareNodeOrder(b1.previousSibling, b1.nextSibling) < 0); - assertTrue('second text node is after first text node', - goog.dom.compareNodeOrder(b1.nextSibling, b1.previousSibling) > 0); - - assertTrue('grandchild is after grandparent', - goog.dom.compareNodeOrder(b1.firstChild, b1.parentNode) > 0); - assertTrue('grandparent is after grandchild', - goog.dom.compareNodeOrder(b1.parentNode, b1.firstChild) < 0); - - assertTrue('grandchild is after grandparent', - goog.dom.compareNodeOrder(b1.firstChild, b1.parentNode) > 0); - assertTrue('grandparent is after grandchild', - goog.dom.compareNodeOrder(b1.parentNode, b1.firstChild) < 0); - - assertTrue('second cousins compare correctly', - goog.dom.compareNodeOrder(b1.firstChild, b2.firstChild) < 0); - assertTrue('second cousins compare correctly in reverse', - goog.dom.compareNodeOrder(b2.firstChild, b1.firstChild) > 0); - - assertTrue('testEl2 is after testEl', - goog.dom.compareNodeOrder($('testEl2'), $('testEl')) > 0); - assertTrue('testEl is before testEl2', - goog.dom.compareNodeOrder($('testEl'), $('testEl2')) < 0); - - var p = $('order-test'); - var text1 = document.createTextNode('1'); - p.appendChild(text1); - var text2 = document.createTextNode('1'); - p.appendChild(text2); - - assertEquals('Equal text nodes should compare to 0', 0, - goog.dom.compareNodeOrder(text1, text1)); - assertTrue('First text node is before second', - goog.dom.compareNodeOrder(text1, text2) < 0); - assertTrue('Second text node is after first', - goog.dom.compareNodeOrder(text2, text1) > 0); - assertTrue('Late text node is after b1', - goog.dom.compareNodeOrder(text1, $('b1')) > 0); -} - -function testFindCommonAncestor() { - var b1 = $('b1'); - var b2 = $('b2'); - var p1 = $('p1'); - var p2 = $('p2'); - var testEl2 = $('testEl2'); - - assertNull('findCommonAncestor() = null', goog.dom.findCommonAncestor()); - assertEquals('findCommonAncestor(b1) = b1', b1, - goog.dom.findCommonAncestor(b1)); - assertEquals('findCommonAncestor(b1, b1) = b1', b1, - goog.dom.findCommonAncestor(b1, b1)); - assertEquals('findCommonAncestor(b1, b2) = p2', p2, - goog.dom.findCommonAncestor(b1, b2)); - assertEquals('findCommonAncestor(p1, b2) = body', document.body, - goog.dom.findCommonAncestor(p1, b2)); - assertEquals('findCommonAncestor(testEl2, b1, b2, p1, p2) = body', - document.body, goog.dom.findCommonAncestor(testEl2, b1, b2, p1, p2)); - - var outOfDoc = document.createElement('div'); - assertNull('findCommonAncestor(outOfDoc, b1) = null', - goog.dom.findCommonAncestor(outOfDoc, b1)); -} - -function testRemoveNode() { - var b = document.createElement('b'); - var el = $('p1'); - el.appendChild(b); - goog.dom.removeNode(b); - assertTrue('b should have been removed', el.lastChild != b); -} - -function testReplaceNode() { - var n = $('toReplace'); - var previousSibling = n.previousSibling; - var goodNode = goog.dom.createDom('div', {'id': 'goodReplaceNode'}); - goog.dom.replaceNode(goodNode, n); - - assertEquals('n should have been replaced', previousSibling.nextSibling, - goodNode); - assertNull('n should no longer be in the DOM tree', $('toReplace')); - - var badNode = goog.dom.createDom('div', {'id': 'badReplaceNode'}); - goog.dom.replaceNode(badNode, n); - assertNull('badNode should not be in the DOM tree', $('badReplaceNode')); -} - -function testAppendChildAt() { - var parent = $('p2'); - var origNumChildren = parent.childNodes.length; - - var child1 = document.createElement('div'); - goog.dom.insertChildAt(parent, child1, origNumChildren); - assertEquals(origNumChildren + 1, parent.childNodes.length); - - var child2 = document.createElement('div'); - goog.dom.insertChildAt(parent, child2, origNumChildren + 42); - assertEquals(origNumChildren + 2, parent.childNodes.length); - - var child3 = document.createElement('div'); - goog.dom.insertChildAt(parent, child3, 0); - assertEquals(origNumChildren + 3, parent.childNodes.length); - - var child4 = document.createElement('div'); - goog.dom.insertChildAt(parent, child3, 2); - assertEquals(origNumChildren + 3, parent.childNodes.length); - - parent.removeChild(child1); - parent.removeChild(child2); - parent.removeChild(child3); - - var emptyParentNotInDocument = document.createElement('div'); - goog.dom.insertChildAt(emptyParentNotInDocument, child1, 0); - assertEquals(1, emptyParentNotInDocument.childNodes.length); -} - -function testFlattenElement() { - var text = document.createTextNode('Text'); - var br = document.createElement('br'); - var span = goog.dom.createDom('span', null, text, br); - assertEquals('span should have 2 children', 2, span.childNodes.length); - - var el = $('p1'); - el.appendChild(span); - - var ret = goog.dom.flattenElement(span); - - assertTrue('span should have been removed', el.lastChild != span); - assertFalse('span should have no parent', !!span.parentNode && - span.parentNode.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT); - assertEquals('span should have no children', 0, span.childNodes.length); - assertEquals('Last child of p should be br', br, el.lastChild); - assertEquals('Previous sibling of br should be text', text, - br.previousSibling); - - var outOfDoc = goog.dom.createDom('span', null, '1 child'); - // Should do nothing. - goog.dom.flattenElement(outOfDoc); - assertEquals('outOfDoc should still have 1 child', 1, - outOfDoc.childNodes.length); -} - -function testIsNodeLike() { - assertTrue('document should be node like', goog.dom.isNodeLike(document)); - assertTrue('document.body should be node like', - goog.dom.isNodeLike(document.body)); - assertTrue('a text node should be node like', goog.dom.isNodeLike( - document.createTextNode(''))); - - assertFalse('null should not be node like', goog.dom.isNodeLike(null)); - assertFalse('a string should not be node like', goog.dom.isNodeLike('abcd')); - - assertTrue('custom object should be node like', - goog.dom.isNodeLike({nodeType: 1})); -} - -function testIsElement() { - assertFalse('document is not an element', goog.dom.isElement(document)); - assertTrue('document.body is an element', - goog.dom.isElement(document.body)); - assertFalse('a text node is not an element', goog.dom.isElement( - document.createTextNode(''))); - assertTrue('an element created with createElement() is an element', - goog.dom.isElement(document.createElement('a'))); - - assertFalse('null is not an element', goog.dom.isElement(null)); - assertFalse('a string is not an element', goog.dom.isElement('abcd')); - - assertTrue('custom object is an element', - goog.dom.isElement({nodeType: 1})); - assertFalse('custom non-element object is a not an element', - goog.dom.isElement({someProperty: 'somevalue'})); -} - -function testIsWindow() { - var global = goog.global; - var frame = window.frames['frame']; - var otherWindow = window.open('', 'blank'); - var object = {window: goog.global}; - var nullVar = null; - var notDefined; - - try { - // Use try/finally to ensure that we clean up the window we open, even if an - // assertion fails or something else goes wrong. - assertTrue('global object in HTML context should be a window', - goog.dom.isWindow(goog.global)); - assertTrue('iframe window should be a window', goog.dom.isWindow(frame)); - if (otherWindow) { - assertTrue('other window should be a window', - goog.dom.isWindow(otherWindow)); - } - assertFalse('object should not be a window', goog.dom.isWindow(object)); - assertFalse('null should not be a window', goog.dom.isWindow(nullVar)); - assertFalse('undefined should not be a window', - goog.dom.isWindow(notDefined)); - } finally { - if (otherWindow) { - otherWindow.close(); - } - } -} - -function testGetOwnerDocument() { - assertEquals(goog.dom.getOwnerDocument($('p1')), document); - assertEquals(goog.dom.getOwnerDocument(document.body), document); - assertEquals(goog.dom.getOwnerDocument(document.documentElement), document); -} - -function testDomHelper() { - var x = new goog.dom.DomHelper(window.frames['frame'].document); - assertTrue('Should have some HTML', - x.getDocument().body.innerHTML.length > 0); -} - -function testGetFirstElementChild() { - var p2 = $('p2'); - var b1 = goog.dom.getFirstElementChild(p2); - assertNotNull('First element child of p2 should not be null', b1); - assertEquals('First element child is b1', 'b1', b1.id); - - var c = goog.dom.getFirstElementChild(b1); - assertNull('First element child of b1 should be null', c); - - // Test with an undefined firstElementChild attribute. - var b2 = $('b2'); - var mockP2 = { - childNodes: [b1, b2], - firstChild: b1, - firstElementChild: undefined - }; - - b1 = goog.dom.getFirstElementChild(mockP2); - assertNotNull('First element child of mockP2 should not be null', b1); - assertEquals('First element child is b1', 'b1', b1.id); -} - -function testGetLastElementChild() { - var p2 = $('p2'); - var b2 = goog.dom.getLastElementChild(p2); - assertNotNull('Last element child of p2 should not be null', b2); - assertEquals('Last element child is b2', 'b2', b2.id); - - var c = goog.dom.getLastElementChild(b2); - assertNull('Last element child of b2 should be null', c); - - // Test with an undefined lastElementChild attribute. - var b1 = $('b1'); - var mockP2 = { - childNodes: [b1, b2], - lastChild: b2, - lastElementChild: undefined - }; - - b2 = goog.dom.getLastElementChild(mockP2); - assertNotNull('Last element child of mockP2 should not be null', b2); - assertEquals('Last element child is b2', 'b2', b2.id); -} - -function testGetNextElementSibling() { - var b1 = $('b1'); - var b2 = goog.dom.getNextElementSibling(b1); - assertNotNull('Next element sibling of b1 should not be null', b1); - assertEquals('Next element sibling is b2', 'b2', b2.id); - - var c = goog.dom.getNextElementSibling(b2); - assertNull('Next element sibling of b2 should be null', c); - - // Test with an undefined nextElementSibling attribute. - var mockB1 = { - nextSibling: b2, - nextElementSibling: undefined - }; - - b2 = goog.dom.getNextElementSibling(mockB1); - assertNotNull('Next element sibling of mockB1 should not be null', b1); - assertEquals('Next element sibling is b2', 'b2', b2.id); -} - -function testGetPreviousElementSibling() { - var b2 = $('b2'); - var b1 = goog.dom.getPreviousElementSibling(b2); - assertNotNull('Previous element sibling of b2 should not be null', b1); - assertEquals('Previous element sibling is b1', 'b1', b1.id); - - var c = goog.dom.getPreviousElementSibling(b1); - assertNull('Previous element sibling of b1 should be null', c); - - // Test with an undefined previousElementSibling attribute. - var mockB2 = { - previousSibling: b1, - previousElementSibling: undefined - }; - - b1 = goog.dom.getPreviousElementSibling(mockB2); - assertNotNull('Previous element sibling of mockB2 should not be null', b1); - assertEquals('Previous element sibling is b1', 'b1', b1.id); -} - -function testGetChildren() { - var p2 = $('p2'); - var children = goog.dom.getChildren(p2); - assertNotNull('Elements array should not be null', children); - assertEquals('List of element children should be length two.', 2, - children.length); - - var b1 = $('b1'); - var b2 = $('b2'); - assertObjectEquals('First element child should be b1.', b1, children[0]); - assertObjectEquals('Second element child should be b2.', b2, children[1]); - - var noChildren = goog.dom.getChildren(b1); - assertNotNull('Element children array should not be null', noChildren); - assertEquals('List of element children should be length zero.', 0, - noChildren.length); - - // Test with an undefined children attribute. - var mockP2 = { - childNodes: [b1, b2], - children: undefined - }; - - children = goog.dom.getChildren(mockP2); - assertNotNull('Elements array should not be null', children); - assertEquals('List of element children should be length two.', 2, - children.length); - - assertObjectEquals('First element child should be b1.', b1, children[0]); - assertObjectEquals('Second element child should be b2.', b2, children[1]); -} - -function testGetNextNode() { - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - - assertNull(goog.dom.getNextNode(null)); - - var node = tree; - var next = function() { - return node = goog.dom.getNextNode(node); - }; - - assertEquals('P', next().tagName); - assertEquals('Some text', next().nodeValue); - assertEquals('BLOCKQUOTE', next().tagName); - assertEquals('Some ', next().nodeValue); - assertEquals('I', next().tagName); - assertEquals('special', next().nodeValue); - assertEquals(' ', next().nodeValue); - assertEquals('B', next().tagName); - assertEquals('text', next().nodeValue); - assertEquals('ADDRESS', next().tagName); - assertEquals(goog.dom.NodeType.COMMENT, next().nodeType); - assertEquals('Foo', next().nodeValue); - - assertNull(next()); -} - -function testGetPreviousNode() { - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - - assertNull(goog.dom.getPreviousNode(null)); - - var node = tree.lastChild.lastChild; - var previous = function() { - return node = goog.dom.getPreviousNode(node); - }; - - assertEquals(goog.dom.NodeType.COMMENT, previous().nodeType); - assertEquals('ADDRESS', previous().tagName); - assertEquals('text', previous().nodeValue); - assertEquals('B', previous().tagName); - assertEquals(' ', previous().nodeValue); - assertEquals('special', previous().nodeValue); - assertEquals('I', previous().tagName); - assertEquals('Some ', previous().nodeValue); - assertEquals('BLOCKQUOTE', previous().tagName); - assertEquals('Some text', previous().nodeValue); - assertEquals('P', previous().tagName); - assertEquals('DIV', previous().tagName); - - if (!goog.userAgent.IE) { - // Internet Explorer maintains a parentNode for Elements after they are - // removed from the hierarchy. Everyone else agrees on a null parentNode. - assertNull(previous()); - } -} - -function testSetTextContent() { - var p1 = $('p1'); - var s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - assertEquals(s, p1.innerHTML); - - s = 'four elefants < five ants'; - var sHtml = 'four elefants < five ants'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - assertEquals(sHtml, p1.innerHTML); - - // ensure that we remove existing children - p1.innerHTML = 'a<b>b</b>c'; - s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - - // same but start with an element - p1.innerHTML = '<b>a</b>b<i>c</i>'; - s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - - // clean up - p1.innerHTML = ''; -} - -function testFindNode() { - var expected = document.body; - var result = goog.dom.findNode(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'BODY'; - }); - assertEquals(expected, result); - - expected = document.getElementsByTagName('P')[0]; - result = goog.dom.findNode(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'P'; - }); - assertEquals(expected, result); - - result = goog.dom.findNode(document, function(n) { - return false; - }); - assertUndefined(result); -} - -function testFindNodes() { - var expected = document.getElementsByTagName('P'); - var result = goog.dom.findNodes(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'P'; - }); - assertEquals(expected.length, result.length); - assertEquals(expected[0], result[0]); - assertEquals(expected[1], result[1]); - - result = goog.dom.findNodes(document, function(n) { - return false; - }).length; - assertEquals(0, result); -} - -function createTestDom(txt) { - var dom = goog.dom.createDom('div'); - dom.innerHTML = txt; - return dom; -} - -function testIsFocusableTabIndex() { - assertFalse('isFocusableTabIndex() must be false for no tab index', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - assertFalse('isFocusableTabIndex() must be false for tab index -2', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndexNegative2'))); - assertFalse('isFocusableTabIndex() must be false for tab index -1', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndexNegative1'))); - - // WebKit on Mac doesn't support focusable DIVs until version 526 and later. - if (!goog.userAgent.WEBKIT || !goog.userAgent.MAC || - goog.userAgent.isVersion('526')) { - assertTrue('isFocusableTabIndex() must be true for tab index 0', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - assertTrue('isFocusableTabIndex() must be true for tab index 1', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex1'))); - assertTrue('isFocusableTabIndex() must be true for tab index 2', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex2'))); - } -} - -function testSetFocusableTabIndex() { - // WebKit on Mac doesn't support focusable DIVs until version 526 and later. - if (!goog.userAgent.WEBKIT || !goog.userAgent.MAC || - goog.userAgent.isVersion('526')) { - // Test enabling focusable tab index. - goog.dom.setFocusableTabIndex(goog.dom.getElement('noTabIndex'), true); - assertTrue('isFocusableTabIndex() must be true after enabling tab index', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - - // Test disabling focusable tab index that was added programmatically. - goog.dom.setFocusableTabIndex(goog.dom.getElement('noTabIndex'), false); - assertFalse('isFocusableTabIndex() must be false after disabling tab ' + - 'index that was programmatically added', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - - // Test disabling focusable tab index that was specified in markup. - goog.dom.setFocusableTabIndex(goog.dom.getElement('tabIndex0'), false); - assertFalse('isFocusableTabIndex() must be false after disabling tab ' + - 'index that was specified in markup', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - - // Test re-enabling focusable tab index. - goog.dom.setFocusableTabIndex(goog.dom.getElement('tabIndex0'), true); - assertTrue('isFocusableTabIndex() must be true after reenabling tabindex', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - } -} - -function testGetTextContent() { - function t(inp, out) { - assertEquals(out.replace(/ /g, '_'), - goog.dom.getTextContent( - createTestDom(inp)).replace(/ /g, '_')); - } - - t('abcde', 'abcde'); - t('a<b>bcd</b>efgh', 'abcdefgh'); - t('a<script type="text/javascript' + '">var a=1;<' + '/script>h', 'ah'); - t('<html><head><style type="text/css">' + - 'p{margin:100%;padding:5px}\n.class{background-color:red;}</style>' + - '</head><body><h1>Hello</h1>\n<p>One two three</p>\n<table><tr><td>a' + - '<td>b</table><' + 'script>var a = \'foo\';' + - '</scrip' + 't></body></html>', 'HelloOne two threeab'); - t('abc<br>def', 'abc\ndef'); - t('abc<br>\ndef', 'abc\ndef'); - t('abc<br>\n\ndef', 'abc\ndef'); - t('abc<br><br>\ndef', 'abc\n\ndef'); - t(' <b>abcde </b> ', 'abcde '); - t(' <b>abcde </b> hi ', 'abcde hi '); - t(' \n<b>abcde </b> ', 'abcde '); - t(' \n<b>abcde </b> \n\n\n', 'abcde '); - t('<p>abcde</p>\nfg', 'abcdefg'); - t('\n <div> <b>abcde </b> ', 'abcde '); - t(' \n­<b>abcde ­ </b> \n\n\n­', 'abcde '); - t(' \n­\n\n­\na ', 'a '); - t(' \n<wbr></wbr><b>abcde <wbr></wbr> </b> \n\n\n<wbr></wbr>', 'abcde '); - t('a b', - goog.dom.BrowserFeature.CAN_USE_INNER_TEXT ? - 'a b' : 'a\xA0\xA0\xA0\xA0\xA0b'); -} - -function testGetNodeTextLength() { - - assertEquals(6, goog.dom.getNodeTextLength(createTestDom('abcdef'))); - assertEquals(8, goog.dom.getNodeTextLength( - createTestDom('a<b>bcd</b>efgh'))); - assertEquals(2, goog.dom.getNodeTextLength(createTestDom( - 'a<script type="text/javascript' + '">var a = 1234;<' + '/script>h'))); - assertEquals(4, goog.dom.getNodeTextLength(createTestDom( - 'a<br>\n<!-- some comments -->\nfo'))); - assertEquals(20, goog.dom.getNodeTextLength(createTestDom( - '<html><head><style type="text/css">' + - 'p{margin:100%;padding:5px}\n.class{background-color:red;}</style>' + - '</head><body><h1>Hello</h1><p>One two three</p><table><tr><td>a<td>b' + - '</table><' + 'script>var a = \'foo\';</scrip' + - 't></body></html>'))); - assertEquals(10, goog.dom.getNodeTextLength(createTestDom( - 'a<b>bcd</b><br />efghi'))); -} - -function testGetNodeTextOffset() { - assertEquals(4, goog.dom.getNodeTextOffset($('offsetTest1'), - $('offsetParent1'))); - assertEquals(12, goog.dom.getNodeTextOffset($('offsetTest1'))); -} - -function testGetNodeAtOffset() { - var html = '<div id=a>123<b id=b>45</b><span id=c>67<b id=d>89<i id=e>01' + - '</i>23<i id=f>45</i>67</b>890<i id=g>123</i><b id=h>456</b>' + - '</span></div><div id=i>7890<i id=j>123</i></div>'; - var node = document.createElement('div'); - node.innerHTML = html; - var rv = {}; - - goog.dom.getNodeAtOffset(node, 2, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('a', rv.node.parentNode.id); - assertEquals(1, rv.remainder); - - goog.dom.getNodeAtOffset(node, 3, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('a', rv.node.parentNode.id); - assertEquals(2, rv.remainder); - - goog.dom.getNodeAtOffset(node, 5, rv); - assertEquals('45', rv.node.nodeValue); - assertEquals('b', rv.node.parentNode.id); - assertEquals(1, rv.remainder); - - goog.dom.getNodeAtOffset(node, 6, rv); - assertEquals('67', rv.node.nodeValue); - assertEquals('c', rv.node.parentNode.id); - assertEquals(0, rv.remainder); - - goog.dom.getNodeAtOffset(node, 23, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('g', rv.node.parentNode.id); - assertEquals(2, rv.remainder); - - goog.dom.getNodeAtOffset(node, 30, rv); - assertEquals('7890', rv.node.nodeValue); - assertEquals('i', rv.node.parentNode.id); - assertEquals(3, rv.remainder); - -} - -// IE inserts line breaks and capitalizes nodenames. -function assertEqualsCaseAndLeadingWhitespaceInsensitive(value1, value2) { - value1 = value1.replace(/^\s+|\s+$/g, '').toLowerCase(); - value2 = value2.replace(/^\s+|\s+$/g, '').toLowerCase(); - assertEquals(value1, value2); -} - -function testGetOuterHtml() { - var contents = '<b>foo</b>'; - var node = document.createElement('div'); - node.setAttribute('foo', 'bar'); - node.innerHTML = contents; - assertEqualsCaseAndLeadingWhitespaceInsensitive( - goog.dom.getOuterHtml(node), '<div foo="bar">' + contents + '</div>'); - - var imgNode = document.createElement('img'); - imgNode.setAttribute('foo', 'bar'); - assertEqualsCaseAndLeadingWhitespaceInsensitive( - goog.dom.getOuterHtml(imgNode), '<img foo="bar">'); -} - - -function testGetWindowFrame() { - var frameWindow = window.frames['frame']; - var frameDocument = frameWindow.document; - var frameDomHelper = new goog.dom.DomHelper(frameDocument); - - // Cannot use assertEquals since IE fails on === - assertTrue(frameWindow == frameDomHelper.getWindow()); -} - -function testGetWindow() { - var domHelper = new goog.dom.DomHelper(); - // Cannot use assertEquals since IE fails on === - assertTrue(window == domHelper.getWindow()); -} - -function testGetWindowStatic() { - // Cannot use assertEquals since IE fails on === - assertTrue(window == goog.dom.getWindow()); -} - -function testIsNodeList() { - var elem = document.getElementById('p2'); - var text = document.getElementById('b2').firstChild; - - assertTrue('NodeList should be a node list', - goog.dom.isNodeList(elem.childNodes)); - assertFalse('TextNode should not be a node list', - goog.dom.isNodeList(text)); - assertFalse('Array of nodes should not be a node list', - goog.dom.isNodeList([elem.firstChild, elem.lastChild])); -} - -function testGetFrameContentDocument() { - var iframe = document.getElementsByTagName('iframe')[0]; - var name = iframe.name; - var iframeDoc = goog.dom.getFrameContentDocument(iframe); - assertEquals(window.frames[name].document, iframeDoc); -} - -function testGetFrameContentWindow() { - var iframe = document.getElementsByTagName('iframe')[0]; - var name = iframe.name; - var iframeWin = goog.dom.getFrameContentWindow(iframe); - assertEquals(window.frames[name], iframeWin); -} - -function testCanHaveChildren() { - for (var tag in goog.dom.TagName) { - var expected = true; - switch (tag) { - case goog.dom.TagName.BASE: - case goog.dom.TagName.APPLET: - case goog.dom.TagName.AREA: - case goog.dom.TagName.BR: - case goog.dom.TagName.COL: - case goog.dom.TagName.FRAME: - case goog.dom.TagName.HR: - case goog.dom.TagName.IMG: - case goog.dom.TagName.INPUT: - case goog.dom.TagName.IFRAME: - case goog.dom.TagName.ISINDEX: - case goog.dom.TagName.LINK: - case goog.dom.TagName.NOFRAMES: - case goog.dom.TagName.NOSCRIPT: - case goog.dom.TagName.META: - case goog.dom.TagName.OBJECT: - case goog.dom.TagName.PARAM: - case goog.dom.TagName.SCRIPT: - case goog.dom.TagName.STYLE: - expected = false; - break; - } - var node = goog.dom.createDom(tag); - assertEquals(tag + ' should ' + (expected ? '' : 'not ') + - 'have children', expected, goog.dom.canHaveChildren(node)); - - // Make sure we can _actually_ add a child if we identify the node as - // allowing children. - if (goog.dom.canHaveChildren(node)) { - node.appendChild(goog.dom.createDom('div', null, 'foo')); - } - } -} - -function testGetAncestorNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull(goog.dom.getAncestor(elem, function() {return false;})); -} - -function testGetAncestorMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor(elem, function() {return true;}, true); - assertEquals(elem, matched); -} - -function testGetAncestorNoMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor(elem, function() {return true;}); - assertEquals(elem.parentNode, matched); -} - -function testGetAncestorWithMaxSearchStepsMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor( - elem, function() {return true;}, true, 2); - assertEquals(elem, matched); -} - -function testGetAncestorWithMaxSearchStepsMatch() { - var elem = goog.dom.getElement('nestedElement'); - var searchEl = elem.parentNode.parentNode; - var matched = goog.dom.getAncestor( - elem, function(el) {return el == searchEl;}, false, 1); - assertEquals(searchEl, matched); -} - -function testGetAncestorWithMaxSearchStepsNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - var searchEl = elem.parentNode.parentNode; - var matched = goog.dom.getAncestor( - elem, function(el) {return el == searchEl;}, false, 0); - assertNull(matched); -} - -function testGetAncestorByTagNameNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull( - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.IMG)); -} - -function testGetAncestorByTagNameOnly() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorDiv'); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.DIV)); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, 'div')); -} - -function testGetAncestorByClassNameNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull( - goog.dom.getAncestorByClass(elem, 'bogusClassName')); -} - -function testGetAncestorByClassName() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorP'); - assertEquals(expected, - goog.dom.getAncestorByClass(elem, 'testAncestor')); -} - -function testGetAncestorByTagNameAndClass() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorDiv'); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.DIV, - 'testAncestor')); -} - -function testCreateTable() { - var table = goog.dom.createTable(2, 3, true); - assertEquals(2, table.getElementsByTagName(goog.dom.TagName.TR).length); - assertEquals(3, - table.getElementsByTagName(goog.dom.TagName.TR)[0].childNodes.length); - assertEquals(6, table.getElementsByTagName(goog.dom.TagName.TD).length); - assertEquals(goog.string.Unicode.NBSP, - table.getElementsByTagName(goog.dom.TagName.TD)[0].firstChild.nodeValue); - - table = goog.dom.createTable(2, 3, false); - assertEquals(2, table.getElementsByTagName(goog.dom.TagName.TR).length); - assertEquals(3, - table.getElementsByTagName(goog.dom.TagName.TR)[0].childNodes.length); - assertEquals(6, table.getElementsByTagName(goog.dom.TagName.TD).length); - assertEquals(0, - table.getElementsByTagName(goog.dom.TagName.TD)[0].childNodes.length); -} - -function testHtmlToDocumentFragment() { - var docFragment = goog.dom.htmlToDocumentFragment('<a>1</a><b>2</b>'); - assertNull(docFragment.parentNode); - assertEquals(2, docFragment.childNodes.length); - - var div = goog.dom.htmlToDocumentFragment('<div>3</div>'); - assertEquals('DIV', div.tagName); - - var script = goog.dom.htmlToDocumentFragment('<script></script>'); - assertEquals('SCRIPT', script.tagName); - - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - // Removing an Element from a DOM tree in IE sets its parentNode to a new - // DocumentFragment. Bizarre! - assertEquals(goog.dom.NodeType.DOCUMENT_FRAGMENT, - goog.dom.removeNode(div).parentNode.nodeType); - } else { - assertNull(div.parentNode); - } -} - -function testAppend() { - var div = document.createElement('div'); - var b = document.createElement('b'); - var c = document.createTextNode('c'); - goog.dom.append(div, 'a', b, c); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend2() { - var div = myIframeDoc.createElement('div'); - var b = myIframeDoc.createElement('b'); - var c = myIframeDoc.createTextNode('c'); - goog.dom.append(div, 'a', b, c); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend3() { - var div = document.createElement('div'); - var b = document.createElement('b'); - var c = document.createTextNode('c'); - goog.dom.append(div, ['a', b, c]); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend4() { - var div = document.createElement('div'); - var div2 = document.createElement('div'); - div2.innerHTML = 'a<b></b>c'; - goog.dom.append(div, div2.childNodes); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); - assertFalse(div2.hasChildNodes()); -} - -function testGetDocumentScroll() { - // setUpPage added divForTestingScrolling to the DOM. It's not init'd here so - // it can be shared amonst other tests. - window.scrollTo(100, 100); - - assertEquals(100, goog.dom.getDocumentScroll().x); - assertEquals(100, goog.dom.getDocumentScroll().y); -} - -function testGetDocumentScrollOfFixedViewport() { - // iOS and perhaps other environments don't actually support scrolling. - // Instead, you view the document's fixed layout through a screen viewport. - // We need getDocumentScroll to handle this case though. - var fakeDocumentScrollElement = {scrollLeft: 0, scrollTop: 0}; - var fakeDocument = { - defaultView: {pageXOffset: 100, pageYOffset: 100}, - documentElement: fakeDocumentScrollElement, - body: fakeDocumentScrollElement - }; - var dh = goog.dom.getDomHelper(document); - dh.setDocument(fakeDocument); - assertEquals(100, dh.getDocumentScroll().x); - assertEquals(100, dh.getDocumentScroll().y); -} - -function testActiveElementIE() { - if (!goog.userAgent.IE) { - return; - } - - var link = goog.dom.getElement('link'); - link.focus(); - - assertEquals(link.tagName, goog.dom.getActiveElement(document).tagName); - assertEquals(link, goog.dom.getActiveElement(document)); -} - -function testParentElement() { - var testEl = $('testEl'); - var bodyEl = goog.dom.getParentElement(testEl); - assertNotNull(bodyEl); - var htmlEl = goog.dom.getParentElement(bodyEl); - assertNotNull(htmlEl); - var documentNotAnElement = goog.dom.getParentElement(htmlEl); - assertNull(documentNotAnElement); - - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - assertNull(goog.dom.getParentElement(tree)); - pEl = goog.dom.getNextNode(tree); - var fragmentRootEl = goog.dom.getParentElement(pEl); - assertEquals(tree, fragmentRootEl); - - var detachedEl = goog.dom.createDom('div'); - var detachedHasNoParent = goog.dom.getParentElement(detachedEl); - assertNull(detachedHasNoParent); -} - -/** - * @return {boolean} Returns true if the userAgent is IE8 or higher. - */ -function isIE8OrHigher() { - return goog.userAgent.IE && goog.userAgent.product.isVersion('8'); -} diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base deleted file mode 100644 index e505257..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2005 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A class that can be used to listen to font size changes. - */ - -goog.provide('goog.dom.FontSizeMonitor'); -goog.provide('goog.dom.FontSizeMonitor.EventType'); - -goog.require('goog.dom'); -goog.require('goog.events'); -goog.require('goog.events.EventTarget'); -goog.require('goog.events.EventType'); -goog.require('goog.userAgent'); - - -// TODO(arv): Move this to goog.events instead. - - - -/** - * This class can be used to monitor changes in font size. Instances will - * dispatch a {@code goog.dom.FontSizeMonitor.EventType.CHANGE} event. - * Example usage: - * <pre> - * var fms = new goog.dom.FontSizeMonitor(); - * goog.events.listen(fms, goog.dom.FontSizeMonitor.EventType.CHANGE, - * function(e) { - * alert('Font size was changed'); - * }); - * </pre> - * @param {goog.dom.DomHelper=} opt_domHelper DOM helper object that is used to - * determine where to insert the DOM nodes used to determine when the font - * size changes. - * @constructor - * @extends {goog.events.EventTarget} - */ -goog.dom.FontSizeMonitor = function(opt_domHelper) { - goog.events.EventTarget.call(this); - - var dom = opt_domHelper || goog.dom.getDomHelper(); - - /** - * Offscreen iframe which we use to detect resize events. - * @type {Element} - * @private - */ - this.sizeElement_ = dom.createDom( - // The size of the iframe is expressed in em, which are font size relative - // which will cause the iframe to be resized when the font size changes. - // The actual values are not relevant as long as we can ensure that the - // iframe has a non zero size and is completely off screen. - goog.userAgent.IE ? 'div' : 'iframe', { - 'style': 'position:absolute;width:9em;height:9em;top:-99em', - 'tabIndex': -1, - 'aria-hidden': 'true' - }); - var p = dom.getDocument().body; - p.insertBefore(this.sizeElement_, p.firstChild); - - /** - * The object that we listen to resize events on. - * @type {Element|Window} - * @private - */ - var resizeTarget = this.resizeTarget_ = - goog.userAgent.IE ? this.sizeElement_ : - goog.dom.getFrameContentWindow( - /** @type {HTMLIFrameElement} */ (this.sizeElement_)); - - // We need to open and close the document to get Firefox 2 to work. We must - // not do this for IE in case we are using HTTPS since accessing the document - // on an about:blank iframe in IE using HTTPS raises a Permission Denied - // error. - if (goog.userAgent.GECKO) { - var doc = resizeTarget.document; - doc.open(); - doc.close(); - } - - // Listen to resize event on the window inside the iframe. - goog.events.listen(resizeTarget, goog.events.EventType.RESIZE, - this.handleResize_, false, this); - - /** - * Last measured width of the iframe element. - * @type {number} - * @private - */ - this.lastWidth_ = this.sizeElement_.offsetWidth; -}; -goog.inherits(goog.dom.FontSizeMonitor, goog.events.EventTarget); - - -/** - * The event types that the FontSizeMonitor fires. - * @enum {string} - */ -goog.dom.FontSizeMonitor.EventType = { - // TODO(arv): Change value to 'change' after updating the callers. - CHANGE: 'fontsizechange' -}; - - -/** - * Constant for the change event. - * @type {string} - * @deprecated Use {@code goog.dom.FontSizeMonitor.EventType.CHANGE} instead. - */ -goog.dom.FontSizeMonitor.CHANGE_EVENT = - goog.dom.FontSizeMonitor.EventType.CHANGE; - - -/** @override */ -goog.dom.FontSizeMonitor.prototype.disposeInternal = function() { - goog.dom.FontSizeMonitor.superClass_.disposeInternal.call(this); - - goog.events.unlisten(this.resizeTarget_, goog.events.EventType.RESIZE, - this.handleResize_, false, this); - this.resizeTarget_ = null; - - // Firefox 2 crashes if the iframe is removed during the unload phase. - if (!goog.userAgent.GECKO || goog.userAgent.isVersion('1.9')) { - goog.dom.removeNode(this.sizeElement_); - } - delete this.sizeElement_; -}; - - -/** - * Handles the onresize event of the iframe and dispatches a change event in - * case its size really changed. - * @param {goog.events.BrowserEvent} e The event object. - * @private - */ -goog.dom.FontSizeMonitor.prototype.handleResize_ = function(e) { - // Only dispatch the event if the size really changed. Some newer browsers do - // not really change the font-size, instead they zoom the whole page. This - // does trigger window resize events on the iframe but the logical pixel size - // remains the same (the device pixel size changes but that is irrelevant). - var currentWidth = this.sizeElement_.offsetWidth; - if (this.lastWidth_ != currentWidth) { - this.lastWidth_ = currentWidth; - this.dispatchEvent(goog.dom.FontSizeMonitor.EventType.CHANGE); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base deleted file mode 100644 index 3852042..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base +++ /dev/null @@ -1,284 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: arv@google.com (Erik Arvidsson) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.FontSizeMonitor</title> -<script src="../base.js"></script> -<script> - -goog.require('goog.dom'); -goog.require('goog.dom.FontSizeMonitor'); -goog.require('goog.events'); -goog.require('goog.testing.PropertyReplacer'); -goog.require('goog.testing.events'); -goog.require('goog.testing.jsunit'); -goog.require('goog.userAgent'); - -</script> -</head> -<body> - -<!-- iframe to be used to test DomHelper support --> -<iframe></iframe> - -<script> - -function isBuggyGecko() { - return goog.userAgent.GECKO && !goog.userAgent.isVersion('1.9'); -} - -var monitor; - -function setUp() { - monitor = new goog.dom.FontSizeMonitor(); -} - -function tearDown() { - monitor.dispose(); -} - -function getResizeTarget() { - return goog.userAgent.IE ? monitor.sizeElement_ : - goog.dom.getFrameContentWindow(monitor.sizeElement_); -} - -function testFontSizeNoChange() { - // This tests that firing the resize event without changing the font-size - // does not trigger the event. - - var fired = false; - goog.events.listen(monitor, goog.dom.FontSizeMonitor.EventType.CHANGE, - function(e) { - fired = true; - }); - - var resizeEvent = new goog.events.Event('resize', getResizeTarget()); - goog.testing.events.fireBrowserEvent(resizeEvent); - - assertFalse('The font size should not have changed', fired); -} - -function testFontSizeChanged() { - // One can trigger the iframe resize by changing the - // document.body.style.fontSize but the event is fired asynchronously in - // Firefox. Instead, we just override the lastWidth_ to simulate that the - // size changed. - - var fired = false; - goog.events.listen(monitor, goog.dom.FontSizeMonitor.EventType.CHANGE, - function(e) { - fired = true; - }); - - monitor.lastWidth_--; - - var resizeEvent = new goog.events.Event('resize', getResizeTarget()); - goog.testing.events.fireBrowserEvent(resizeEvent); - - assertTrue('The font size should have changed', fired); -} - -function testCreateAndDispose() { - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount + isBuggyGecko(), newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount + isBuggyGecko(), - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); -} - -function testWithDomHelper() { - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(goog.dom.getDomHelper()); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - if (goog.userAgent.IE) { - assertEquals('There should be one new div element', - divElementCount + 1, newDivElementCount); - } else { - assertEquals('There should be one new frame', - frameCount + 1, newFrameCount); - assertEquals('There should be one new iframe element', - iframeElementCount + 1, newIframeElementCount); - } - - // Use the first iframe in the doc. This is added in the HTML markup. - var win = window.frames[0]; - var doc = win.document; - doc.open(); - doc.write('<html><body></body></html>'); - doc.close(); - var domHelper = goog.dom.getDomHelper(doc); - - var frameCount2 = win.frames.length; - var iframeElementCount2 = doc.getElementsByTagName('iframe').length; - var divElementCount2 = doc.getElementsByTagName('div').length; - - var monitor2 = new goog.dom.FontSizeMonitor(domHelper); - - var newFrameCount2 = win.frames.length; - var newIframeElementCount2 = doc.getElementsByTagName('iframe').length; - var newDivElementCount2 = doc.getElementsByTagName('div').length; - - if (goog.userAgent.IE) { - assertEquals('There should be one new div element', - divElementCount2 + 1, newDivElementCount2); - } else { - assertEquals('There should be one new frame', frameCount2 + 1, - newFrameCount2); - assertEquals('There should be one new iframe element', - iframeElementCount2 + 1, newIframeElementCount2); - } - - monitor.dispose(); - monitor2.dispose(); -} - -function testEnsureThatDocIsOpenedForGecko() { - - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - var openCalled = false; - var closeCalled = false; - var instance = { - document: { - open: function() { - openCalled = true; - }, - close: function() { - closeCalled = true; - } - }, - attachEvent: function() {} - }; - - pr.set(goog.dom, 'getFrameContentWindow', function() { - return instance; - }); - - try { - var monitor = new goog.dom.FontSizeMonitor(); - - assertTrue('doc.open should have been called', openCalled); - assertTrue('doc.close should have been called', closeCalled); - - monitor.dispose(); - } finally { - pr.reset(); - } -} - -function testFirefox2WorkAroundFirefox3() { - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - try { - // 1.9 should clear iframes - pr.set(goog.userAgent, 'VERSION', '1.9'); - goog.userAgent.isVersionCache_ = {}; - - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount, newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount, - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); - } finally { - pr.reset(); - } -} - - -function testFirefox2WorkAroundFirefox2() { - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - try { - // 1.8 should NOT clear iframes - pr.set(goog.userAgent, 'VERSION', '1.8'); - goog.userAgent.isVersionCache_ = {}; - - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount + 1, newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount + 1, - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); - } finally { - pr.reset(); - } -} - -</script> - -<!-- -This div has a script in it that creates a FontSizeMonitor. This ensures that -we do not get an "Operation abort" error in IE. ---> -<div> - <script> - var operationAbortTester = new goog.dom.FontSizeMonitor(); - // Close script tag before disposing. - </script> - <script> - operationAbortTester.dispose(); - </script> -</div> - -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base deleted file mode 100644 index af403f9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for manipulating a form and elements. - * - * @author arv@google.com (Erik Arvidsson) - * @author jonp@google.com (Jon Perlow) - * @author elsigh@google.com (Lindsey Simon) - */ - -goog.provide('goog.dom.forms'); - -goog.require('goog.structs.Map'); - - -/** - * Returns form data as a map of name to value arrays. This doesn't - * support file inputs. - * @param {HTMLFormElement} form The form. - * @return {!goog.structs.Map} A map of the form data as form name to arrays of - * values. - */ -goog.dom.forms.getFormDataMap = function(form) { - var map = new goog.structs.Map(); - goog.dom.forms.getFormDataHelper_(form, map, - goog.dom.forms.addFormDataToMap_); - return map; -}; - - -/** - * Returns the form data as an application/x-www-url-encoded string. This - * doesn't support file inputs. - * @param {HTMLFormElement} form The form. - * @return {string} An application/x-www-url-encoded string. - */ -goog.dom.forms.getFormDataString = function(form) { - var sb = []; - goog.dom.forms.getFormDataHelper_(form, sb, - goog.dom.forms.addFormDataToStringBuffer_); - return sb.join('&'); -}; - - -/** - * Returns the form data as a map or an application/x-www-url-encoded - * string. This doesn't support file inputs. - * @param {HTMLFormElement} form The form. - * @param {Object} result The object form data is being put in. - * @param {Function} fnAppend Function that takes {@code result}, an element - * name, and an element value, and adds the name/value pair to the result - * object. - * @private - */ -goog.dom.forms.getFormDataHelper_ = function(form, result, fnAppend) { - var els = form.elements; - for (var el, i = 0; el = els[i]; i++) { - if (el.disabled || el.tagName.toLowerCase() == 'fieldset') { - continue; - } - var name = el.name; - var type = el.type.toLowerCase(); - switch (type) { - case 'file': - // file inputs are not supported - case 'submit': - case 'reset': - case 'button': - // don't submit these - break; - case 'select-multiple': - var values = goog.dom.forms.getValue(el); - if (values != null) { - for (var value, j = 0; value = values[j]; j++) { - fnAppend(result, name, value); - } - } - break; - default: - var value = goog.dom.forms.getValue(el); - if (value != null) { - fnAppend(result, name, value); - } - } - } - - // input[type=image] are not included in the elements collection - var inputs = form.getElementsByTagName('input'); - for (var input, i = 0; input = inputs[i]; i++) { - if (input.form == form && input.type.toLowerCase() == 'image') { - name = input.name; - fnAppend(result, name, input.value); - fnAppend(result, name + '.x', '0'); - fnAppend(result, name + '.y', '0'); - } - } -}; - - -/** - * Adds the name/value pair to the map. - * @param {goog.structs.Map} map The map to add to. - * @param {string} name The name. - * @param {string} value The value. - * @private - */ -goog.dom.forms.addFormDataToMap_ = function(map, name, value) { - var array = map.get(name); - if (!array) { - array = []; - map.set(name, array); - } - array.push(value); -}; - - -/** - * Adds a name/value pair to an string buffer array in the form 'name=value'. - * @param {Array} sb The string buffer array for storing data. - * @param {string} name The name. - * @param {string} value The value. - * @private - */ -goog.dom.forms.addFormDataToStringBuffer_ = function(sb, name, value) { - sb.push(encodeURIComponent(name) + '=' + encodeURIComponent(value)); -}; - - -/** - * Whether the form has a file input. - * @param {HTMLFormElement} form The form. - * @return {boolean} Whether the form has a file input. - */ -goog.dom.forms.hasFileInput = function(form) { - var els = form.elements; - for (var el, i = 0; el = els[i]; i++) { - if (!el.disabled && el.type && el.type.toLowerCase() == 'file') { - return true; - } - } - return false; -}; - - -/** - * Enables or disables either all elements in a form or a single form element. - * @param {Element} el The element, either a form or an element within a form. - * @param {boolean} disabled Whether the element should be disabled. - */ -goog.dom.forms.setDisabled = function(el, disabled) { - // disable all elements in a form - if (el.tagName == 'FORM') { - var els = el.elements; - for (var i = 0; el = els[i]; i++) { - goog.dom.forms.setDisabled(el, disabled); - } - } else { - // makes sure to blur buttons, multi-selects, and any elements which - // maintain keyboard/accessibility focus when disabled - if (disabled == true) { - el.blur(); - } - el.disabled = disabled; - } -}; - - -/** - * Focuses, and optionally selects the content of, a form element. - * @param {Element} el The form element. - */ -goog.dom.forms.focusAndSelect = function(el) { - el.focus(); - if (el.select) { - el.select(); - } -}; - - -/** - * Whether a form element has a value. - * @param {Element} el The element. - * @return {boolean} Whether the form has a value. - */ -goog.dom.forms.hasValue = function(el) { - var value = goog.dom.forms.getValue(el); - return !!value; -}; - - -/** - * Whether a named form field has a value. - * @param {HTMLFormElement} form The form element. - * @param {string} name Name of an input to the form. - * @return {boolean} Whether the form has a value. - */ -goog.dom.forms.hasValueByName = function(form, name) { - var value = goog.dom.forms.getValueByName(form, name); - return !!value; -}; - - -/** - * Gets the current value of any element with a type. - * @param {Element} el The element. - * @return {string|Array.<string>|null} The current value of the element - * (or null). - */ -goog.dom.forms.getValue = function(el) { - var type = el.type; - if (!goog.isDef(type)) { - return null; - } - switch (type.toLowerCase()) { - case 'checkbox': - case 'radio': - return goog.dom.forms.getInputChecked_(el); - case 'select-one': - return goog.dom.forms.getSelectSingle_(el); - case 'select-multiple': - return goog.dom.forms.getSelectMultiple_(el); - default: - return goog.isDef(el.value) ? el.value : null; - } -}; - - -/** - * Alias for goog.dom.form.element.getValue - * @type {Function} - * @deprecated Use {@link goog.dom.forms.getValue} instead. - */ -goog.dom.$F = goog.dom.forms.getValue; - - -/** - * Returns the value of the named form field. In the case of radio buttons, - * returns the value of the checked button with the given name. - * - * @param {HTMLFormElement} form The form element. - * @param {string} name Name of an input to the form. - * - * @return {Array.<string>|string|null} The value of the form element, or - * null if the form element does not exist or has no value. - */ -goog.dom.forms.getValueByName = function(form, name) { - var els = form.elements[name]; - - if (els.type) { - return goog.dom.forms.getValue(els); - } else { - for (var i = 0; i < els.length; i++) { - var val = goog.dom.forms.getValue(els[i]); - if (val) { - return val; - } - } - - return null; - } -}; - - -/** - * Gets the current value of a checkable input element. - * @param {Element} el The element. - * @return {?string} The value of the form element (or null). - * @private - */ -goog.dom.forms.getInputChecked_ = function(el) { - return el.checked ? el.value : null; -}; - - -/** - * Gets the current value of a select-one element. - * @param {Element} el The element. - * @return {?string} The value of the form element (or null). - * @private - */ -goog.dom.forms.getSelectSingle_ = function(el) { - var selectedIndex = el.selectedIndex; - return selectedIndex >= 0 ? el.options[selectedIndex].value : null; -}; - - -/** - * Gets the current value of a select-multiple element. - * @param {Element} el The element. - * @return {Array.<string>?} The value of the form element (or null). - * @private - */ -goog.dom.forms.getSelectMultiple_ = function(el) { - var values = []; - for (var option, i = 0; option = el.options[i]; i++) { - if (option.selected) { - values.push(option.value); - } - } - return values.length ? values : null; -}; - - -/** - * Sets the current value of any element with a type. - * @param {Element} el The element. - * @param {*=} opt_value The value to give to the element, which will be coerced - * by the browser in the default case using toString. This value should be - * an array for setting the value of select multiple elements. - */ -goog.dom.forms.setValue = function(el, opt_value) { - var type = el.type; - if (goog.isDef(type)) { - switch (type.toLowerCase()) { - case 'checkbox': - case 'radio': - goog.dom.forms.setInputChecked_(el, - /** @type {string} */ (opt_value)); - break; - case 'select-one': - goog.dom.forms.setSelectSingle_(el, - /** @type {string} */ (opt_value)); - break; - case 'select-multiple': - goog.dom.forms.setSelectMultiple_(el, - /** @type {Array} */ (opt_value)); - break; - default: - el.value = goog.isDefAndNotNull(opt_value) ? opt_value : ''; - } - } -}; - - -/** - * Sets a checkable input element's checked property. - * #TODO(user): This seems potentially unintuitive since it doesn't set - * the value property but my hunch is that the primary use case is to check a - * checkbox, not to reset its value property. - * @param {Element} el The element. - * @param {string|boolean=} opt_value The value, sets the element checked if - * val is set. - * @private - */ -goog.dom.forms.setInputChecked_ = function(el, opt_value) { - el.checked = opt_value ? 'checked' : null; -}; - - -/** - * Sets the value of a select-one element. - * @param {Element} el The element. - * @param {string=} opt_value The value of the selected option element. - * @private - */ -goog.dom.forms.setSelectSingle_ = function(el, opt_value) { - // unset any prior selections - el.selectedIndex = -1; - if (goog.isString(opt_value)) { - for (var option, i = 0; option = el.options[i]; i++) { - if (option.value == opt_value) { - option.selected = true; - break; - } - } - } -}; - - -/** - * Sets the value of a select-multiple element. - * @param {Element} el The element. - * @param {Array.<string>|string=} opt_value The value of the selected option - * element(s). - * @private - */ -goog.dom.forms.setSelectMultiple_ = function(el, opt_value) { - // reset string opt_values as an array - if (goog.isString(opt_value)) { - opt_value = [opt_value]; - } - for (var option, i = 0; option = el.options[i]; i++) { - // we have to reset the other options to false for select-multiple - option.selected = false; - if (opt_value) { - for (var value, j = 0; value = opt_value[j]; j++) { - if (option.value == value) { - option.selected = true; - } - } - } - } -}; - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base deleted file mode 100644 index 67570fd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base +++ /dev/null @@ -1,483 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.forms</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.forms'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <!-- empty div to test against --> - <div id="testdiv1"></div> - - <form id="testform1" onsubmit="return false"> - - <!-- text input with one value --> - <input id="in1" name="in1" value="foo"> - - <!-- text inputs with two values --> - <input id="in2" name="in2" value="bar"> - <input id="in2" name="in2" value="baaz"> - - <!-- empty text input --> - <input id="in3" name="in3" value=""> - - <!-- password --> - <input id="pass" name="pass" type="password" value="bar"> - - <!-- textarea --> - <textarea id="textarea1" name="textarea">foo bar baz</textarea> - - <!-- select single --> - <select id="select1" name="select1"> - <option value="1" selected>one</option> - <option value="2">two</option> - </select> - - <!-- select multiple --> - <select id="select2" name="select2" multiple=true> - <option value="a" selected>A</option> - <option value="b">B</option> - <option value="c" selected>C</option> - </select> - - <!-- select no value --> - <select id="select3" name="select3"> - <option></option> - <option value="1">one</option> - <option value="2">two</option> - </select> - - <!-- checkboxes --> - <fieldset id="testfieldset1"> - <legend id="testlegend1">Checkboxes</legend> - <input id="checkbox1" type="checkbox" name="checkbox1" checked> - <input id="checkbox2" type="checkbox" name="checkbox2"> - </fieldset> - - <!-- radio buttons --> - <fieldset> - <legend>Radio Buttons</legend> - <input id="radio1" type="radio" name="radio" value="X" checked> - <input id="radio2" type="radio" name="radio" value="Y"> - </fieldset> - - <fieldset> - <legend>Radio Buttons</legend> - <input id="radio3" type="radio" name="radio2" value="X"> - <input id="radio4" type="radio" name="radio2" value="Y" checked> - </fieldset> - - <!-- button --> - <button id="button" name="button" type="button" value="button" onclick="testSetValueSelectMultiple()">button</button> - - <!-- submit --> - <input id="submit" type="submit" name="submit" value="submit"> - - <!-- reset --> - <input id="reset" type="reset" name="reset" value="reset"> - - </form> - - <form id="testform2"> - <input type="file" name="file"> - </form> - - <form id="testform3"> - <!-- text input --> - <input id="in4" name="in4"> - - <!-- textarea --> - <textarea id="textarea2" name="textarea"></textarea> - - <!-- select single --> - <select id="select4" name="select1"> - <option value="1">one</option> - <option value="2">two</option> - </select> - - <!-- select multiple --> - <select id="select5" name="select5" multiple=true> - <option value="a">A</option> - <option value="b">B</option> - <option value="c">C</option> - </select> - - <!-- radio --> - <input id="radio3" type="radio" name="radio3" value="Z"> - - <!-- checkbox --> - <input id="checkbox2" type="checkbox" name="checkbox2"> - - - <!-- select multiple no value --> - <select id="select6" name="select6" multiple=true> - <option value="a">A</option> - <option value="b">B</option> - </select> - - <!-- select with empty value --> - <select id="select7" name="select7"> - <option value="">Empty</option> - <option value="a">A</option> - <option value="b">B</option> - </select> - </form> - -<script> - - function testGetFormDataString() { - var el = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getFormDataString(el); - assertEquals('in1=foo&in2=bar&in2=baaz&in3=&pass=bar&textarea=foo%20bar%20baz&select1=1&select2=a&select2=c&select3=&checkbox1=on&radio=X&radio2=Y', result); - } - - function testGetFormDataMap() { - var el = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getFormDataMap(el); - - assertArrayEquals(['foo'], result.get('in1')); - assertArrayEquals(['bar', 'baaz'], result.get('in2')); - assertArrayEquals(['1'], result.get('select1')); - assertArrayEquals(['a', 'c'], result.get('select2')); - assertArrayEquals(['on'], result.get('checkbox1')); - assertUndefined(result.get('select6')); - assertUndefined(result.get('checkbox2')); - assertArrayEquals(['X'], result.get('radio')); - assertArrayEquals(['Y'], result.get('radio2')); - } - - function testHasFileInput() { - var el = goog.dom.getElement('testform1'); - assertFalse(goog.dom.forms.hasFileInput(el)); - el = goog.dom.getElement('testform2'); - assertTrue(goog.dom.forms.hasFileInput(el)); - } - - - function testGetValueOnAtypicalValueElements() { - var el = goog.dom.getElement('testdiv1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - var el = goog.dom.getElement('testfieldset1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - var el = goog.dom.getElement('testlegend1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testHasValueInput() { - var el = goog.dom.getElement('in1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameInput() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'in1'); - assertTrue(result); - } - - function testHasValueInputEmpty() { - var el = goog.dom.getElement('in3'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameEmpty() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'in3'); - assertFalse(result); - } - - function testHasValueRadio() { - var el = goog.dom.getElement('radio1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameRadio() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'radio'); - assertTrue(result); - } - - function testHasValueRadioNotChecked() { - var el = goog.dom.getElement('radio2'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameRadioNotChecked() { - var form = goog.dom.getElement('testform3'); - var result = goog.dom.forms.hasValueByName(form, 'radio3'); - assertFalse(result); - } - - function testHasValueSelectSingle() { - var el = goog.dom.getElement('select1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameSelectSingle() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select1'); - assertTrue(result); - } - - function testHasValueSelectMultiple() { - var el = goog.dom.getElement('select2'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameSelectMultiple() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select2'); - assertTrue(result); - } - - function testHasValueSelectNotSelected() { - // select without value - var el = goog.dom.getElement('select3'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameSelectNotSelected() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select3'); - assertFalse(result); - } - - function testHasValueSelectMultipleNotSelected() { - var el = goog.dom.getElement('select6'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameSelectMultipleNotSelected() { - var form = goog.dom.getElement('testform3'); - var result = goog.dom.forms.hasValueByName(form, 'select6'); - assertFalse(result); - } - - // TODO(user): make this a meaningful selenium test - function testSetDisabledFalse() { - } - function testSetDisabledTrue() { - } - - // TODO(user): make this a meaningful selenium test - function testFocusAndSelect() { - var el = goog.dom.getElement('in1'); - goog.dom.forms.focusAndSelect(el); - } - - function testGetValueInput() { - var el = goog.dom.getElement('in1'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo', result); - } - - function testSetValueInput() { - var el = goog.dom.getElement('in3'); - goog.dom.forms.setValue(el, 'foo'); - assertEquals('foo', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, 3500); - assertEquals('3500', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, 0); - assertEquals('0', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, null); - assertEquals('', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, undefined); - assertEquals('', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, false); - assertEquals('false', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, {}); - assertEquals({}.toString(), goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, { - toString: function() { - return 'test'; - } - }); - assertEquals('test', goog.dom.forms.getValue(el)); - - // unset - goog.dom.forms.setValue(el); - assertEquals('', goog.dom.forms.getValue(el)); - } - - function testGetValuePassword() { - var el = goog.dom.getElement('pass'); - var result = goog.dom.forms.getValue(el); - assertEquals('bar', result); - } - - function testGetValueByNamePassword() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'pass'); - assertEquals('bar', result); - } - - function testGetValueTextarea() { - var el = goog.dom.getElement('textarea1'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo bar baz', result); - } - - function testGetValueByNameTextarea() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'textarea1'); - assertEquals('foo bar baz', result); - } - - function testSetValueTextarea() { - var el = goog.dom.getElement('textarea2'); - goog.dom.forms.setValue(el, 'foo bar baz'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo bar baz', result); - } - - function testGetValueSelectSingle() { - var el = goog.dom.getElement('select1'); - var result = goog.dom.forms.getValue(el); - assertEquals('1', result); - } - - function testGetValueByNameSelectSingle() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'select1'); - assertEquals('1', result); - } - - function testSetValueSelectSingle() { - var el = goog.dom.getElement('select4'); - goog.dom.forms.setValue(el, '2'); - var result = goog.dom.forms.getValue(el); - assertEquals('2', result); - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testSetValueSelectSingleEmptyString() { - var el = goog.dom.getElement('select7'); - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - goog.dom.forms.setValue(el, ''); - result = goog.dom.forms.getValue(el); - assertEquals('', result); - } - - function testGetValueSelectMultiple() { - var el = goog.dom.getElement('select2'); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a', 'c'], result); - } - - function testGetValueSelectMultipleNotSelected() { - var el = goog.dom.getElement('select6'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameSelectMultiple() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'select2'); - assertArrayEquals(['a', 'c'], result); - } - - function testSetValueSelectMultiple() { - var el = goog.dom.getElement('select5'); - goog.dom.forms.setValue(el, ['a', 'c']); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a', 'c'], result); - - goog.dom.forms.setValue(el, 'a'); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a'], result); - - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueCheckbox() { - var el = goog.dom.getElement('checkbox1'); - var result = goog.dom.forms.getValue(el); - assertEquals('on', result); - var el = goog.dom.getElement('checkbox2'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameCheckbox() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'checkbox1'); - assertEquals('on', result); - result = goog.dom.forms.getValueByName(form, 'checkbox2'); - assertNull(result); - } - - function testGetValueRadio() { - var el = goog.dom.getElement('radio1'); - var result = goog.dom.forms.getValue(el); - assertEquals('X', result); - var el = goog.dom.getElement('radio2'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameRadio() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'radio'); - assertEquals('X', result); - - result = goog.dom.forms.getValueByName(form, 'radio2'); - assertEquals('Y', result); - } - - function testGetValueButton() { - var el = goog.dom.getElement('button'); - var result = goog.dom.forms.getValue(el); - assertEquals('button', result); - } - - function testGetValueSubmit() { - var el = goog.dom.getElement('submit'); - var result = goog.dom.forms.getValue(el); - assertEquals('submit', result); - } - - function testGetValueReset() { - var el = goog.dom.getElement('reset'); - var result = goog.dom.forms.getValue(el); - assertEquals('reset', result); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base deleted file mode 100644 index 71b3df4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for creating and working with iframes - * cross-browser. - * @author gboyer@google.com (Garry Boyer) - */ - - -goog.provide('goog.dom.iframe'); - -goog.require('goog.dom'); - - -/** - * Safe source for a blank iframe. - * - * Intentionally not about:blank, which gives mixed content warnings in IE6 - * over HTTPS. - * - * @type {string} - */ -goog.dom.iframe.BLANK_SOURCE = 'javascript:""'; - - -/** - * Styles to help ensure an undecorated iframe. - * @type {string} - * @private - */ -goog.dom.iframe.STYLES_ = 'border:0;vertical-align:bottom;'; - - -/** - * Creates a completely blank iframe element. - * - * The iframe will not caused mixed-content warnings for IE6 under HTTPS. - * The iframe will also have no borders or padding, so that the styled width - * and height will be the actual width and height of the iframe. - * - * This function currently only attempts to create a blank iframe. There - * are no guarantees to the contents of the iframe or whether it is rendered - * in quirks mode. - * - * @param {goog.dom.DomHelper} domHelper The dom helper to use. - * @param {string=} opt_styles CSS styles for the iframe. - * @return {!HTMLIFrameElement} A completely blank iframe. - */ -goog.dom.iframe.createBlank = function(domHelper, opt_styles) { - return /** @type {!HTMLIFrameElement} */ (domHelper.createDom('iframe', { - 'frameborder': 0, - // Since iframes are inline elements, we must align to bottom to - // compensate for the line descent. - 'style': goog.dom.iframe.STYLES_ + (opt_styles || ''), - 'src': goog.dom.iframe.BLANK_SOURCE - })); -}; - - -/** - * Writes the contents of a blank iframe that has already been inserted - * into the document. - * @param {!HTMLIFrameElement} iframe An iframe with no contents, such as - * one created by goog.dom.iframe.createBlank, but already appended to - * a parent document. - * @param {string} content Content to write to the iframe, from doctype to - * the HTML close tag. - */ -goog.dom.iframe.writeContent = function(iframe, content) { - var doc = goog.dom.getFrameContentDocument(iframe); - doc.open(); - doc.write(content); - doc.close(); -}; - - -// TODO(gboyer): Provide a higher-level API for the most common use case, so -// that you can just provide a list of stylesheets and some content HTML. -/** - * Creates a same-domain iframe containing preloaded content. - * - * This is primarily useful for DOM sandboxing. One use case is to embed - * a trusted Javascript app with potentially conflicting CSS styles. The - * second case is to reduce the cost of layout passes by the browser -- for - * example, you can perform sandbox sizing of characters in an iframe while - * manipulating a heavy DOM in the main window. The iframe and parent frame - * can access each others' properties and functions without restriction. - * - * @param {!Element} parentElement The parent element in which to append the - * iframe. - * @param {string=} opt_headContents Contents to go into the iframe's head. - * @param {string=} opt_bodyContents Contents to go into the iframe's body. - * @param {string=} opt_styles CSS styles for the iframe itself, before adding - * to the parent element. - * @param {boolean=} opt_quirks Whether to use quirks mode (false by default). - * @return {HTMLIFrameElement} An iframe that has the specified contents. - */ -goog.dom.iframe.createWithContent = function( - parentElement, opt_headContents, opt_bodyContents, opt_styles, opt_quirks) { - var domHelper = goog.dom.getDomHelper(parentElement); - // Generate the HTML content. - var contentBuf = []; - - if (!opt_quirks) { - contentBuf.push('<!DOCTYPE html>'); - } - contentBuf.push('<html><head>', opt_headContents, '</head><body>', - opt_bodyContents, '</body></html>'); - - var iframe = goog.dom.iframe.createBlank(domHelper, opt_styles); - - // Cannot manipulate iframe content until it is in a document. - parentElement.appendChild(iframe); - goog.dom.iframe.writeContent(iframe, contentBuf.join('')); - - return iframe; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base deleted file mode 100644 index 5a1fcc6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base +++ /dev/null @@ -1,88 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - All Rights Reserved. - -Author: gboyer@google.com (Garrett Boyer) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.iframe</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.iframe'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> - -</head> -<body> - <div style="border: 1px solid black; padding: 4px"> - <div> - Blank Iframe - The below area should be completely white. - </div> - <!-- - - Simple table to measure the exterior size of the iframe. A table is - - used because it is sensitive to problems with iframe margins and - - vertical alignment. - --> - <table cellpadding="0" cellspacing="0"> - <tr><td> - <div id="blank"> - </div> - </td></tr> - </table> - </div> - - <div id="sandbox"></div> - -<script> - - var domHelper = goog.dom.getDomHelper(); - var sandbox = domHelper.getElement('sandbox'); - - function setUp() { - goog.dom.removeChildren(sandbox); - } - - function testCreateWithContent() { - var iframe = goog.dom.iframe.createWithContent(sandbox, - '<title>Foo Title</title>', '<div id="blah">Test</div>', - 'position: absolute', - false /* opt_quirks */); - - var doc = goog.dom.getFrameContentDocument(iframe); - assertNotNull(doc.getElementById('blah')); - assertEquals('Foo Title', doc.title); - assertEquals('absolute', iframe.style.position); - }; - - function testCreateBlankYieldsIframeWithNoBorderOrPadding() { - var iframe = goog.dom.iframe.createBlank(domHelper); - iframe.style.width = '350px'; - iframe.style.height = '250px'; - var blankElement = domHelper.getElement('blank'); - blankElement.appendChild(iframe); - assertEquals( - 'Width should be as styled: no extra borders, padding, etc.', - 350, blankElement.offsetWidth); - assertEquals( - 'Height should be as styled: no extra borders, padding, etc.', - 250, blankElement.offsetHeight); - }; - - function testCreateBlankWithStyles() { - var iframe = goog.dom.iframe.createBlank(domHelper, 'position:absolute'); - assertEquals('absolute', iframe.style.position); - assertEquals('bottom', iframe.style.verticalAlign); - }; -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base deleted file mode 100644 index 0224af3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterators over DOM nodes. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.iter.AncestorIterator'); -goog.provide('goog.dom.iter.ChildIterator'); -goog.provide('goog.dom.iter.SiblingIterator'); - -goog.require('goog.iter.Iterator'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Iterator over a Node's siblings. - * @param {Node} node The node to start with. - * @param {boolean=} opt_includeNode Whether to return the given node as the - * first return value from next. - * @param {boolean=} opt_reverse Whether to traverse siblings in reverse - * document order. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.iter.SiblingIterator = function(node, opt_includeNode, opt_reverse) { - /** - * The current node, or null if iteration is finished. - * @type {Node} - * @private - */ - this.node_ = node; - - /** - * Whether to iterate in reverse. - * @type {boolean} - * @private - */ - this.reverse_ = !!opt_reverse; - - if (node && !opt_includeNode) { - this.next(); - } -}; -goog.inherits(goog.dom.iter.SiblingIterator, goog.iter.Iterator); - - -/** @override */ -goog.dom.iter.SiblingIterator.prototype.next = function() { - var node = this.node_; - if (!node) { - throw goog.iter.StopIteration; - } - this.node_ = this.reverse_ ? node.previousSibling : node.nextSibling; - return node; -}; - - - -/** - * Iterator over an Element's children. - * @param {Element} element The element to iterate over. - * @param {boolean=} opt_reverse Optionally traverse children from last to - * first. - * @param {number=} opt_startIndex Optional starting index. - * @constructor - * @extends {goog.dom.iter.SiblingIterator} - */ -goog.dom.iter.ChildIterator = function(element, opt_reverse, opt_startIndex) { - if (!goog.isDef(opt_startIndex)) { - opt_startIndex = opt_reverse && element.childNodes.length ? - element.childNodes.length - 1 : 0; - } - goog.dom.iter.SiblingIterator.call(this, element.childNodes[opt_startIndex], - true, opt_reverse); -}; -goog.inherits(goog.dom.iter.ChildIterator, goog.dom.iter.SiblingIterator); - - - -/** - * Iterator over a Node's ancestors, stopping after the document body. - * @param {Node} node The node to start with. - * @param {boolean=} opt_includeNode Whether to return the given node as the - * first return value from next. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.iter.AncestorIterator = function(node, opt_includeNode) { - /** - * The current node, or null if iteration is finished. - * @type {Node} - * @private - */ - this.node_ = node; - - if (node && !opt_includeNode) { - this.next(); - } -}; -goog.inherits(goog.dom.iter.AncestorIterator, goog.iter.Iterator); - - -/** @override */ -goog.dom.iter.AncestorIterator.prototype.next = function() { - var node = this.node_; - if (!node) { - throw goog.iter.StopIteration; - } - this.node_ = node.parentNode; - return node; -}; - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base deleted file mode 100644 index 00485bd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base +++ /dev/null @@ -1,97 +0,0 @@ -<!DOCTYPE html> -<html id="html"> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.iter</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.iter.AncestorIterator'); - goog.require('goog.dom.iter.ChildIterator'); - goog.require('goog.dom.iter.SiblingIterator'); - goog.require('goog.dom.NodeType'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body id="body"> - <div id="test">abc<br id="br">def</div> - - -<script> -var test = goog.dom.getElement('test'); -var br = goog.dom.getElement('br'); - -function testNextSibling() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.firstChild), - ['#br', 'def']); -} - -function testNextSiblingInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.firstChild, true), - ['abc', '#br', 'def']); -} - -function testPreviousSibling() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.lastChild, false, true), - ['#br', 'abc']); -} - -function testPreviousSiblingInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.lastChild, true, true), - ['def', '#br', 'abc']); -} - -function testChildIterator() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test), - ['abc', '#br', 'def']); -} - -function testChildIteratorIndex() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, false, 1), - ['#br', 'def']); -} - -function testChildIteratorReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, true), - ['def', '#br', 'abc']); -} - -function testEmptyChildIteratorReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(br, true), []); -} - -function testChildIteratorIndexReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, true, 1), - ['#br', 'abc']); -} - -function testAncestorIterator() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.AncestorIterator(br), - ['#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); -} - -function testAncestorIteratorInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.AncestorIterator(br, true), - ['#br', '#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); -}; - -</script> -</body> -</html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base deleted file mode 100644 index 5eaa392..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base +++ /dev/null @@ -1,519 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with W3C multi-part ranges. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.MultiRange'); -goog.provide('goog.dom.MultiRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.debug.Logger'); -goog.require('goog.dom.AbstractMultiRange'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TextRange'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Creates a new multi part range with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractMultiRange} - */ -goog.dom.MultiRange = function() { - /** - * Array of browser sub-ranges comprising this multi-range. - * @type {Array.<Range>} - * @private - */ - this.browserRanges_ = []; - - /** - * Lazily initialized array of range objects comprising this multi-range. - * @type {Array.<goog.dom.TextRange>} - * @private - */ - this.ranges_ = []; - - /** - * Lazily computed sorted version of ranges_, sorted by start point. - * @type {Array.<goog.dom.TextRange>?} - * @private - */ - this.sortedRanges_ = null; - - /** - * Lazily computed container node. - * @type {Node} - * @private - */ - this.container_ = null; -}; -goog.inherits(goog.dom.MultiRange, goog.dom.AbstractMultiRange); - - -/** - * Creates a new range wrapper from the given browser selection object. Do not - * use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Selection} selection The browser selection object. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromBrowserSelection = function(selection) { - var range = new goog.dom.MultiRange(); - for (var i = 0, len = selection.rangeCount; i < len; i++) { - range.browserRanges_.push(selection.getRangeAt(i)); - } - return range; -}; - - -/** - * Creates a new range wrapper from the given browser ranges. Do not - * use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Array.<Range>} browserRanges The browser ranges. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromBrowserRanges = function(browserRanges) { - var range = new goog.dom.MultiRange(); - range.browserRanges_ = goog.array.clone(browserRanges); - return range; -}; - - -/** - * Creates a new range wrapper from the given goog.dom.TextRange objects. Do - * not use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Array.<goog.dom.TextRange>} textRanges The text range objects. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromTextRanges = function(textRanges) { - var range = new goog.dom.MultiRange(); - range.ranges_ = textRanges; - range.browserRanges_ = goog.array.map(textRanges, function(range) { - return range.getBrowserRangeObject(); - }); - return range; -}; - - -/** - * Logging object. - * @type {goog.debug.Logger} - * @private - */ -goog.dom.MultiRange.prototype.logger_ = - goog.debug.Logger.getLogger('goog.dom.MultiRange'); - - -// Method implementations - - -/** - * Clears cached values. Should be called whenever this.browserRanges_ is - * modified. - * @private - */ -goog.dom.MultiRange.prototype.clearCachedValues_ = function() { - this.ranges_ = []; - this.sortedRanges_ = null; - this.container_ = null; -}; - - -/** - * @return {goog.dom.MultiRange} A clone of this range. - */ -goog.dom.MultiRange.prototype.clone = function() { - return goog.dom.MultiRange.createFromBrowserRanges(this.browserRanges_); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getType = function() { - return goog.dom.RangeType.MULTI; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getBrowserRangeObject = function() { - // NOTE(robbyw): This method does not make sense for multi-ranges. - if (this.browserRanges_.length > 1) { - this.logger_.warning( - 'getBrowserRangeObject called on MultiRange with more than 1 range'); - } - return this.browserRanges_[0]; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.setBrowserRangeObject = function(nativeRange) { - // TODO(robbyw): Look in to adding setBrowserSelectionObject. - return false; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getTextRangeCount = function() { - return this.browserRanges_.length; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getTextRange = function(i) { - if (!this.ranges_[i]) { - this.ranges_[i] = goog.dom.TextRange.createFromBrowserRange( - this.browserRanges_[i]); - } - return this.ranges_[i]; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getContainer = function() { - if (!this.container_) { - var nodes = []; - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - nodes.push(this.getTextRange(i).getContainer()); - } - this.container_ = goog.dom.findCommonAncestor.apply(null, nodes); - } - return this.container_; -}; - - -/** - * @return {Array.<goog.dom.TextRange>} An array of sub-ranges, sorted by start - * point. - */ -goog.dom.MultiRange.prototype.getSortedRanges = function() { - if (!this.sortedRanges_) { - this.sortedRanges_ = this.getTextRanges(); - this.sortedRanges_.sort(function(a, b) { - var aStartNode = a.getStartNode(); - var aStartOffset = a.getStartOffset(); - var bStartNode = b.getStartNode(); - var bStartOffset = b.getStartOffset(); - - if (aStartNode == bStartNode && aStartOffset == bStartOffset) { - return 0; - } - - return goog.dom.Range.isReversed(aStartNode, aStartOffset, bStartNode, - bStartOffset) ? 1 : -1; - }); - } - return this.sortedRanges_; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getStartNode = function() { - return this.getSortedRanges()[0].getStartNode(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getStartOffset = function() { - return this.getSortedRanges()[0].getStartOffset(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getEndNode = function() { - // NOTE(robbyw): This may return the wrong node if any subranges overlap. - return goog.array.peek(this.getSortedRanges()).getEndNode(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getEndOffset = function() { - // NOTE(robbyw): This may return the wrong value if any subranges overlap. - return goog.array.peek(this.getSortedRanges()).getEndOffset(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.isRangeInDocument = function() { - return goog.array.every(this.getTextRanges(), function(range) { - return range.isRangeInDocument(); - }); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.isCollapsed = function() { - return this.browserRanges_.length == 0 || - this.browserRanges_.length == 1 && this.getTextRange(0).isCollapsed(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getText = function() { - return goog.array.map(this.getTextRanges(), function(range) { - return range.getText(); - }).join(''); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getHtmlFragment = function() { - return this.getValidHtml(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getValidHtml = function() { - // NOTE(robbyw): This does not behave well if the sub-ranges overlap. - return goog.array.map(this.getTextRanges(), function(range) { - return range.getValidHtml(); - }).join(''); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getPastableHtml = function() { - // TODO(robbyw): This should probably do something smart like group TR and TD - // selections in to the same table. - return this.getValidHtml(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.MultiRangeIterator(this); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.MultiRange.prototype.select = function() { - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow( - this.getWindow()); - selection.removeAllRanges(); - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - selection.addRange(this.getTextRange(i).getBrowserRangeObject()); - } -}; - - -/** @override */ -goog.dom.MultiRange.prototype.removeContents = function() { - goog.array.forEach(this.getTextRanges(), function(range) { - range.removeContents(); - }); -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.MultiRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedMultiRange_(this); -}; - - -// RANGE MODIFICATION - - -/** - * Collapses this range to a single point, either the first or last point - * depending on the parameter. This will result in the number of ranges in this - * multi range becoming 1. - * @param {boolean} toAnchor Whether to collapse to the anchor. - */ -goog.dom.MultiRange.prototype.collapse = function(toAnchor) { - if (!this.isCollapsed()) { - var range = toAnchor ? this.getTextRange(0) : this.getTextRange( - this.getTextRangeCount() - 1); - - this.clearCachedValues_(); - range.collapse(toAnchor); - this.ranges_ = [range]; - this.sortedRanges_ = [range]; - this.browserRanges_ = [range.getBrowserRangeObject()]; - } -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.MultiRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedMultiRange_ = function(range) { - /** - * Array of saved ranges. - * @type {Array.<goog.dom.SavedRange>} - * @private - */ - this.savedRanges_ = goog.array.map(range.getTextRanges(), function(range) { - return range.saveUsingDom(); - }); -}; -goog.inherits(goog.dom.DomSavedMultiRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.MultiRange} The restored range. - */ -goog.dom.DomSavedMultiRange_.prototype.restoreInternal = function() { - var ranges = goog.array.map(this.savedRanges_, function(savedRange) { - return savedRange.restore(); - }); - return goog.dom.MultiRange.createFromTextRanges(ranges); -}; - - -/** @override */ -goog.dom.DomSavedMultiRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedMultiRange_.superClass_.disposeInternal.call(this); - - goog.array.forEach(this.savedRanges_, function(savedRange) { - savedRange.dispose(); - }); - delete this.savedRanges_; -}; - - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {goog.dom.MultiRange} range The range to traverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.MultiRangeIterator = function(range) { - if (range) { - this.iterators_ = goog.array.map( - range.getSortedRanges(), - function(r) { - return goog.iter.toIterator(r); - }); - } - - goog.dom.RangeIterator.call( - this, range ? this.getStartNode() : null, false); -}; -goog.inherits(goog.dom.MultiRangeIterator, goog.dom.RangeIterator); - - -/** - * The list of range iterators left to traverse. - * @type {Array.<goog.dom.RangeIterator>?} - * @private - */ -goog.dom.MultiRangeIterator.prototype.iterators_ = null; - - -/** - * The index of the current sub-iterator being traversed. - * @type {number} - * @private - */ -goog.dom.MultiRangeIterator.prototype.currentIdx_ = 0; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getStartTextOffset = function() { - return this.iterators_[this.currentIdx_].getStartTextOffset(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getEndTextOffset = function() { - return this.iterators_[this.currentIdx_].getEndTextOffset(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getStartNode = function() { - return this.iterators_[0].getStartNode(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getEndNode = function() { - return goog.array.peek(this.iterators_).getEndNode(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.isLast = function() { - return this.iterators_[this.currentIdx_].isLast(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.next = function() { - /** @preserveTry */ - try { - var it = this.iterators_[this.currentIdx_]; - var next = it.next(); - this.setPosition(it.node, it.tagType, it.depth); - return next; - } catch (ex) { - if (ex !== goog.iter.StopIteration || - this.iterators_.length - 1 == this.currentIdx_) { - throw ex; - } else { - // In case we got a StopIteration, increment counter and try again. - this.currentIdx_++; - return this.next(); - } - } -}; - - -/** - * Replaces this iterator's values with values from another. - * @param {goog.dom.MultiRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.MultiRangeIterator.prototype.copyFrom = function(other) { - this.iterators_ = goog.array.clone(other.iterators_); - goog.dom.MultiRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.MultiRangeIterator} An identical iterator. - */ -goog.dom.MultiRangeIterator.prototype.clone = function() { - var copy = new goog.dom.MultiRangeIterator(null); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base deleted file mode 100644 index f82fc50..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base +++ /dev/null @@ -1,67 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - -Author: robbyw@google.com (Robby Walker) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.MultiRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.MultiRange'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <div id="test"> - <div id="test1">abc</div> - <div id="test2">defghi</div> - </div> - -<script> - var range; - function setUp() { - range = new goog.dom.MultiRange.createFromTextRanges([ - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test2')), - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test1')) - ]); - } - - function testStartAndEnd() { - assertEquals(goog.dom.getElement('test1').firstChild, range.getStartNode()); - assertEquals(0, range.getStartOffset()); - assertEquals(goog.dom.getElement('test2').firstChild, range.getEndNode()); - assertEquals(6, range.getEndOffset()); - } - - function testStartAndEndIterator() { - var it = goog.iter.toIterator(range); - assertEquals(goog.dom.getElement('test1').firstChild, it.getStartNode()); - assertEquals(0, it.getStartTextOffset()); - assertEquals(goog.dom.getElement('test2').firstChild, it.getEndNode()); - assertEquals(3, it.getEndTextOffset()); - - it.next(); - it.next(); - assertEquals(6, it.getEndTextOffset()); - } - - function testIteration() { - var tags = goog.iter.toArray(range); - assertEquals(2, tags.length); - - assertEquals(goog.dom.getElement('test1').firstChild, tags[0]); - assertEquals(goog.dom.getElement('test2').firstChild, tags[1]); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base deleted file mode 100644 index 7716b41..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator subclass for DOM tree traversal. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.NodeIterator'); - -goog.require('goog.dom.TagIterator'); - - - -/** - * A DOM tree traversal iterator. - * - * Starting with the given node, the iterator walks the DOM in order, reporting - * events for each node. The iterator acts as a prefix iterator: - * - * <pre> - * <div>1<span>2</span>3</div> - * </pre> - * - * Will return the following nodes: - * - * <code>[div, 1, span, 2, 3]</code> - * - * With the following depths - * - * <code>[1, 1, 2, 2, 1]</code> - * - * Imagining <code>|</code> represents iterator position, the traversal stops at - * each of the following locations: - * - * <pre><div>|1|<span>|2|</span>3|</div></pre> - * - * The iterator can also be used in reverse mode, which will return the nodes - * and states in the opposite order. The depths will be slightly different - * since, like in normal mode, the depth is computed *after* the last move. - * - * Lastly, it is possible to create an iterator that is unconstrained, meaning - * that it will continue iterating until the end of the document instead of - * until exiting the start node. - * - * @param {Node=} opt_node The start node. Defaults to an empty iterator. - * @param {boolean=} opt_reversed Whether to traverse the tree in reverse. - * @param {boolean=} opt_unconstrained Whether the iterator is not constrained - * to the starting node and its children. - * @param {number=} opt_depth The starting tree depth. - * @constructor - * @extends {goog.dom.TagIterator} - */ -goog.dom.NodeIterator = function(opt_node, opt_reversed, - opt_unconstrained, opt_depth) { - goog.dom.TagIterator.call(this, opt_node, opt_reversed, opt_unconstrained, - null, opt_depth); -}; -goog.inherits(goog.dom.NodeIterator, goog.dom.TagIterator); - - -/** - * Moves to the next position in the DOM tree. - * @return {Node} Returns the next node, or throws a goog.iter.StopIteration - * exception if the end of the iterator's range has been reached. - */ -goog.dom.NodeIterator.prototype.next = function() { - do { - goog.dom.NodeIterator.superClass_.next.call(this); - } while (this.isEndTag()); - - return this.node; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base deleted file mode 100644 index cea874e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base +++ /dev/null @@ -1,49 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.NodeIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.NodeIterator'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<!-- - The next line goes past 80 characters to avoid ambiguity with - newlines as text nodes ---> -<div id="test"><a href="#" id="a1">T<b id="b1">e</b>xt</a><span id="span1"></span><p id="p1">Text</p></div> -<ul id="test2"><li id="li1">Not<li id="li2">Closed</ul> - -<script> - function testBasic() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test')), - ['#test', '#a1', 'T', '#b1', 'e', 'xt', '#span1', '#p1', 'Text']); - } - - function testUnclosed() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test2')), - ['#test2', '#li1', 'Not', '#li2', 'Closed']); - } - - function testReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test'), true), - ['Text', '#p1', '#span1', 'xt', 'e', '#b1', 'T', '#a1', '#test']); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base deleted file mode 100644 index 9180796..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2005 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Object to store the offset from one node to another in a way - * that works on any similar DOM structure regardless of whether it is the same - * actual nodes. - * - */ - -goog.provide('goog.dom.NodeOffset'); - -goog.require('goog.Disposable'); -goog.require('goog.dom.TagName'); - - - -/** - * Object to store the offset from one node to another in a way that works on - * any similar DOM structure regardless of whether it is the same actual nodes. - * @param {Node} node The node to get the offset for. - * @param {Node} baseNode The node to calculate the offset from. - * @extends {goog.Disposable} - * @constructor - */ -goog.dom.NodeOffset = function(node, baseNode) { - goog.Disposable.call(this); - - /** - * A stack of childNode offsets. - * @type {Array.<number>} - * @private - */ - this.offsetStack_ = []; - - /** - * A stack of childNode names. - * @type {Array.<string>} - * @private - */ - this.nameStack_ = []; - - while (node && node.nodeName != goog.dom.TagName.BODY && node != baseNode) { - // Compute the sibling offset. - var siblingOffset = 0; - var sib = node.previousSibling; - while (sib) { - sib = sib.previousSibling; - ++siblingOffset; - } - this.offsetStack_.unshift(siblingOffset); - this.nameStack_.unshift(node.nodeName); - - node = node.parentNode; - } -}; -goog.inherits(goog.dom.NodeOffset, goog.Disposable); - - -/** - * @return {string} A string representation of this object. - */ -goog.dom.NodeOffset.prototype.toString = function() { - var strs = []; - var name; - for (var i = 0; name = this.nameStack_[i]; i++) { - strs.push(this.offsetStack_[i] + ',' + name); - } - return strs.join('\n'); -}; - - -/** - * Walk the dom and find the node relative to baseNode. Returns null on - * failure. - * @param {Node} baseNode The node to start walking from. Should be equivalent - * to the node passed in to the constructor, in that it should have the - * same contents. - * @return {Node} The node relative to baseNode, or null on failure. - */ -goog.dom.NodeOffset.prototype.findTargetNode = function(baseNode) { - var name; - var curNode = baseNode; - for (var i = 0; name = this.nameStack_[i]; ++i) { - curNode = curNode.childNodes[this.offsetStack_[i]]; - - // Sanity check and make sure the element names match. - if (!curNode || curNode.nodeName != name) { - return null; - } - } - return curNode; -}; - - -/** @override */ -goog.dom.NodeOffset.prototype.disposeInternal = function() { - delete this.offsetStack_; - delete this.nameStack_; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base deleted file mode 100644 index b92b8f7..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base +++ /dev/null @@ -1,88 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.NodeOffset Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.NodeOffset'); - goog.require('goog.dom.NodeType'); - goog.require('goog.dom.TagName'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<div id="test1">Text<br> and <b>more <i id="i">text.</i></b></div> -<div id="test2"></div> -<div id="empty"></div> - -<script> - var test1 = goog.dom.getElement('test1'); - var i = goog.dom.getElement('i'); - - var test2 = goog.dom.getElement('test2'); - test2.innerHTML = test1.innerHTML; - - var empty = goog.dom.getElement('empty'); - - function testElementOffset() { - var nodeOffset = new goog.dom.NodeOffset(i, test1); - - var recovered = nodeOffset.findTargetNode(test2); - assertNotNull('Should recover a node.', recovered); - assertEquals('Should recover an I node.', goog.dom.TagName.I, - recovered.tagName); - assertTrue('Should recover a child of test2', - goog.dom.contains(test2, recovered)); - assertFalse('Should not recover a child of test1', - goog.dom.contains(test1, recovered)); - - nodeOffset.dispose(); - } - - function testNodeOffset() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - var recovered = nodeOffset.findTargetNode(test2); - assertNotNull('Should recover a node.', recovered); - assertEquals('Should recover a text node.', goog.dom.NodeType.TEXT, - recovered.nodeType); - assertEquals('Should have correct contents.', 'text.', - recovered.nodeValue); - assertTrue('Should recover a child of test2', - goog.dom.contains(test2, recovered)); - assertFalse('Should not recover a child of test1', - goog.dom.contains(test1, recovered)); - - nodeOffset.dispose(); - } - - function testToString() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - assertEquals('Should have correct string representation', - '3,B\n1,I\n0,#text', nodeOffset.toString()); - - nodeOffset.dispose(); - } - - function testBadRecovery() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - var recovered = nodeOffset.findTargetNode(empty); - assertNull('Should recover nothing.', recovered); - - nodeOffset.dispose(); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base deleted file mode 100644 index 4df2a20..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with ranges in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - -goog.provide('goog.dom.Range'); - -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.ControlRange'); -goog.require('goog.dom.MultiRange'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.TextRange'); -goog.require('goog.userAgent'); - - -/** - * Create a new selection from the given browser window's current selection. - * Note that this object does not auto-update if the user changes their - * selection and should be used as a snapshot. - * @param {Window=} opt_win The window to get the selection of. Defaults to the - * window this class was defined in. - * @return {goog.dom.AbstractRange?} A range wrapper object, or null if there - * was an error. - */ -goog.dom.Range.createFromWindow = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - return sel && goog.dom.Range.createFromBrowserSelection(sel); -}; - - -/** - * Create a new range wrapper from the given browser selection object. Note - * that this object does not auto-update if the user changes their selection and - * should be used as a snapshot. - * @param {!Object} selection The browser selection object. - * @return {goog.dom.AbstractRange?} A range wrapper object or null if there - * was an error. - */ -goog.dom.Range.createFromBrowserSelection = function(selection) { - var range; - var isReversed = false; - if (selection.createRange) { - /** @preserveTry */ - try { - range = selection.createRange(); - } catch (e) { - // Access denied errors can be thrown here in IE if the selection was - // a flash obj or if there are cross domain issues - return null; - } - } else if (selection.rangeCount) { - if (selection.rangeCount > 1) { - return goog.dom.MultiRange.createFromBrowserSelection( - /** @type {Selection} */ (selection)); - } else { - range = selection.getRangeAt(0); - isReversed = goog.dom.Range.isReversed(selection.anchorNode, - selection.anchorOffset, selection.focusNode, selection.focusOffset); - } - } else { - return null; - } - - return goog.dom.Range.createFromBrowserRange(range, isReversed); -}; - - -/** - * Create a new range wrapper from the given browser range object. - * @param {Range|TextRange} range The browser range object. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromBrowserRange = function(range, opt_isReversed) { - // Create an IE control range when appropriate. - return goog.dom.AbstractRange.isNativeControlRange(range) ? - goog.dom.ControlRange.createFromBrowserRange(range) : - goog.dom.TextRange.createFromBrowserRange(range, opt_isReversed); -}; - - -/** - * Create a new range wrapper that selects the given node's text. - * @param {Node} node The node to select. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromNodeContents = function(node, opt_isReversed) { - return goog.dom.TextRange.createFromNodeContents(node, opt_isReversed); -}; - - -/** - * Create a new range wrapper that represents a caret at the given node, - * accounting for the given offset. This always creates a TextRange, regardless - * of whether node is an image node or other control range type node. - * @param {Node} node The node to place a caret at. - * @param {number} offset The offset within the node to place the caret at. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createCaret = function(node, offset) { - return goog.dom.TextRange.createFromNodes(node, offset, node, offset); -}; - - -/** - * Create a new range wrapper that selects the area between the given nodes, - * accounting for the given offsets. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromNodes = function(startNode, startOffset, endNode, - endOffset) { - return goog.dom.TextRange.createFromNodes(startNode, startOffset, endNode, - endOffset); -}; - - -/** - * Clears the window's selection. - * @param {Window=} opt_win The window to get the selection of. Defaults to the - * window this class was defined in. - */ -goog.dom.Range.clearSelection = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - if (!sel) { - return; - } - if (sel.empty) { - // We can't just check that the selection is empty, becuase IE - // sometimes gets confused. - try { - sel.empty(); - } catch (e) { - // Emptying an already empty selection throws an exception in IE - } - } else { - try { - sel.removeAllRanges(); - } catch (e) { - // This throws in IE9 if the range has been invalidated; for example, if - // the user clicked on an element which disappeared during the event - // handler. - } - } -}; - - -/** - * Tests if the window has a selection. - * @param {Window=} opt_win The window to check the selection of. Defaults to - * the window this class was defined in. - * @return {boolean} Whether the window has a selection. - */ -goog.dom.Range.hasSelection = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - return !!sel && (goog.userAgent.IE ? sel.type != 'None' : !!sel.rangeCount); -}; - - -/** - * Returns whether the focus position occurs before the anchor position. - * @param {Node} anchorNode The node to start with. - * @param {number} anchorOffset The offset within the node to start. - * @param {Node} focusNode The node to end with. - * @param {number} focusOffset The offset within the node to end. - * @return {boolean} Whether the focus position occurs before the anchor - * position. - */ -goog.dom.Range.isReversed = function(anchorNode, anchorOffset, focusNode, - focusOffset) { - if (anchorNode == focusNode) { - return focusOffset < anchorOffset; - } - var child; - if (anchorNode.nodeType == goog.dom.NodeType.ELEMENT && anchorOffset) { - child = anchorNode.childNodes[anchorOffset]; - if (child) { - anchorNode = child; - anchorOffset = 0; - } else if (goog.dom.contains(anchorNode, focusNode)) { - // If focus node is contained in anchorNode, it must be before the - // end of the node. Hence we are reversed. - return true; - } - } - if (focusNode.nodeType == goog.dom.NodeType.ELEMENT && focusOffset) { - child = focusNode.childNodes[focusOffset]; - if (child) { - focusNode = child; - focusOffset = 0; - } else if (goog.dom.contains(focusNode, anchorNode)) { - // If anchor node is contained in focusNode, it must be before the - // end of the node. Hence we are not reversed. - return false; - } - } - return (goog.dom.compareNodeOrder(anchorNode, focusNode) || - anchorOffset - focusOffset) > 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base deleted file mode 100644 index 14070be..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base +++ /dev/null @@ -1,702 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.Range</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1">Text</div> - <div id="test2">abc<br id="br">def</div> - <div id="empty"></div> - <div id="test3"><div></div></div> - <div id="removeTest"><div>Text that<br/>will be deleted</div></div> - <div id="surroundTest"></div> - <div id="insertTest"></div> - <div id="surroundWithNodesTest"></div> - <div id="removePartialTest">012345</div> - <table id="tableTest"><tr><td id="cell">1</td><td>2</td></tr></table> - <div id="ulTest"><ul><li>1</li><li>2</li></ul></div> - <div id="olTest"><ol><li>1</li><li>2</li></ol></div> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - <div id="removeNodeTest"><div>Will be removed</div></div> - - <div id='bug1480638'></div> - <div id='textWithSpaces'>hello world !</div> - <div contentEditable=true> - <div id='rangeAroundBreaks'>abcd<br />e</div> - <div id='breaksAroundNode'><br />abcde<br /></div> - </div> - -<script> - var assertRangeEquals = goog.testing.dom.assertRangeEquals; - - function normalizeHtml(str) { - return str.toLowerCase().replace(/[\n\r\f"]/g, '') - .replace(/<\/li>/g, ''); // " for emacs - } - - function testCreate() { - assertNotNull('Browser range object can be created for node', - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test1'))); - } - - function testTableRange() { - var tr = goog.dom.getElement('cell').parentNode; - var range = goog.dom.Range.createFromNodeContents(tr); - assertEquals('Selection should have correct text', '12', - range.getText()); - assertEquals('Selection should have correct html fragment', - '1</td><td>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the TR is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<tr id=row><td>1</td><td>2</td></tr>', - // normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<table><tbody><tr><td id=cell>1</td><td>2</td></tr></tbody></table>', - normalizeHtml(range.getPastableHtml())); - } - - function testUnorderedListRange() { - var ul = goog.dom.getElement('ulTest').firstChild; - var range = goog.dom.Range.createFromNodeContents(ul); - assertEquals('Selection should have correct html fragment', - '1<li>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the UL is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<li>1</li><li>2</li>', normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<ul><li>1<li>2</ul>', - normalizeHtml(range.getPastableHtml())); - } - - function testOrderedListRange() { - var ol = goog.dom.getElement('olTest').firstChild; - var range = goog.dom.Range.createFromNodeContents(ol); - assertEquals('Selection should have correct html fragment', - '1<li>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the OL is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<li>1</li><li>2</li>', normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<ol><li>1<li>2</ol>', - normalizeHtml(range.getPastableHtml())); - } - - function testCreateFromNodes() { - var start = goog.dom.getElement('test1').firstChild; - var end = goog.dom.getElement('br'); - var range = goog.dom.Range.createFromNodes(start, 2, end, 0); - assertNotNull('Browser range object can be created for W3C node range', - range); - - assertEquals('Start node should be selected at start endpoint', start, - range.getStartNode()); - assertEquals('Selection should start at offset 2', 2, - range.getStartOffset()); - assertEquals('Start node should be selected at anchor endpoint', start, - range.getAnchorNode()); - assertEquals('Selection should be anchored at offset 2', 2, - range.getAnchorOffset()); - - var div = goog.dom.getElement('test2'); - assertEquals('DIV node should be selected at end endpoint', div, - range.getEndNode()); - assertEquals('Selection should end at offset 1', 1, range.getEndOffset()); - assertEquals('DIV node should be selected at focus endpoint', div, - range.getFocusNode()); - assertEquals('Selection should be focused at offset 1', 1, - range.getFocusOffset()); - - - assertTrue('Text content should be "xt\\s*abc"', - /xt\s*abc/.test(range.getText())); - assertFalse('Nodes range is not collapsed', range.isCollapsed()); - } - - - function testCreateControlRange() { - if (!goog.userAgent.IE) { - return; - } - var cr = document.body.createControlRange(); - cr.addElement(goog.dom.getElement('logo')); - - var range = goog.dom.Range.createFromBrowserRange(cr); - assertNotNull('Control range object can be created from browser range', - range); - assertEquals('Created range is a control range', goog.dom.RangeType.CONTROL, - range.getType()); - } - - - function testTextNode() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1').firstChild); - - assertEquals('Created range is a text range', goog.dom.RangeType.TEXT, - range.getType()); - assertEquals('Text node should be selected at start endpoint', 'Text', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node should be selected at end endpoint', 'Text', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 4', 'Text'.length, - range.getEndOffset()); - - assertEquals('Container should be text node', goog.dom.NodeType.TEXT, - range.getContainer().nodeType); - - assertEquals('Text content should be "Text"', 'Text', range.getText()); - assertFalse('Text range is not collapsed', range.isCollapsed()); - } - - - function testDiv() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')); - - assertEquals('Text node "abc" should be selected at start endpoint', 'abc', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node "def" should be selected at end endpoint', 'def', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 3', 'def'.length, - range.getEndOffset()); - - assertEquals('Container should be DIV', goog.dom.getElement('test2'), - range.getContainer()); - - assertTrue('Div text content should be "abc\\s*def"', - /abc\s*def/.test(range.getText())); - assertFalse('Div range is not collapsed', range.isCollapsed()); - } - - - function testEmptyNode() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('empty')); - - assertEquals('DIV be selected at start endpoint', - goog.dom.getElement('empty'), range.getStartNode()); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('DIV should be selected at end endpoint', - goog.dom.getElement('empty'), range.getEndNode()); - assertEquals('Selection should end at offset 0', 0, - range.getEndOffset()); - - assertEquals('Container should be DIV', goog.dom.getElement('empty'), - range.getContainer()); - - assertEquals('Empty text content should be ""', '', range.getText()); - assertTrue('Empty range is collapsed', range.isCollapsed()); - } - - - function testCollapse() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')); - assertFalse('Div range is not collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Div range is collapsed after call to empty()', - range.isCollapsed()); - - range = goog.dom.Range.createFromNodeContents(goog.dom.getElement('empty')); - assertTrue('Empty range is collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Empty range is still collapsed', range.isCollapsed()); - } - - // TODO(robbyw): Test iteration over a strange document fragment. - - function testIterator() { - goog.testing.dom.assertNodesMatch(goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')), ['abc', '#br', '#br', 'def']); - } - - function testReversedNodes() { - var node = goog.dom.getElement('test1').firstChild; - var range = goog.dom.Range.createFromNodes(node, 4, node, 0); - assertTrue('Range is reversed', range.isReversed()); - node = goog.dom.getElement('test3'); - range = goog.dom.Range.createFromNodes(node, 0, node, 1); - assertFalse('Range is not reversed', range.isReversed()); - } - - function testReversedContents() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1'), true); - assertTrue('Range is reversed', range.isReversed()); - assertEquals('Range should select "Text"', 'Text', - range.getText()); - assertEquals('Range start offset should be 0', 0, range.getStartOffset()); - assertEquals('Range end offset should be 4', 4, range.getEndOffset()); - assertEquals('Range anchor offset should be 4', 4, range.getAnchorOffset()); - assertEquals('Range focus offset should be 0', 0, range.getFocusOffset()); - - var range2 = range.clone(); - - range.collapse(true); - assertTrue('Range is collapsed', range.isCollapsed()); - assertFalse('Collapsed range is not reversed', range.isReversed()); - assertEquals('Post collapse start offset should be 4', 4, - range.getStartOffset()); - - range2.collapse(false); - assertTrue('Range 2 is collapsed', range2.isCollapsed()); - assertFalse('Collapsed range 2 is not reversed', range2.isReversed()); - assertEquals('Post collapse start offset 2 should be 0', 0, - range2.getStartOffset()); - } - - function testRemoveContents() { - var outer = goog.dom.getElement('removeTest'); - var range = goog.dom.Range.createFromNodeContents(outer.firstChild); - - range.removeContents(); - - assertEquals('Removed range content should be ""', '', range.getText()); - assertTrue('Removed range should be collapsed', range.isCollapsed()); - assertEquals('Outer div should have 1 child now', 1, - outer.childNodes.length); - assertEquals('Inner div should be empty', 0, - outer.firstChild.childNodes.length); - } - - function testRemovePartialContents() { - var outer = goog.dom.getElement('removePartialTest'); - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 2, - outer.firstChild, 4); - removeHelper(1, range, outer, 1, '0145'); - - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, - outer.firstChild, 1); - removeHelper(2, range, outer, 1, '145'); - - range = goog.dom.Range.createFromNodes(outer.firstChild, 2, - outer.firstChild, 3); - removeHelper(3, range, outer, 1, '14'); - - var br = goog.dom.createDom('BR'); - outer.appendChild(br); - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer, 1); - removeHelper(4, range, outer, 2, '1<br>'); - - outer.innerHTML = '<br>123'; - range = goog.dom.Range.createFromNodes(outer, 0, outer.lastChild, 2); - removeHelper(5, range, outer, 1, '3'); - - outer.innerHTML = '123<br>456'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, outer.lastChild, - 2); - removeHelper(6, range, outer, 2, '16'); - - outer.innerHTML = '123<br>456'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, outer.lastChild, - 2); - removeHelper(7, range, outer, 1, '6'); - - outer.innerHTML = '<div></div>'; - range = goog.dom.Range.createFromNodeContents(outer.firstChild); - removeHelper(8, range, outer, 1, '<div></div>'); - - // TODO(robbyw): Fix the following edge cases: - // * Selecting contents of a node containing multiply empty divs - // * Selecting via createFromNodes(x, 0, x, x.childNodes.length) - // * Consistent handling of nodeContents(<div><div></div></div>).remove - } - - function removeHelper(testNumber, range, outer, expectedChildCount, - expectedContent) { - range.removeContents(); - assertTrue(testNumber + ': Removed range should now be collapsed', - range.isCollapsed()); - assertEquals(testNumber + ': Removed range content should be ""', '', - range.getText()); - assertEquals(testNumber + ': Outer div should contain correct text', - expectedContent, outer.innerHTML.toLowerCase()); - assertEquals(testNumber + ': Outer div should have ' + expectedChildCount + - ' children now', expectedChildCount, outer.childNodes.length); - assertNotNull(testNumber + ': Empty node should still exist', - goog.dom.getElement('empty')); - } - - function testSurroundContents() { - var outer = goog.dom.getElement('surroundTest'); - outer.innerHTML = '---Text that<br/>will be surrounded---'; - var range = goog.dom.Range.createFromNodes(outer.firstChild, 3, - outer.lastChild, outer.lastChild.nodeValue.length - 3); - - var div = goog.dom.createDom(goog.dom.TagName.DIV, {'style': 'color: red'}); - var output = range.surroundContents(div); - - assertEquals('Outer element should contain new element', outer, - output.parentNode); - assertFalse('New element should have no id', !!output.id); - assertEquals('New element should be red', 'red', output.style.color); - assertEquals('Outer element should have three children', 3, - outer.childNodes.length); - assertEquals('New element should have three children', 3, - output.childNodes.length); - - // TODO(robbyw): Ensure the range stays in a reasonable state. - } - - /** - * Given two offsets into the 'foobar' node, make sure that inserting - * nodes at those offsets doesn't change a selection of 'oba'. - * @bug 1480638 - */ - function assertSurroundDoesntChangeSelectionWithOffsets( - offset1, offset2, expectedHtml) { - var div = goog.dom.getElement('bug1480638'); - div.innerHTML = 'foobar'; - var rangeToSelect = goog.dom.Range.createFromNodes( - div.firstChild, 2, div.firstChild, 5); - rangeToSelect.select(); - - var rangeToSurround = goog.dom.Range.createFromNodes( - div.firstChild, offset1, div.firstChild, offset2); - rangeToSurround.surroundWithNodes(goog.dom.createDom('span'), - goog.dom.createDom('span')); - - // Make sure that the selection didn't change. - assertHTMLEquals('Selection must not change when contents are surrounded.', - expectedHtml, goog.dom.Range.createFromWindow().getHtmlFragment()); - } - - function testSurroundWithNodesDoesntChangeSelection1() { - assertSurroundDoesntChangeSelectionWithOffsets(3, 4, - 'o<span></span>b<span></span>a'); - } - - function testSurroundWithNodesDoesntChangeSelection2() { - assertSurroundDoesntChangeSelectionWithOffsets(3, 6, - 'o<span></span>ba'); - } - - function testSurroundWithNodesDoesntChangeSelection3() { - assertSurroundDoesntChangeSelectionWithOffsets(1, 3, - 'o<span></span>ba'); - } - - function testSurroundWithNodesDoesntChangeSelection4() { - assertSurroundDoesntChangeSelectionWithOffsets(1, 6, - 'oba'); - } - - function testInsertNode() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'ACD'; - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - range.insertNode(goog.dom.createTextNode('B'), true); - assertEquals('Element should have correct innerHTML', 'ABCD', - outer.innerHTML); - - outer.innerHTML = '12'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, - outer.firstChild, 1); - var br = range.insertNode(goog.dom.createDom(goog.dom.TagName.BR), false); - assertEquals('New element should have correct innerHTML', '1<br>2', - outer.innerHTML.toLowerCase()); - assertEquals('BR should be in outer', outer, br.parentNode); - } - - function testReplaceContentsWithNode() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'AXC'; - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - range.replaceContentsWithNode(goog.dom.createTextNode('B')); - assertEquals('Element should have correct innerHTML', 'ABC', - outer.innerHTML); - - outer.innerHTML = 'ABC'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 3, - outer.firstChild, 3); - range.replaceContentsWithNode(goog.dom.createTextNode('D')); - assertEquals( - 'Element should have correct innerHTML after collapsed replace', - 'ABCD', outer.innerHTML); - - outer.innerHTML = 'AX<b>X</b>XC'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.lastChild, 1); - range.replaceContentsWithNode(goog.dom.createTextNode('B')); - goog.testing.dom.assertHtmlContentsMatch('ABC', outer); - } - - function testSurroundWithNodes() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'ACE'; - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - - range.surroundWithNodes(goog.dom.createTextNode('B'), - goog.dom.createTextNode('D')); - - assertEquals('New element should have correct innerHTML', 'ABCDE', - outer.innerHTML); - } - - function testIsRangeInDocument() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = '<br>ABC'; - var range = goog.dom.Range.createCaret(outer.lastChild, 1); - - assertEquals('Should get correct start element', 'ABC', - range.getStartNode().nodeValue); - assertTrue('Should be considered in document', range.isRangeInDocument()); - - outer.innerHTML = 'DEF'; - - assertFalse('Should be marked as out of document', - range.isRangeInDocument()); - } - - function testRemovedNode() { - var node = goog.dom.getElement('removeNodeTest'); - var range = goog.dom.browserrange.createRangeFromNodeContents(node); - range.select(); - goog.dom.removeNode(node); - - var newRange = goog.dom.Range.createFromWindow(window); - if (goog.userAgent.WEBKIT) { - assertNull('Webkit supports rangeCount == 0', newRange); - } else { - assertTrue('The other browsers will just have an empty range.', - newRange.isCollapsed()); - } - } - - function testReversedRange() { - goog.dom.Range.createFromNodes(goog.dom.getElement('test2'), 0, - goog.dom.getElement('test1'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertTrue('Range should be reversed', - goog.userAgent.IE || range.isReversed()); - } - - function testUnreversedRange() { - goog.dom.Range.createFromNodes(goog.dom.getElement('test1'), 0, - goog.dom.getElement('test2'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertFalse('Range should not be reversed', range.isReversed()); - } - - function testReversedThenUnreversedRange() { - // This tests a workaround for a webkit bug where webkit caches selections - // incorrectly. - goog.dom.Range.createFromNodes(goog.dom.getElement('test2'), 0, - goog.dom.getElement('test1'), 0).select(); - goog.dom.Range.createFromNodes(goog.dom.getElement('test1'), 0, - goog.dom.getElement('test2'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertFalse('Range should not be reversed', range.isReversed()); - } - - function testHasAndClearSelection() { - goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1')).select(); - - assertTrue('Selection should exist', goog.dom.Range.hasSelection()); - - goog.dom.Range.clearSelection(); - - assertFalse('Selection should not exist', goog.dom.Range.hasSelection()); - } - - function assertForward(string, startNode, startOffset, endNode, endOffset) { - var root = goog.dom.getElement('test2'); - var originalInnerHtml = root.innerHTML; - - assertFalse(string, goog.dom.Range.isReversed(startNode, startOffset, - endNode, endOffset)); - assertTrue(string, goog.dom.Range.isReversed(endNode, endOffset, - startNode, startOffset)); - assertEquals('Contents should be unaffected after: ' + string, - root.innerHTML, originalInnerHtml); - } - - function testIsReversed() { - var root = goog.dom.getElement('test2'); - var text1 = root.firstChild; // Text content: 'abc'. - var br = root.childNodes[1]; - var text2 = root.lastChild; // Text content: 'def'. - - assertFalse('Same element position gives false', goog.dom.Range.isReversed( - root, 0, root, 0)); - assertFalse('Same text position gives false', goog.dom.Range.isReversed( - text1, 0, text2, 0)); - assertForward('Element offsets should compare against each other', - root, 0, root, 2); - assertForward('Text node offsets should compare against each other', - text1, 0, text2, 2); - assertForward('Text nodes should compare correctly', - text1, 0, text2, 0); - assertForward('Text nodes should compare to later elements', - text1, 0, br, 0); - assertForward('Text nodes should compare to earlier elements', - br, 0, text2, 0); - assertForward('Parent is before element child', root, 0, br, 0); - assertForward('Parent is before text child', root, 0, text1, 0); - assertFalse('Equivalent position gives false', goog.dom.Range.isReversed( - root, 0, text1, 0)); - assertFalse('Equivalent position gives false', goog.dom.Range.isReversed( - root, 1, br, 0)); - assertForward('End of element is after children', text1, 0, root, 3); - assertForward('End of element is after children', br, 0, root, 3); - assertForward('End of element is after children', text2, 0, root, 3); - assertForward('End of element is after end of last child', - text2, 3, root, 3); - } - - function testSelectAroundSpaces() { - // set the selection - var textNode = goog.dom.getElement('textWithSpaces').firstChild; - goog.dom.TextRange.createFromNodes( - textNode, 5, textNode, 12).select(); - - // get the selection and check that it matches what we set it to - var range = goog.dom.Range.createFromWindow(); - assertEquals(' world ', range.getText()); - assertEquals(5, range.getStartOffset()); - assertEquals(12, range.getEndOffset()); - assertEquals(textNode, range.getContainer()); - - // Check the contents again, because there used to be a bug where - // it changed after calling getContainer(). - assertEquals(' world ', range.getText()); - } - - function testSelectInsideSpaces() { - // set the selection - var textNode = goog.dom.getElement('textWithSpaces').firstChild; - goog.dom.TextRange.createFromNodes( - textNode, 6, textNode, 11).select(); - - // get the selection and check that it matches what we set it to - var range = goog.dom.Range.createFromWindow(); - assertEquals('world', range.getText()); - assertEquals(6, range.getStartOffset()); - assertEquals(11, range.getEndOffset()); - assertEquals(textNode, range.getContainer()); - - // Check the contents again, because there used to be a bug where - // it changed after calling getContainer(). - assertEquals('world', range.getText()); - } - - function testRangeBeforeBreak() { - var container = goog.dom.getElement('rangeAroundBreaks'); - var text = container.firstChild; - var offset = text.length; - assertEquals(4, offset); - - var br = container.childNodes[1]; - var caret = goog.dom.Range.createCaret(text, offset); - caret.select(); - assertEquals(offset, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - if (goog.userAgent.IE) { - assertTrue('Range over <br> is adjacent to the immediate range before it', - range.containsNode(br, true)); - } else { - assertFalse('Should not contain partial <br>', - range.containsNode(br, true)); - } - - assertEquals(offset, range.getStartOffset()); - assertEquals(text, range.getStartNode()); - } - - function testRangeAfterBreak() { - var container = goog.dom.getElement('rangeAroundBreaks'); - var br = container.childNodes[1]; - var caret = goog.dom.Range.createCaret(container.lastChild, 0); - caret.select(); - assertEquals(0, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - var isSafari3 = goog.userAgent.WEBKIT && !goog.userAgent.isVersion('528'); - - if (goog.userAgent.IE || isSafari3) { - assertTrue('Range over <br> is adjacent to the immediate range after it', - range.containsNode(br, true)); - } else { - assertFalse('Should not contain partial <br>', - range.containsNode(br, true)); - } - - if (isSafari3) { - assertEquals(2, range.getStartOffset()); - assertEquals(container, range.getStartNode()); - } else { - assertEquals(0, range.getStartOffset()); - assertEquals(container.lastChild, range.getStartNode()); - } - } - - function testRangeAtBreakAtStart() { - var container = goog.dom.getElement('breaksAroundNode'); - var br = container.firstChild; - var caret = goog.dom.Range.createCaret(container.firstChild, 0); - caret.select(); - assertEquals(0, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertTrue('Range over <br> is adjacent to the immediate range before it', - range.containsNode(br, true)); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - - assertRangeEquals(container, 0, container, 0, range); - } - - function assertNodeEquals(expected, actual) { - assertEquals( - 'Expected: ' + goog.testing.dom.exposeNode(expected) + - '\nActual: ' + goog.testing.dom.exposeNode(actual), - expected, actual); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base deleted file mode 100644 index f8d0fe4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Simple struct for endpoints of a range. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.RangeEndpoint'); - - -/** - * Constants for selection endpoints. - * @enum {number} - */ -goog.dom.RangeEndpoint = { - START: 1, - END: 0 -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base deleted file mode 100644 index 31d3134..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview An API for saving and restoring ranges as HTML carets. - * - * @author nicksantos@google.com (Nick Santos) - */ - - -goog.provide('goog.dom.SavedCaretRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagName'); -goog.require('goog.string'); - - - -/** - * A struct for holding context about saved selections. - * This can be used to preserve the selection and restore while the DOM is - * manipulated, or through an asynchronous call. Use goog.dom.Range factory - * methods to obtain an {@see goog.dom.AbstractRange} instance, and use - * {@see goog.dom.AbstractRange#saveUsingCarets} to obtain a SavedCaretRange. - * For editor ranges under content-editable elements or design-mode iframes, - * prefer using {@see goog.editor.range.saveUsingNormalizedCarets}. - * @param {goog.dom.AbstractRange} range The range being saved. - * @constructor - * @extends {goog.dom.SavedRange} - */ -goog.dom.SavedCaretRange = function(range) { - goog.dom.SavedRange.call(this); - - /** - * The DOM id of the caret at the start of the range. - * @type {string} - * @private - */ - this.startCaretId_ = goog.string.createUniqueString(); - - /** - * The DOM id of the caret at the end of the range. - * @type {string} - * @private - */ - this.endCaretId_ = goog.string.createUniqueString(); - - /** - * A DOM helper for storing the current document context. - * @type {goog.dom.DomHelper} - * @private - */ - this.dom_ = goog.dom.getDomHelper(range.getDocument()); - - range.surroundWithNodes(this.createCaret_(true), this.createCaret_(false)); -}; -goog.inherits(goog.dom.SavedCaretRange, goog.dom.SavedRange); - - -/** - * Gets the range that this SavedCaretRage represents, without selecting it - * or removing the carets from the DOM. - * @return {goog.dom.AbstractRange?} An abstract range. - */ -goog.dom.SavedCaretRange.prototype.toAbstractRange = function() { - var range = null; - var startCaret = this.getCaret(true); - var endCaret = this.getCaret(false); - if (startCaret && endCaret) { - range = goog.dom.Range.createFromNodes(startCaret, 0, endCaret, 0); - } - return range; -}; - - -/** - * Gets carets. - * @param {boolean} start If true, returns the start caret. Otherwise, get the - * end caret. - * @return {Element} The start or end caret in the given document. - */ -goog.dom.SavedCaretRange.prototype.getCaret = function(start) { - return this.dom_.getElement(start ? this.startCaretId_ : this.endCaretId_); -}; - - -/** - * Removes the carets from the current restoration document. - * @param {goog.dom.AbstractRange=} opt_range A range whose offsets have already - * been adjusted for caret removal; it will be adjusted if it is also - * affected by post-removal operations, such as text node normalization. - * @return {goog.dom.AbstractRange|undefined} The adjusted range, if opt_range - * was provided. - */ -goog.dom.SavedCaretRange.prototype.removeCarets = function(opt_range) { - goog.dom.removeNode(this.getCaret(true)); - goog.dom.removeNode(this.getCaret(false)); - return opt_range; -}; - - -/** - * Sets the document where the range will be restored. - * @param {!Document} doc An HTML document. - */ -goog.dom.SavedCaretRange.prototype.setRestorationDocument = function(doc) { - this.dom_.setDocument(doc); -}; - - -/** - * Reconstruct the selection from the given saved range. Removes carets after - * restoring the selection. If restore does not dispose this saved range, it may - * only be restored a second time if innerHTML or some other mechanism is used - * to restore the carets to the dom. - * @return {goog.dom.AbstractRange?} Restored selection. - * @override - * @protected - */ -goog.dom.SavedCaretRange.prototype.restoreInternal = function() { - var range = null; - var startCaret = this.getCaret(true); - var endCaret = this.getCaret(false); - if (startCaret && endCaret) { - var startNode = startCaret.parentNode; - var startOffset = goog.array.indexOf(startNode.childNodes, startCaret); - var endNode = endCaret.parentNode; - var endOffset = goog.array.indexOf(endNode.childNodes, endCaret); - if (endNode == startNode) { - // Compensate for the start caret being removed. - endOffset -= 1; - } - range = goog.dom.Range.createFromNodes(startNode, startOffset, - endNode, endOffset); - range = this.removeCarets(range); - range.select(); - } else { - // If only one caret was found, remove it. - this.removeCarets(); - } - return range; -}; - - -/** - * Dispose the saved range and remove the carets from the DOM. - * @override - * @protected - */ -goog.dom.SavedCaretRange.prototype.disposeInternal = function() { - this.removeCarets(); - this.dom_ = null; -}; - - -/** - * Creates a caret element. - * @param {boolean} start If true, creates the start caret. Otherwise, - * creates the end caret. - * @return {Element} The new caret element. - * @private - */ -goog.dom.SavedCaretRange.prototype.createCaret_ = function(start) { - return this.dom_.createDom(goog.dom.TagName.SPAN, - {'id': start ? this.startCaretId_ : this.endCaretId_}); -}; - - -/** - * A regex that will match all saved range carets in a string. - * @type {RegExp} - */ -goog.dom.SavedCaretRange.CARET_REGEX = /<span\s+id="?goog_\d+"?><\/span>/ig; - - -/** - * Returns whether two strings of html are equal, ignoring any saved carets. - * Thus two strings of html whose only difference is the id of their saved - * carets will be considered equal, since they represent html with the - * same selection. - * @param {string} str1 The first string. - * @param {string} str2 The second string. - * @return {boolean} Whether two strings of html are equal, ignoring any - * saved carets. - */ -goog.dom.SavedCaretRange.htmlEqual = function(str1, str2) { - return str1 == str2 || - str1.replace(goog.dom.SavedCaretRange.CARET_REGEX, '') == - str2.replace(goog.dom.SavedCaretRange.CARET_REGEX, ''); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base deleted file mode 100644 index 22a1b4a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base +++ /dev/null @@ -1,235 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.SavedCaretRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.userAgent'); - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <div id='caretRangeTest'> - abc - <div id='def'>def</div> - ghi - <div id='jkl'>jkl</div> - mno - <div id='pqr'>pqr</div> - stu - </div> - - <div id='caretRangeTest-2'> - abc - <div id='def-2'>def</div> - ghi - <div id='jkl-2'>jkl</div> - mno - <div id='pqr-2'>pqr</div> - stu - </div> - - <div id='caretRangeTest-3'> - abc - <div id='def-3'>def</div> - ghi - <div id='jkl-3'>jkl</div> - mno - <div id='pqr-3'>pqr</div> - stu - </div> - - <div id='removeContentsTest'> - abc - <div id='def-4'>def</div> - ghi - <div id='jkl-4'>jkl</div> - mno - <div id='pqr-4'>pqr</div> - stu - </div> - - <div id='bug1480638'>foo<table><tr><td>bar</td></tr></table>baz</div> - -<script> - /** @bug 1480638 */ - function testSavedCaretRangeDoesntChangeSelection() { - // NOTE(nicksantos): We cannot detect this bug programatically. The only - // way to detect it is to run this test manually and look at the selection - // when it ends. - var div = goog.dom.getElement('bug1480638'); - var range = goog.dom.Range.createFromNodes( - div.firstChild, 0, div.lastChild, 1); - range.select(); - - // Observe visible selection. Then move to next line and see it change. - // If the bug exists, it starts with "foo" selected and ends with - // it not selected. - //debugger; - var saved = range.saveUsingCarets(); - } - - function testSavedCaretRange() { - var parent = goog.dom.getElement('caretRangeTest'); - var def = goog.dom.getElement('def'); - var jkl = goog.dom.getElement('jkl'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - assertHTMLEquals( - "d<span id='" + saved.startCaretId_ + "'></span>ef", def.innerHTML); - assertHTMLEquals( - "jk<span id='" + saved.endCaretId_ + "'></span>l", jkl.innerHTML); - - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[1], 0, - saved.toAbstractRange()); - - def = goog.dom.getElement('def'); - jkl = goog.dom.getElement('jkl'); - - var restoredRange = clearSelectionAndRestoreSaved(parent, saved); - goog.testing.dom.assertRangeEquals( - def, 1, jkl, 1, restoredRange); - - var selection = goog.dom.Range.createFromWindow(window); - assertHTMLEquals('def', def.innerHTML); - assertHTMLEquals('jkl', jkl.innerHTML); - - // def and jkl now contain fragmented text nodes. - if (goog.userAgent.WEBKIT || goog.userAgent.IE) { - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[0], 2, selection); - } else if (goog.userAgent.OPERA) { - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[1], 0, selection); - } else { - goog.testing.dom.assertRangeEquals( - def, 1, jkl, 1, selection); - } - } - - - /* - TODO(user): Look into why removeCarets test doesn't pass. - function testRemoveCarets() { - var def = goog.dom.getElement('def'); - var jkl = goog.dom.getElement('jkl'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - assertHTMLEquals( - "d<span id='" + saved.startCaretId_ + "'></span>ef", def.innerHTML); - assertHTMLEquals( - "jk<span id='" + saved.endCaretId_ + "'></span>l", jkl.innerHTML); - - saved.removeCarets(); - assertHTMLEquals("def", def.innerHTML); - assertHTMLEquals("jkl", jkl.innerHTML); - - var selection = goog.dom.Range.createFromWindow(window); - - assertEquals('Wrong start node', def.firstChild, selection.getStartNode()); - assertEquals('Wrong end node', jkl.firstChild, selection.getEndNode()); - assertEquals('Wrong start offset', 1, selection.getStartOffset()); - assertEquals('Wrong end offset', 2, selection.getEndOffset()); - } -*/ - - function testRemoveContents() { - var def = goog.dom.getElement('def-4'); - var jkl = goog.dom.getElement('jkl-4'); - - // Sanity check. - var container = goog.dom.getElement('removeContentsTest'); - assertEquals(7, container.childNodes.length); - assertEquals('def', def.innerHTML); - assertEquals('jkl', jkl.innerHTML); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - var restored = saved.restore(); - restored.removeContents(); - - assertEquals(6, container.childNodes.length); - assertEquals('d', def.innerHTML); - assertEquals('l', jkl.innerHTML); - } - - function testHtmlEqual() { - var parent = goog.dom.getElement('caretRangeTest-2'); - var def = goog.dom.getElement('def-2'); - var jkl = goog.dom.getElement('jkl-2'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - var saved = range.saveUsingCarets(); - var html1 = parent.innerHTML; - saved.removeCarets(); - - var saved2 = range.saveUsingCarets(); - var html2 = parent.innerHTML; - saved2.removeCarets(); - - assertNotEquals('Same selection with different saved caret range carets ' + - 'must have different html.', html1, html2); - - assertTrue('Same selection with different saved caret range carets must ' + - 'be considered equal by htmlEqual', - goog.dom.SavedCaretRange.htmlEqual(html1, html2)); - - saved.dispose(); - saved2.dispose(); - } - - function testStartCaretIsAtEndOfParent() { - var parent = goog.dom.getElement('caretRangeTest-3'); - var def = goog.dom.getElement('def-3'); - var jkl = goog.dom.getElement('jkl-3'); - - var range = goog.dom.Range.createFromNodes( - def, 1, jkl, 1); - range.select(); - var saved = range.saveUsingCarets(); - clearSelectionAndRestoreSaved(parent, saved); - range = goog.dom.Range.createFromWindow(); - assertEquals('ghijkl', range.getText().replace(/\s/g, '')); - } - - /** - * Clear the selection by re-parsing the DOM. Then restore the saved - * selection. - * @param {Node} parent The node containing the current selection. - * @param {goog.dom.SavedRange} saved The saved range. - * @return {goog.dom.AbstractRange} Restored range. - */ - function clearSelectionAndRestoreSaved(parent, saved) { - goog.dom.Range.clearSelection(); - assertFalse(goog.dom.Range.hasSelection(window)); - var range = saved.restore(); - assertTrue(goog.dom.Range.hasSelection(window)); - return range; - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base deleted file mode 100644 index 4f356d3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A generic interface for saving and restoring ranges. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.SavedRange'); - -goog.require('goog.Disposable'); -goog.require('goog.debug.Logger'); - - - -/** - * Abstract interface for a saved range. - * @constructor - * @extends {goog.Disposable} - */ -goog.dom.SavedRange = function() { - goog.Disposable.call(this); -}; -goog.inherits(goog.dom.SavedRange, goog.Disposable); - - -/** - * Logging object. - * @type {goog.debug.Logger} - * @private - */ -goog.dom.SavedRange.logger_ = - goog.debug.Logger.getLogger('goog.dom.SavedRange'); - - -/** - * Restores the range and by default disposes of the saved copy. Take note: - * this means the by default SavedRange objects are single use objects. - * @param {boolean=} opt_stayAlive Whether this SavedRange should stay alive - * (not be disposed) after restoring the range. Defaults to false (dispose). - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.SavedRange.prototype.restore = function(opt_stayAlive) { - if (this.isDisposed()) { - goog.dom.SavedRange.logger_.severe( - 'Disposed SavedRange objects cannot be restored.'); - } - - var range = this.restoreInternal(); - if (!opt_stayAlive) { - this.dispose(); - } - return range; -}; - - -/** - * Internal method to restore the saved range. - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.SavedRange.prototype.restoreInternal = goog.abstractMethod; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base deleted file mode 100644 index 9e4b018..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base +++ /dev/null @@ -1,61 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.SavedRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1">Text</div> - -<script> - function testSaved() { - var node = goog.dom.getElement('test1'); - var range = goog.dom.Range.createFromNodeContents(node); - var savedRange = range.saveUsingDom(); - - range = savedRange.restore(true); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - assertFalse('Restored range should not be reversed.', range.isReversed()); - assertFalse('Range should not have disposed itself.', - savedRange.isDisposed()); - - goog.dom.Range.clearSelection(); - assertFalse(goog.dom.Range.hasSelection(window)); - - range = savedRange.restore(); - assertTrue('Range should have auto-disposed.', savedRange.isDisposed()); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - assertFalse('Restored range should not be reversed.', range.isReversed()); - } - - function testReversedSave() { - var node = goog.dom.getElement('test1').firstChild; - var range = goog.dom.Range.createFromNodes(node, 4, node, 0); - var savedRange = range.saveUsingDom(); - - range = savedRange.restore(); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - if (!goog.userAgent.IE) { - assertTrue('Restored range should be reversed.', range.isReversed()); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base deleted file mode 100644 index 6d6f69e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with selections in input boxes and text - * areas. - * - * @see ../demos/dom_selection.html - */ - - -goog.provide('goog.dom.selection'); - -goog.require('goog.string'); -goog.require('goog.userAgent'); - - -/** - * Sets the place where the selection should start inside a textarea or a text - * input - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position to set the start of the selection at. - */ -goog.dom.selection.setStart = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - textfield.selectionStart = pos; - } else if (goog.userAgent.IE) { - // destructuring assignment would have been sweet - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - - range.collapse(true); - range.move('character', pos); - range.select(); - } - } -}; - - -/** - * Return the place where the selection starts inside a textarea or a text - * input - * @param {Element} textfield A textarea or text input. - * @return {number} The position where the selection starts or 0 if it was - * unable to find the position or no selection exists. Note that we can't - * reliably tell the difference between an element that has no selection and - * one where it starts at 0. - */ -goog.dom.selection.getStart = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, true)[0]; -}; - - -/** - * Returns the start and end points of the selection within a textarea in IE. - * IE treats newline characters as \r\n characters, and we need to check for - * these characters at the edge of our selection, to ensure that we return the - * right cursor position. - * @param {TextRange} range Complete range object, e.g., "Hello\r\n". - * @param {TextRange} selRange Selected range object. - * @param {boolean} getOnlyStart Value indicating if only start - * cursor position is to be returned. In IE, obtaining the end position - * involves extra work, hence we have this parameter for calls which need - * only start position. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. If getOnlyStart was true, we return - * -1 as end offset. - * @private - */ -goog.dom.selection.getEndPointsTextareaIe_ = function( - range, selRange, getOnlyStart) { - // Create a duplicate of the selected range object to perform our actions - // against. Example of selectionRange = "" (assuming that the cursor is - // just after the \r\n combination) - var selectionRange = selRange.duplicate(); - - // Text before the selection start, e.g.,"Hello" (notice how range.text - // excludes the \r\n sequence) - var beforeSelectionText = range.text; - // Text before the selection start, e.g., "Hello" (this will later include - // the \r\n sequences also) - var untrimmedBeforeSelectionText = beforeSelectionText; - // Text within the selection , e.g. "" assuming that the cursor is just after - // the \r\n combination. - var selectionText = selectionRange.text; - // Text within the selection, e.g., "" (this will later include the \r\n - // sequences also) - var untrimmedSelectionText = selectionText; - - // Boolean indicating whether we are done dealing with the text before the - // selection's beginning. - var isRangeEndTrimmed = false; - // Go over the range until it becomes a 0-lengthed range or until the range - // text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isRangeEndTrimmed) { - if (range.compareEndPoints('StartToEnd', range) == 0) { - isRangeEndTrimmed = true; - } else { - range.moveEnd('character', -1); - if (range.text == beforeSelectionText) { - // If the start position of the cursor was after a \r\n string, - // we would skip over it in one go with the moveEnd call, but - // range.text will still show "Hello" (because of the IE range.text - // bug) - this implies that we should add a \r\n to our - // untrimmedBeforeSelectionText string. - untrimmedBeforeSelectionText += '\r\n'; - } else { - isRangeEndTrimmed = true; - } - } - } - - if (getOnlyStart) { - // We return -1 as end, since the caller is only interested in the start - // value. - return [untrimmedBeforeSelectionText.length, -1]; - } - // Boolean indicating whether we are done dealing with the text inside the - // selection. - var isSelectionRangeEndTrimmed = false; - // Go over the selected range until it becomes a 0-lengthed range or until - // the range text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isSelectionRangeEndTrimmed) { - if (selectionRange.compareEndPoints('StartToEnd', selectionRange) == 0) { - isSelectionRangeEndTrimmed = true; - } else { - selectionRange.moveEnd('character', -1); - if (selectionRange.text == selectionText) { - // If the selection was not empty, and the end point of the selection - // was just after a \r\n, we would have skipped it in one go with the - // moveEnd call, and this implies that we should add a \r\n to the - // untrimmedSelectionText string. - untrimmedSelectionText += '\r\n'; - } else { - isSelectionRangeEndTrimmed = true; - } - } - } - return [ - untrimmedBeforeSelectionText.length, - untrimmedBeforeSelectionText.length + untrimmedSelectionText.length]; -}; - - -/** - * Returns the start and end points of the selection inside a textarea or a - * text input. - * @param {Element} textfield A textarea or text input. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. - */ -goog.dom.selection.getEndPoints = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, false); -}; - - -/** - * Returns the start and end points of the selection inside a textarea or a - * text input. - * @param {Element} textfield A textarea or text input. - * @param {boolean} getOnlyStart Value indicating if only start - * cursor position is to be returned. In IE, obtaining the end position - * involves extra work, hence we have this parameter. In FF, there is not - * much extra effort involved. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. If getOnlyStart was true, we return - * -1 as end offset. - * @private - */ -goog.dom.selection.getEndPoints_ = function(textfield, getOnlyStart) { - var startPos = 0; - var endPos = 0; - if (goog.dom.selection.useSelectionProperties_(textfield)) { - startPos = textfield.selectionStart; - endPos = getOnlyStart ? -1 : textfield.selectionEnd; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - range.setEndPoint('EndToStart', selectionRange); - if (textfield.type == 'textarea') { - return goog.dom.selection.getEndPointsTextareaIe_( - range, selectionRange, getOnlyStart); - } - startPos = range.text.length; - if (!getOnlyStart) { - endPos = range.text.length + selectionRange.text.length; - } else { - endPos = -1; // caller did not ask for end position - } - } - } - return [startPos, endPos]; -}; - - -/** - * Sets the place where the selection should end inside a text area or a text - * input - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position to end the selection at. - */ -goog.dom.selection.setEnd = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - textfield.selectionEnd = pos; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - // Both the current position and the start cursor position need - // to be canonicalized to take care of possible \r\n miscounts. - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - var startCursorPos = goog.dom.selection.canonicalizePositionIe_( - textfield, goog.dom.selection.getStart(textfield)); - - selectionRange.collapse(true); - selectionRange.moveEnd('character', pos - startCursorPos); - selectionRange.select(); - } - } -}; - - -/** - * Returns the place where the selection ends inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @return {number} The position where the selection ends or 0 if it was - * unable to find the position or no selection exists. - */ -goog.dom.selection.getEnd = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, false)[1]; -}; - - -/** - * Sets the cursor position within a textfield. - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position within the text field. - */ -goog.dom.selection.setCursorPosition = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - // Mozilla directly supports this - textfield.selectionStart = pos; - textfield.selectionEnd = pos; - - } else if (goog.userAgent.IE) { - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - - // IE has textranges. A textfield's textrange encompasses the - // entire textfield's text by default - var sel = textfield.createTextRange(); - - sel.collapse(true); - sel.move('character', pos); - sel.select(); - } -}; - - -/** - * Sets the selected text inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @param {string} text The text to change the selection to. - */ -goog.dom.selection.setText = function(textfield, text) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - var value = textfield.value; - var oldSelectionStart = textfield.selectionStart; - var before = value.substr(0, oldSelectionStart); - var after = value.substr(textfield.selectionEnd); - textfield.value = before + text + after; - textfield.selectionStart = oldSelectionStart; - textfield.selectionEnd = oldSelectionStart + text.length; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (!range.inRange(selectionRange)) { - return; - } - // When we set the selection text the selection range is collapsed to the - // end. We therefore duplicate the current selection so we know where it - // started. Once we've set the selection text we move the start of the - // selection range to the old start - var range2 = selectionRange.duplicate(); - selectionRange.text = text; - selectionRange.setEndPoint('StartToStart', range2); - selectionRange.select(); - } else { - throw Error('Cannot set the selection end'); - } -}; - - -/** - * Returns the selected text inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @return {string} The selected text. - */ -goog.dom.selection.getText = function(textfield) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - var s = textfield.value; - return s.substring(textfield.selectionStart, textfield.selectionEnd); - } - - if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (!range.inRange(selectionRange)) { - return ''; - } else if (textfield.type == 'textarea') { - return goog.dom.selection.getSelectionRangeText_(selectionRange); - } - return selectionRange.text; - } - - throw Error('Cannot get the selection text'); -}; - - -/** - * Returns the selected text within a textarea in IE. - * IE treats newline characters as \r\n characters, and we need to check for - * these characters at the edge of our selection, to ensure that we return the - * right string. - * @param {TextRange} selRange Selected range object. - * @return {string} Selected text in the textarea. - * @private - */ -goog.dom.selection.getSelectionRangeText_ = function(selRange) { - // Create a duplicate of the selected range object to perform our actions - // against. Suppose the text in the textarea is "Hello\r\nWorld" and the - // selection encompasses the "o\r\n" bit, initial selectionRange will be "o" - // (assuming that the cursor is just after the \r\n combination) - var selectionRange = selRange.duplicate(); - - // Text within the selection , e.g. "o" assuming that the cursor is just after - // the \r\n combination. - var selectionText = selectionRange.text; - // Text within the selection, e.g., "o" (this will later include the \r\n - // sequences also) - var untrimmedSelectionText = selectionText; - - // Boolean indicating whether we are done dealing with the text inside the - // selection. - var isSelectionRangeEndTrimmed = false; - // Go over the selected range until it becomes a 0-lengthed range or until - // the range text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isSelectionRangeEndTrimmed) { - if (selectionRange.compareEndPoints('StartToEnd', selectionRange) == 0) { - isSelectionRangeEndTrimmed = true; - } else { - selectionRange.moveEnd('character', -1); - if (selectionRange.text == selectionText) { - // If the selection was not empty, and the end point of the selection - // was just after a \r\n, we would have skipped it in one go with the - // moveEnd call, and this implies that we should add a \r\n to the - // untrimmedSelectionText string. - untrimmedSelectionText += '\r\n'; - } else { - isSelectionRangeEndTrimmed = true; - } - } - } - return untrimmedSelectionText; -}; - - -/** - * Helper function for returning the range for an object as well as the - * selection range - * @private - * @param {Element} el The element to get the range for. - * @return {Array.<TextRange>} Range of object and selection range in two - * element array. - */ -goog.dom.selection.getRangeIe_ = function(el) { - var doc = el.ownerDocument || el.document; - - var selectionRange = doc.selection.createRange(); - // el.createTextRange() doesn't work on textareas - var range; - - if (el.type == 'textarea') { - range = doc.body.createTextRange(); - range.moveToElementText(el); - } else { - range = el.createTextRange(); - } - - return [range, selectionRange]; -}; - - -/** - * Helper function for canonicalizing a position inside a textfield in IE. - * Deals with the issue that \r\n counts as 2 characters, but - * move('character', n) passes over both characters in one move. - * @private - * @param {Element} textfield The text element. - * @param {number} pos The position desired in that element. - * @return {number} The canonicalized position that will work properly with - * move('character', pos). - */ -goog.dom.selection.canonicalizePositionIe_ = function(textfield, pos) { - if (textfield.type == 'textarea') { - // We do this only for textarea because it is the only one which can - // have a \r\n (input cannot have this). - var value = textfield.value.substring(0, pos); - pos = goog.string.canonicalizeNewlines(value).length; - } - return pos; -}; - - -/** - * Helper function to determine whether it's okay to use - * selectionStart/selectionEnd. - * - * @param {Element} el The element to check for. - * @return {boolean} Whether it's okay to use the selectionStart and - * selectionEnd properties on {@code el}. - * @private - */ -goog.dom.selection.useSelectionProperties_ = function(el) { - try { - return typeof el.selectionStart == 'number'; - } catch (e) { - // Firefox throws an exception if you try to access selectionStart - // on an element with display: none. - return false; - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base deleted file mode 100644 index 8cfc624..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base +++ /dev/null @@ -1,329 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.selection</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.selection'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - -<script> - - var input; - var hiddenInput; - var textarea; - var hiddenTextarea; - - function setUp() { - input = goog.dom.createDom('input', {type: 'text'}); - textarea = goog.dom.createDom('textarea'); - hiddenInput = goog.dom.createDom( - 'input', {type: 'text', style: 'display: none'}); - hiddenTextarea = goog.dom.createDom( - 'textarea', {style: 'display: none'}); - - document.body.appendChild(input); - document.body.appendChild(textarea); - document.body.appendChild(hiddenInput); - document.body.appendChild(hiddenTextarea); - } - - function tearDown() { - goog.dom.removeNode(input); - goog.dom.removeNode(textarea); - goog.dom.removeNode(hiddenInput); - goog.dom.removeNode(hiddenTextarea); - } - - /** - * Tests getStart routine in both input and textarea. - */ - function testGetStartInput() { - getStartHelper(input, hiddenInput); - } - - function testGetStartTextarea() { - getStartHelper(textarea, hiddenTextarea); - } - - function getStartHelper(field, hiddenField) { - assertEquals(0, goog.dom.selection.getStart(field)); - assertEquals(0, goog.dom.selection.getStart(hiddenField)); - - field.focus(); - assertEquals(0, goog.dom.selection.getStart(field)); - } - - /** - * Tests the setText routine for both input and textarea - * with a single line of text. - */ - function testSetTextInput() { - setTextHelper(input); - } - - function testSetTextTextarea() { - setTextHelper(textarea); - } - - function setTextHelper(field) { - // Test one line string only - select(field); - assertEquals('', goog.dom.selection.getText(field)); - - goog.dom.selection.setText(field, 'Get Behind Me Satan'); - assertEquals('Get Behind Me Satan', goog.dom.selection.getText(field)); - } - - /** - * Tests the setText routine for textarea with multiple lines of text. - */ - function testSetTextMultipleLines() { - select(textarea); - assertEquals('', goog.dom.selection.getText(textarea)); - var message = goog.userAgent.IE ? - 'Get Behind Me\r\nSatan' : - 'Get Behind Me\nSatan'; - goog.dom.selection.setText(textarea, message); - assertEquals(message, goog.dom.selection.getText(textarea)); - - // Select the text upto the point just after the \r\n combination - // or \n in GECKO. - var endOfNewline = goog.userAgent.IE ? 15 : 14; - var selectedMessage = message.substring(0, endOfNewline); - goog.dom.selection.setStart(textarea, 0); - goog.dom.selection.setEnd(textarea, endOfNewline); - assertEquals(selectedMessage, goog.dom.selection.getText(textarea)); - - selectedMessage = goog.userAgent.IE ? '\r\n' : '\n'; - goog.dom.selection.setStart(textarea, 13); - goog.dom.selection.setEnd(textarea, endOfNewline); - assertEquals(selectedMessage, goog.dom.selection.getText(textarea)); - } - - /** - * Tests the setCursor routine for both input and textarea. - */ - function testSetCursorInput() { - setCursorHelper(input); - } - - function testSetCursorTextarea() { - setCursorHelper(textarea); - } - - function setCursorHelper(field) { - select(field); - // try to set the cursor beyond the length of the content - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, 15); - assertEquals(0, goog.dom.selection.getStart(field)); - assertEquals(0, goog.dom.selection.getEnd(field)); - - select(field); - var message = 'Get Behind Me Satan'; - goog.dom.selection.setText(field, message); - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, message.length); - assertEquals(5, goog.dom.selection.getStart(field)); - assertEquals(message.length, goog.dom.selection.getEnd(field)); - - // Set the end before the start, and see if getEnd returns the start - // position itself. - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, 3); - assertEquals(3, goog.dom.selection.getEnd(field)); - } - - /** - * Tests the getText and setText routines acting on selected text in - * both input and textarea. - */ - function testGetAndSetSelectedTextInput() { - getAndSetSelectedTextHelper(input); - } - - function testGetAndSetSelectedTextTextarea() { - getAndSetSelectedTextHelper(textarea); - } - - function getAndSetSelectedTextHelper(field) { - select(field); - goog.dom.selection.setText(field, 'Get Behind Me Satan'); - - // select 'Behind' - goog.dom.selection.setStart(field, 4); - goog.dom.selection.setEnd(field, 10); - assertEquals('Behind', goog.dom.selection.getText(field)); - - goog.dom.selection.setText(field, 'In Front Of'); - goog.dom.selection.setStart(field, 0); - goog.dom.selection.setEnd(field, 100); - assertEquals('Get In Front Of Me Satan', goog.dom.selection.getText(field)); - } - - /** - * Test setStart on hidden input and hidden textarea. - */ - function testSetCursorOnHiddenInput() { - setCursorOnHiddenInputHelper(hiddenInput); - } - - function testSetCursorOnHiddenTextarea() { - setCursorOnHiddenInputHelper(hiddenTextarea); - } - - function setCursorOnHiddenInputHelper(hiddenField) { - goog.dom.selection.setStart(hiddenField, 0); - assertEquals(0, goog.dom.selection.getStart(hiddenField)); - } - - /** - * Test setStart, setEnd, getStart and getEnd in textarea with text - * containing line breaks. - */ - function testSetAndGetCursorWithLineBreaks() { - select(textarea); - var newline = goog.userAgent.IE ? '\r\n' : '\n'; - var message = 'Hello' + newline + 'World'; - goog.dom.selection.setText(textarea, message); - - // Test setEnd and getEnd, by setting the cursor somewhere after the - // \r\n combination. - goog.dom.selection.setEnd(textarea, 9); - assertEquals(9, goog.dom.selection.getEnd(textarea)); - - // Test basic setStart and getStart - goog.dom.selection.setStart(textarea, 10); - assertEquals(10, goog.dom.selection.getStart(textarea)); - - // Test setEnd and getEnd, by setting the cursor exactly after the - // \r\n combination in IE or after \n in GECKO. - var endOfNewline = goog.userAgent.IE ? 7 : 6; - checkSetAndGetTextarea(endOfNewline, endOfNewline); - - // Select a \r\n combination in IE or \n in GECKO and see if - // getStart and getEnd work correctly. - clearField(textarea); - message = 'Hello' + newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var startOfNewline = goog.userAgent.IE ? 7 : 6; - endOfNewline = goog.userAgent.IE ? 9 : 7; - checkSetAndGetTextarea(startOfNewline, endOfNewline); - - // Select 2 \r\n combinations in IE or 2 \ns in GECKO and see if getStart - // and getEnd work correctly. - checkSetAndGetTextarea(5, endOfNewline); - - // Position cursor b/w 2 \r\n combinations in IE or 2 \ns in GECKO and see - // if getStart and getEnd work correctly. - clearField(textarea); - message = 'Hello' + newline + newline + newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var middleOfNewlines = goog.userAgent.IE ? 9 : 7; - checkSetAndGetTextarea(middleOfNewlines, middleOfNewlines); - - // Position cursor at end of a textarea which ends with \r\n in IE or \n in - // GECKO. - clearField(textarea); - message = 'Hello' + newline + newline; - goog.dom.selection.setText(textarea, message); - var endOfTextarea = message.length; - checkSetAndGetTextarea(endOfTextarea, endOfTextarea); - - // Position cursor at the end of the 2 starting \r\ns in IE or \ns in GECKO - // within a textarea. - clearField(textarea); - message = newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var endOfTwoNewlines = goog.userAgent.IE ? 4 : 2; - checkSetAndGetTextarea(endOfTwoNewlines, endOfTwoNewlines); - - // Position cursor at the end of the first \r\n in IE or \n in - // GECKO within a textarea. - endOfOneNewline = goog.userAgent.IE ? 2 : 1; - checkSetAndGetTextarea(endOfOneNewline, endOfOneNewline); - } - - /** - * Test to make sure there's no error when getting the range of an unselected - * textarea. See bug 1274027. - */ - function testGetStartOnUnfocusedTextarea() { - input.value = 'White Blood Cells'; - input.focus(); - goog.dom.selection.setCursorPosition(input, 5); - - assertEquals('getStart on input should return where we put the cursor', - 5, goog.dom.selection.getStart(input)); - - assertEquals('getStart on unfocused textarea should succeed without error', - 0, goog.dom.selection.getStart(textarea)); - } - - /** - * Test to make sure there's no error setting cursor position within a - * textarea after a newline. This is problematic on IE because of the - * '\r\n' vs '\n' issue. - */ - function testSetCursorPositionTextareaWithNewlines() { - textarea.value = 'Hello\nWorld'; - textarea.focus(); - - // Set the selection point between 'W' and 'o'. Position is computed this - // way instead of being hard-coded because it's different in IE due to \r\n - // vs \n. - goog.dom.selection.setCursorPosition(textarea, textarea.value.length - 4); - - var linebreak = goog.userAgent.IE ? '\r\n' : '\n'; - var expectedLeftString = 'Hello' + linebreak + 'W'; - - assertEquals('getStart on input should return after the newline', - expectedLeftString.length, goog.dom.selection.getStart(textarea)); - assertEquals('getEnd on input should return after the newline', - expectedLeftString.length, goog.dom.selection.getEnd(textarea)); - - goog.dom.selection.setEnd(textarea, textarea.value.length); - assertEquals('orld', goog.dom.selection.getText(textarea)); - } - - /** - * Helper function to clear the textfield contents. - */ - function clearField(field) { - field.value = ''; - } - - /** - * Helper function to set the start and end and assert the getter values. - */ - function checkSetAndGetTextarea(start, end) { - goog.dom.selection.setStart(textarea, start); - goog.dom.selection.setEnd(textarea, end); - assertEquals(start, goog.dom.selection.getStart(textarea)); - assertEquals(end, goog.dom.selection.getEnd(textarea)); - } - - /** - * Helper function to focus and select a field. In IE8, selected - * fields need focus. - */ - function select(field) { - field.focus(); - field.select(); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base deleted file mode 100644 index b4c22e6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base +++ /dev/null @@ -1,365 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator subclass for DOM tree traversal. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.TagIterator'); -goog.provide('goog.dom.TagWalkType'); - -goog.require('goog.dom.NodeType'); -goog.require('goog.iter.Iterator'); -goog.require('goog.iter.StopIteration'); - - -/** - * There are three types of token: - * <ol> - * <li>{@code START_TAG} - The beginning of a tag. - * <li>{@code OTHER} - Any non-element node position. - * <li>{@code END_TAG} - The end of a tag. - * </ol> - * Users of this enumeration can rely on {@code START_TAG + END_TAG = 0} and - * that {@code OTHER = 0}. - * - * @enum {number} - */ -goog.dom.TagWalkType = { - START_TAG: 1, - OTHER: 0, - END_TAG: -1 -}; - - - -/** - * A DOM tree traversal iterator. - * - * Starting with the given node, the iterator walks the DOM in order, reporting - * events for the start and end of Elements, and the presence of text nodes. For - * example: - * - * <pre> - * <div>1<span>2</span>3</div> - * </pre> - * - * Will return the following nodes: - * - * <code>[div, 1, span, 2, span, 3, div]</code> - * - * With the following states: - * - * <code>[START, OTHER, START, OTHER, END, OTHER, END]</code> - * - * And the following depths - * - * <code>[1, 1, 2, 2, 1, 1, 0]</code> - * - * Imagining <code>|</code> represents iterator position, the traversal stops at - * each of the following locations: - * - * <pre> - * <div>|1|<span>|2|</span>|3|</div>| - * </pre> - * - * The iterator can also be used in reverse mode, which will return the nodes - * and states in the opposite order. The depths will be slightly different - * since, like in normal mode, the depth is computed *after* the given node. - * - * Lastly, it is possible to create an iterator that is unconstrained, meaning - * that it will continue iterating until the end of the document instead of - * until exiting the start node. - * - * @param {Node=} opt_node The start node. If unspecified or null, defaults to - * an empty iterator. - * @param {boolean=} opt_reversed Whether to traverse the tree in reverse. - * @param {boolean=} opt_unconstrained Whether the iterator is not constrained - * to the starting node and its children. - * @param {goog.dom.TagWalkType?=} opt_tagType The type of the position. - * Defaults to the start of the given node for forward iterators, and - * the end of the node for reverse iterators. - * @param {number=} opt_depth The starting tree depth. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.TagIterator = function(opt_node, opt_reversed, - opt_unconstrained, opt_tagType, opt_depth) { - this.reversed = !!opt_reversed; - if (opt_node) { - this.setPosition(opt_node, opt_tagType); - } - this.depth = opt_depth != undefined ? opt_depth : this.tagType || 0; - if (this.reversed) { - this.depth *= -1; - } - this.constrained = !opt_unconstrained; -}; -goog.inherits(goog.dom.TagIterator, goog.iter.Iterator); - - -/** - * The node this position is located on. - * @type {Node} - */ -goog.dom.TagIterator.prototype.node = null; - - -/** - * The type of this position. - * @type {goog.dom.TagWalkType} - */ -goog.dom.TagIterator.prototype.tagType = goog.dom.TagWalkType.OTHER; - - -/** - * The tree depth of this position relative to where the iterator started. The - * depth is considered to be the tree depth just past the current node, so if an - * iterator is at position <pre> - * <div>|</div> - * </pre> - * (i.e. the node is the div and the type is START_TAG) its depth will be 1. - * @type {number} - */ -goog.dom.TagIterator.prototype.depth; - - -/** - * Whether the node iterator is moving in reverse. - * @type {boolean} - */ -goog.dom.TagIterator.prototype.reversed; - - -/** - * Whether the iterator is constrained to the starting node and its children. - * @type {boolean} - */ -goog.dom.TagIterator.prototype.constrained; - - -/** - * Whether iteration has started. - * @type {boolean} - * @private - */ -goog.dom.TagIterator.prototype.started_ = false; - - -/** - * Set the position of the iterator. Overwrite the tree node and the position - * type which can be one of the {@link goog.dom.TagWalkType} token types. - * Only overwrites the tree depth when the parameter is specified. - * @param {Node} node The node to set the position to. - * @param {goog.dom.TagWalkType?=} opt_tagType The type of the position - * Defaults to the start of the given node. - * @param {number=} opt_depth The tree depth. - */ -goog.dom.TagIterator.prototype.setPosition = function(node, - opt_tagType, opt_depth) { - this.node = node; - - if (node) { - if (goog.isNumber(opt_tagType)) { - this.tagType = opt_tagType; - } else { - // Auto-determine the proper type - this.tagType = this.node.nodeType != goog.dom.NodeType.ELEMENT ? - goog.dom.TagWalkType.OTHER : - this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - } - } - - if (goog.isNumber(opt_depth)) { - this.depth = opt_depth; - } -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.TagIterator} other The iterator to copy. - * @protected - */ -goog.dom.TagIterator.prototype.copyFrom = function(other) { - this.node = other.node; - this.tagType = other.tagType; - this.depth = other.depth; - this.reversed = other.reversed; - this.constrained = other.constrained; -}; - - -/** - * @return {goog.dom.TagIterator} A copy of this iterator. - */ -goog.dom.TagIterator.prototype.clone = function() { - return new goog.dom.TagIterator(this.node, this.reversed, - !this.constrained, this.tagType, this.depth); -}; - - -/** - * Skip the current tag. - */ -goog.dom.TagIterator.prototype.skipTag = function() { - var check = this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - if (this.tagType == check) { - this.tagType = /** @type {goog.dom.TagWalkType} */ (check * -1); - this.depth += this.tagType * (this.reversed ? -1 : 1); - } -}; - - -/** - * Restart the current tag. - */ -goog.dom.TagIterator.prototype.restartTag = function() { - var check = this.reversed ? goog.dom.TagWalkType.START_TAG : - goog.dom.TagWalkType.END_TAG; - if (this.tagType == check) { - this.tagType = /** @type {goog.dom.TagWalkType} */ (check * -1); - this.depth += this.tagType * (this.reversed ? -1 : 1); - } -}; - - -/** - * Move to the next position in the DOM tree. - * @return {Node} Returns the next node, or throws a goog.iter.StopIteration - * exception if the end of the iterator's range has been reached. - */ -goog.dom.TagIterator.prototype.next = function() { - var node; - - if (this.started_) { - if (!this.node || this.constrained && this.depth == 0) { - throw goog.iter.StopIteration; - } - node = this.node; - - var startType = this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - - if (this.tagType == startType) { - // If we have entered the tag, test if there are any children to move to. - var child = this.reversed ? node.lastChild : node.firstChild; - if (child) { - this.setPosition(child); - } else { - // If not, move on to exiting this tag. - this.setPosition(node, - /** @type {goog.dom.TagWalkType} */ (startType * -1)); - } - } else { - var sibling = this.reversed ? node.previousSibling : node.nextSibling; - if (sibling) { - // Try to move to the next node. - this.setPosition(sibling); - } else { - // If no such node exists, exit our parent. - this.setPosition(node.parentNode, - /** @type {goog.dom.TagWalkType} */ (startType * -1)); - } - } - - this.depth += this.tagType * (this.reversed ? -1 : 1); - } else { - this.started_ = true; - } - - // Check the new position for being last, and return it if it's not. - node = this.node; - if (!this.node) { - throw goog.iter.StopIteration; - } - return node; -}; - - -/** - * @return {boolean} Whether next has ever been called on this iterator. - * @protected - */ -goog.dom.TagIterator.prototype.isStarted = function() { - return this.started_; -}; - - -/** - * @return {boolean} Whether this iterator's position is a start tag position. - */ -goog.dom.TagIterator.prototype.isStartTag = function() { - return this.tagType == goog.dom.TagWalkType.START_TAG; -}; - - -/** - * @return {boolean} Whether this iterator's position is an end tag position. - */ -goog.dom.TagIterator.prototype.isEndTag = function() { - return this.tagType == goog.dom.TagWalkType.END_TAG; -}; - - -/** - * @return {boolean} Whether this iterator's position is not at an element node. - */ -goog.dom.TagIterator.prototype.isNonElement = function() { - return this.tagType == goog.dom.TagWalkType.OTHER; -}; - - -/** - * Test if two iterators are at the same position - i.e. if the node and tagType - * is the same. This will still return true if the two iterators are moving in - * opposite directions or have different constraints. - * @param {goog.dom.TagIterator} other The iterator to compare to. - * @return {boolean} Whether the two iterators are at the same position. - */ -goog.dom.TagIterator.prototype.equals = function(other) { - // Nodes must be equal, and we must either have reached the end of our tree - // or be at the same position. - return other.node == this.node && (!this.node || - other.tagType == this.tagType); -}; - - -/** - * Replace the current node with the list of nodes. Reset the iterator so that - * it visits the first of the nodes next. - * @param {...Object} var_args A list of nodes to replace the current node with. - * If the first argument is array-like, it will be used, otherwise all the - * arguments are assumed to be nodes. - */ -goog.dom.TagIterator.prototype.splice = function(var_args) { - // Reset the iterator so that it iterates over the first replacement node in - // the arguments on the next iteration. - var node = this.node; - this.restartTag(); - this.reversed = !this.reversed; - goog.dom.TagIterator.prototype.next.call(this); - this.reversed = !this.reversed; - - // Replace the node with the arguments. - var arr = goog.isArrayLike(arguments[0]) ? arguments[0] : arguments; - for (var i = arr.length - 1; i >= 0; i--) { - goog.dom.insertSiblingAfter(arr[i], node); - } - goog.dom.removeNode(node); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base deleted file mode 100644 index 6d61d03..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base +++ /dev/null @@ -1,589 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.TagIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.dom.TagIterator'); -</script> -</head> -<body> - -<div id="test"><a href="#">T<b>e</b>xt</a><span></span><p>Text</p></div> -<ul id="test2"><li>Not<li>Closed</ul> -<div id="test3">text</div> -<div id="testSplice"></div> - -<script> - var it; - var pos; - - function assertStartTag(type) { - assertEquals('Position ' + pos + ' should be start tag', - goog.dom.TagWalkType.START_TAG, it.tagType); - assertTrue('isStartTag should return true', it.isStartTag()); - assertFalse('isEndTag should return false', it.isEndTag()); - assertFalse('isNonElement should return false', it.isNonElement()); - assertEquals('Position ' + pos + ' should be ' + type, type, - it.node.tagName); - } - - function assertEndTag(type) { - assertEquals('Position ' + pos + ' should be end tag', - goog.dom.TagWalkType.END_TAG, it.tagType); - assertFalse('isStartTag should return false', it.isStartTag()); - assertTrue('isEndTag should return true', it.isEndTag()); - assertFalse('isNonElement should return false', it.isNonElement()); - assertEquals('Position ' + pos + ' should be ' + type, type, - it.node.tagName); - } - - function assertTextNode(value) { - assertEquals('Position ' + pos + ' should be text node', - goog.dom.TagWalkType.OTHER, it.tagType); - assertFalse('isStartTag should return false', it.isStartTag()); - assertFalse('isEndTag should return false', it.isEndTag()); - assertTrue('isNonElement should return true', it.isNonElement()); - assertEquals('Position ' + pos + ' should be "' + value + '"', value, - it.node.nodeValue); - } - - function testBasicHTML() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - break; - case 3: - assertTextNode('T'); - break; - case 4: - assertStartTag('B'); - assertEquals('Depth at <B> should be 3', 3, it.depth); - break; - case 5: - assertTextNode('e'); - break; - case 6: - assertEndTag('B'); - break; - case 7: - assertTextNode('xt'); - break; - case 8: - assertEndTag('A'); - break; - case 9: - assertStartTag('SPAN'); - break; - case 10: - assertEndTag('SPAN'); - break; - case 11: - assertStartTag('P'); - break; - case 12: - assertTextNode('Text'); - break; - case 13: - assertEndTag('P'); - break; - case 14: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testSkipTag() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testRestartTag() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - var done = false; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - - // Do them all again, starting after this element. - if (!done) { - pos = 1; - it.restartTag(); - done = true; - } - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - - function testSkipTagReverse() { - it = new goog.dom.TagIterator(goog.dom.getElement('test'), true); - pos = 9; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - case 2: - assertEndTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - - function testUnclosedLI() { - it = new goog.dom.TagIterator(goog.dom.getElement('test2')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('UL'); - break; - case 2: - assertStartTag('LI'); - assertEquals('Depth at <LI> should be 2', 2, it.depth); - break; - case 3: - assertTextNode('Not'); - break; - case 4: - assertEndTag('LI'); - break; - case 5: - assertStartTag('LI'); - assertEquals('Depth at second <LI> should be 2', 2, it.depth); - break; - case 6: - assertTextNode('Closed'); - break; - case 7: - assertEndTag('LI'); - break; - case 8: - assertEndTag('UL'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testReversedUnclosedLI() { - it = new goog.dom.TagIterator(goog.dom.getElement('test2'), true); - pos = 9; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('UL'); - assertEquals('Depth at start should be 0', 0, it.depth); - break; - case 2: - assertStartTag('LI'); - break; - case 3: - assertTextNode('Not'); - break; - case 4: - assertEndTag('LI'); - assertEquals('Depth at <LI> should be 2', 2, it.depth); - break; - case 5: - assertStartTag('LI'); - break; - case 6: - assertTextNode('Closed'); - break; - case 7: - assertEndTag('LI'); - assertEquals('Depth at second <LI> should be 2', 2, it.depth); - break; - case 8: - assertEndTag('UL'); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testConstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), false, false); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertEquals('Constrained iterator should stop at position 3.', 3, pos); - } - - function testUnconstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), false, true); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertNotEquals('Unonstrained iterator should not stop at position 3.', 3, - pos); - } - - function testConstrainedText() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3').firstChild, - false, false); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertTextNode('text'); - break; - } - }); - - assertEquals('Constrained text iterator should stop at position 1.', 1, - pos); - } - - function testReverseConstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), true, false); - pos = 4; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertEquals('Constrained reversed iterator should stop at position 1.', 1, - pos); - } - - function testSpliceRemoveSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<br/>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(); - }); - - assertEquals('Node not removed', 0, testDiv.childNodes.length); - } - - function testSpliceRemoveFirstTextNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'hello<b>world</b><em>goodbye</em>'; - it = new goog.dom.TagIterator(testDiv.firstChild, false, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeType == 3 && node.data == 'hello') { - i.splice(); - } - if (node.nodeName == 'EM') { - i.splice(goog.dom.createDom('I', null, node.childNodes)); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>world</b><i>goodbye</i>', - testDiv.innerHTML); - } - - function testSpliceReplaceFirstTextNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'hello<b>world</b>'; - it = new goog.dom.TagIterator(testDiv.firstChild, false, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeType == 3 && node.data == 'hello') { - i.splice(goog.dom.createDom('EM', null, 'HELLO')); - } else if (node.nodeName == 'EM') { - i.splice(goog.dom.createDom('I', null, node.childNodes)); - } - }); - - goog.testing.dom.assertHtmlMatches('<i>HELLO</i><b>world</b>', - testDiv.innerHTML); - } - - function testSpliceReplaceSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<br/>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(goog.dom.createDom('link'), goog.dom.createDom('img')); - }); - - goog.testing.dom.assertHtmlMatches('<link><img>', testDiv.innerHTML); - } - - function testSpliceFlattenSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<div><b>one</b>two<i>three</i></div>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(node.childNodes); - }); - - goog.testing.dom.assertHtmlMatches('<b>one</b>two<i>three</i>', - testDiv.innerHTML); - } - - function testSpliceMiddleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeName == 'B') { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMiddleNodeReversed() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeName == 'B') { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMiddleNodeAtEndTag() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.tagName == 'B' && i.isEndTag()) { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMultipleNodes() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG') { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM') { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - - function testSpliceMultipleNodesAtEnd() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG' && i.isEndTag()) { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM' && i.isEndTag()) { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - - function testSpliceMultipleNodesReversed() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv, true); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG') { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM') { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base deleted file mode 100644 index 23bdd42..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Defines the goog.dom.TagName enum. This enumerates - * all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html. - */ -goog.provide('goog.dom.TagName'); - - -/** - * Enum of all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html - * @enum {string} - */ -goog.dom.TagName = { - A: 'A', - ABBR: 'ABBR', - ACRONYM: 'ACRONYM', - ADDRESS: 'ADDRESS', - APPLET: 'APPLET', - AREA: 'AREA', - B: 'B', - BASE: 'BASE', - BASEFONT: 'BASEFONT', - BDO: 'BDO', - BIG: 'BIG', - BLOCKQUOTE: 'BLOCKQUOTE', - BODY: 'BODY', - BR: 'BR', - BUTTON: 'BUTTON', - CANVAS: 'CANVAS', - CAPTION: 'CAPTION', - CENTER: 'CENTER', - CITE: 'CITE', - CODE: 'CODE', - COL: 'COL', - COLGROUP: 'COLGROUP', - DD: 'DD', - DEL: 'DEL', - DFN: 'DFN', - DIR: 'DIR', - DIV: 'DIV', - DL: 'DL', - DT: 'DT', - EM: 'EM', - FIELDSET: 'FIELDSET', - FONT: 'FONT', - FORM: 'FORM', - FRAME: 'FRAME', - FRAMESET: 'FRAMESET', - H1: 'H1', - H2: 'H2', - H3: 'H3', - H4: 'H4', - H5: 'H5', - H6: 'H6', - HEAD: 'HEAD', - HR: 'HR', - HTML: 'HTML', - I: 'I', - IFRAME: 'IFRAME', - IMG: 'IMG', - INPUT: 'INPUT', - INS: 'INS', - ISINDEX: 'ISINDEX', - KBD: 'KBD', - LABEL: 'LABEL', - LEGEND: 'LEGEND', - LI: 'LI', - LINK: 'LINK', - MAP: 'MAP', - MENU: 'MENU', - META: 'META', - NOFRAMES: 'NOFRAMES', - NOSCRIPT: 'NOSCRIPT', - OBJECT: 'OBJECT', - OL: 'OL', - OPTGROUP: 'OPTGROUP', - OPTION: 'OPTION', - P: 'P', - PARAM: 'PARAM', - PRE: 'PRE', - Q: 'Q', - S: 'S', - SAMP: 'SAMP', - SCRIPT: 'SCRIPT', - SELECT: 'SELECT', - SMALL: 'SMALL', - SPAN: 'SPAN', - STRIKE: 'STRIKE', - STRONG: 'STRONG', - STYLE: 'STYLE', - SUB: 'SUB', - SUP: 'SUP', - TABLE: 'TABLE', - TBODY: 'TBODY', - TD: 'TD', - TEXTAREA: 'TEXTAREA', - TFOOT: 'TFOOT', - TH: 'TH', - THEAD: 'THEAD', - TITLE: 'TITLE', - TR: 'TR', - TT: 'TT', - U: 'U', - UL: 'UL', - VAR: 'VAR' -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base deleted file mode 100644 index 464a193..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.TagName</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.TagName'); - goog.require('goog.object'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<script> - - function testCorrectNumberOfTagNames() { - assertEquals(92, goog.object.getCount(goog.dom.TagName)); - } - - function testPropertyNamesEqualValues() { - for (var propertyName in goog.dom.TagName) { - assertEquals(propertyName, goog.dom.TagName[propertyName]); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base deleted file mode 100644 index 5f96bd3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base +++ /dev/null @@ -1,611 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with text ranges in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.TextRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.TextRangeIterator'); -goog.require('goog.dom.browserrange'); -goog.require('goog.string'); -goog.require('goog.userAgent'); - - - -/** - * Create a new text selection with no properties. Do not use this constructor: - * use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractRange} - */ -goog.dom.TextRange = function() { -}; -goog.inherits(goog.dom.TextRange, goog.dom.AbstractRange); - - -/** - * Create a new range wrapper from the given browser range object. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Range|TextRange} range The browser range object. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromBrowserRange = function(range, opt_isReversed) { - return goog.dom.TextRange.createFromBrowserRangeWrapper_( - goog.dom.browserrange.createRange(range), opt_isReversed); -}; - - -/** - * Create a new range wrapper from the given browser range wrapper. - * @param {goog.dom.browserrange.AbstractRange} browserRange The browser range - * wrapper. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - * @private - */ -goog.dom.TextRange.createFromBrowserRangeWrapper_ = function(browserRange, - opt_isReversed) { - var range = new goog.dom.TextRange(); - - // Initialize the range as a browser range wrapper type range. - range.browserRangeWrapper_ = browserRange; - range.isReversed_ = !!opt_isReversed; - - return range; -}; - - -/** - * Create a new range wrapper that selects the given node's text. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Node} node The node to select. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromNodeContents = function(node, opt_isReversed) { - return goog.dom.TextRange.createFromBrowserRangeWrapper_( - goog.dom.browserrange.createRangeFromNodeContents(node), - opt_isReversed); -}; - - -/** - * Create a new range wrapper that selects the area between the given nodes, - * accounting for the given offsets. Do not use this method directly - please - * use goog.dom.Range.createFrom* instead. - * @param {Node} anchorNode The node to start with. - * @param {number} anchorOffset The offset within the node to start. - * @param {Node} focusNode The node to end with. - * @param {number} focusOffset The offset within the node to end. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromNodes = function(anchorNode, anchorOffset, - focusNode, focusOffset) { - var range = new goog.dom.TextRange(); - range.isReversed_ = goog.dom.Range.isReversed(anchorNode, anchorOffset, - focusNode, focusOffset); - - // Avoid selecting BRs directly - if (anchorNode.tagName == 'BR') { - var parent = anchorNode.parentNode; - anchorOffset = goog.array.indexOf(parent.childNodes, anchorNode); - anchorNode = parent; - } - - if (focusNode.tagName == 'BR') { - var parent = focusNode.parentNode; - focusOffset = goog.array.indexOf(parent.childNodes, focusNode); - focusNode = parent; - } - - // Initialize the range as a W3C style range. - if (range.isReversed_) { - range.startNode_ = focusNode; - range.startOffset_ = focusOffset; - range.endNode_ = anchorNode; - range.endOffset_ = anchorOffset; - } else { - range.startNode_ = anchorNode; - range.startOffset_ = anchorOffset; - range.endNode_ = focusNode; - range.endOffset_ = focusOffset; - } - - return range; -}; - - -// Representation 1: a browser range wrapper. - - -/** - * The browser specific range wrapper. This can be null if one of the other - * representations of the range is specified. - * @type {goog.dom.browserrange.AbstractRange?} - * @private - */ -goog.dom.TextRange.prototype.browserRangeWrapper_ = null; - - -// Representation 2: two endpoints specified as nodes + offsets - - -/** - * The start node of the range. This can be null if one of the other - * representations of the range is specified. - * @type {Node} - * @private - */ -goog.dom.TextRange.prototype.startNode_ = null; - - -/** - * The start offset of the range. This can be null if one of the other - * representations of the range is specified. - * @type {?number} - * @private - */ -goog.dom.TextRange.prototype.startOffset_ = null; - - -/** - * The end node of the range. This can be null if one of the other - * representations of the range is specified. - * @type {Node} - * @private - */ -goog.dom.TextRange.prototype.endNode_ = null; - - -/** - * The end offset of the range. This can be null if one of the other - * representations of the range is specified. - * @type {?number} - * @private - */ -goog.dom.TextRange.prototype.endOffset_ = null; - - -/** - * Whether the focus node is before the anchor node. - * @type {boolean} - * @private - */ -goog.dom.TextRange.prototype.isReversed_ = false; - - -// Method implementations - - -/** - * @return {goog.dom.TextRange} A clone of this range. - */ -goog.dom.TextRange.prototype.clone = function() { - var range = new goog.dom.TextRange(); - range.browserRangeWrapper_ = this.browserRangeWrapper_; - range.startNode_ = this.startNode_; - range.startOffset_ = this.startOffset_; - range.endNode_ = this.endNode_; - range.endOffset_ = this.endOffset_; - range.isReversed_ = this.isReversed_; - - return range; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getType = function() { - return goog.dom.RangeType.TEXT; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getBrowserRangeObject = function() { - return this.getBrowserRangeWrapper_().getBrowserRange(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.setBrowserRangeObject = function(nativeRange) { - // Test if it's a control range by seeing if a control range only method - // exists. - if (goog.dom.AbstractRange.isNativeControlRange(nativeRange)) { - return false; - } - this.browserRangeWrapper_ = goog.dom.browserrange.createRange( - nativeRange); - this.clearCachedValues_(); - return true; -}; - - -/** - * Clear all cached values. - * @private - */ -goog.dom.TextRange.prototype.clearCachedValues_ = function() { - this.startNode_ = this.startOffset_ = this.endNode_ = this.endOffset_ = null; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getTextRangeCount = function() { - return 1; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getTextRange = function(i) { - return this; -}; - - -/** - * @return {goog.dom.browserrange.AbstractRange} The range wrapper object. - * @private - */ -goog.dom.TextRange.prototype.getBrowserRangeWrapper_ = function() { - return this.browserRangeWrapper_ || - (this.browserRangeWrapper_ = goog.dom.browserrange.createRangeFromNodes( - this.getStartNode(), this.getStartOffset(), - this.getEndNode(), this.getEndOffset())); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getContainer = function() { - return this.getBrowserRangeWrapper_().getContainer(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getStartNode = function() { - return this.startNode_ || - (this.startNode_ = this.getBrowserRangeWrapper_().getStartNode()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getStartOffset = function() { - return this.startOffset_ != null ? this.startOffset_ : - (this.startOffset_ = this.getBrowserRangeWrapper_().getStartOffset()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getEndNode = function() { - return this.endNode_ || - (this.endNode_ = this.getBrowserRangeWrapper_().getEndNode()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getEndOffset = function() { - return this.endOffset_ != null ? this.endOffset_ : - (this.endOffset_ = this.getBrowserRangeWrapper_().getEndOffset()); -}; - - -/** - * Moves a TextRange to the provided nodes and offsets. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @param {boolean} isReversed Whether the range is reversed. - */ -goog.dom.TextRange.prototype.moveToNodes = function(startNode, startOffset, - endNode, endOffset, - isReversed) { - this.startNode_ = startNode; - this.startOffset_ = startOffset; - this.endNode_ = endNode; - this.endOffset_ = endOffset; - this.isReversed_ = isReversed; - this.browserRangeWrapper_ = null; -}; - - -/** @override */ -goog.dom.TextRange.prototype.isReversed = function() { - return this.isReversed_; -}; - - -/** @override */ -goog.dom.TextRange.prototype.containsRange = function(otherRange, - opt_allowPartial) { - var otherRangeType = otherRange.getType(); - if (otherRangeType == goog.dom.RangeType.TEXT) { - return this.getBrowserRangeWrapper_().containsRange( - otherRange.getBrowserRangeWrapper_(), opt_allowPartial); - } else if (otherRangeType == goog.dom.RangeType.CONTROL) { - var elements = otherRange.getElements(); - var fn = opt_allowPartial ? goog.array.some : goog.array.every; - return fn(elements, function(el) { - return this.containsNode(el, opt_allowPartial); - }, this); - } - return false; -}; - - -/** - * Tests if the given node is in a document. - * @param {Node} node The node to check. - * @return {boolean} Whether the given node is in the given document. - */ -goog.dom.TextRange.isAttachedNode = function(node) { - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - var returnValue = false; - /** @preserveTry */ - try { - returnValue = node.parentNode; - } catch (e) { - // IE sometimes throws Invalid Argument errors when a node is detached. - // Note: trying to return a value from the above try block can cause IE - // to crash. It is necessary to use the local returnValue - } - return !!returnValue; - } else { - return goog.dom.contains(node.ownerDocument.body, node); - } -}; - - -/** @override */ -goog.dom.TextRange.prototype.isRangeInDocument = function() { - // Ensure any cached nodes are in the document. IE also allows ranges to - // become detached, so we check if the range is still in the document as - // well for IE. - return (!this.startNode_ || - goog.dom.TextRange.isAttachedNode(this.startNode_)) && - (!this.endNode_ || - goog.dom.TextRange.isAttachedNode(this.endNode_)) && - (!(goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) || - this.getBrowserRangeWrapper_().isRangeInDocument()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.isCollapsed = function() { - return this.getBrowserRangeWrapper_().isCollapsed(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getText = function() { - return this.getBrowserRangeWrapper_().getText(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getHtmlFragment = function() { - // TODO(robbyw): Generalize the code in browserrange so it is static and - // just takes an iterator. This would mean we don't always have to create a - // browser range. - return this.getBrowserRangeWrapper_().getHtmlFragment(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getValidHtml = function() { - return this.getBrowserRangeWrapper_().getValidHtml(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getPastableHtml = function() { - // TODO(robbyw): Get any attributes the table or tr has. - - var html = this.getValidHtml(); - - if (html.match(/^\s*<td\b/i)) { - // Match html starting with a TD. - html = '<table><tbody><tr>' + html + '</tr></tbody></table>'; - } else if (html.match(/^\s*<tr\b/i)) { - // Match html starting with a TR. - html = '<table><tbody>' + html + '</tbody></table>'; - } else if (html.match(/^\s*<tbody\b/i)) { - // Match html starting with a TBODY. - html = '<table>' + html + '</table>'; - } else if (html.match(/^\s*<li\b/i)) { - // Match html starting with an LI. - var container = this.getContainer(); - var tagType = goog.dom.TagName.UL; - while (container) { - if (container.tagName == goog.dom.TagName.OL) { - tagType = goog.dom.TagName.OL; - break; - } else if (container.tagName == goog.dom.TagName.UL) { - break; - } - container = container.parentNode; - } - html = goog.string.buildString('<', tagType, '>', html, '</', tagType, '>'); - } - - return html; -}; - - -/** - * Returns a TextRangeIterator over the contents of the range. Regardless of - * the direction of the range, the iterator will move in document order. - * @param {boolean=} opt_keys Unused for this iterator. - * @return {goog.dom.TextRangeIterator} An iterator over tags in the range. - */ -goog.dom.TextRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.TextRangeIterator(this.getStartNode(), - this.getStartOffset(), this.getEndNode(), this.getEndOffset()); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.TextRange.prototype.select = function() { - this.getBrowserRangeWrapper_().select(this.isReversed_); -}; - - -/** @override */ -goog.dom.TextRange.prototype.removeContents = function() { - this.getBrowserRangeWrapper_().removeContents(); - this.clearCachedValues_(); -}; - - -/** - * Surrounds the text range with the specified element (on Mozilla) or with a - * clone of the specified element (on IE). Returns a reference to the - * surrounding element if the operation was successful; returns null if the - * operation failed. - * @param {Element} element The element with which the selection is to be - * surrounded. - * @return {Element} The surrounding element (same as the argument on Mozilla, - * but not on IE), or null if unsuccessful. - */ -goog.dom.TextRange.prototype.surroundContents = function(element) { - var output = this.getBrowserRangeWrapper_().surroundContents(element); - this.clearCachedValues_(); - return output; -}; - - -/** @override */ -goog.dom.TextRange.prototype.insertNode = function(node, before) { - var output = this.getBrowserRangeWrapper_().insertNode(node, before); - this.clearCachedValues_(); - return output; -}; - - -/** @override */ -goog.dom.TextRange.prototype.surroundWithNodes = function(startNode, endNode) { - this.getBrowserRangeWrapper_().surroundWithNodes(startNode, endNode); - this.clearCachedValues_(); -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.TextRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedTextRange_(this); -}; - - -// RANGE MODIFICATION - - -/** @override */ -goog.dom.TextRange.prototype.collapse = function(toAnchor) { - var toStart = this.isReversed() ? !toAnchor : toAnchor; - - if (this.browserRangeWrapper_) { - this.browserRangeWrapper_.collapse(toStart); - } - - if (toStart) { - this.endNode_ = this.startNode_; - this.endOffset_ = this.startOffset_; - } else { - this.startNode_ = this.endNode_; - this.startOffset_ = this.endOffset_; - } - - // Collapsed ranges can't be reversed - this.isReversed_ = false; -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.AbstractRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedTextRange_ = function(range) { - /** - * The anchor node. - * @type {Node} - * @private - */ - this.anchorNode_ = range.getAnchorNode(); - - /** - * The anchor node offset. - * @type {number} - * @private - */ - this.anchorOffset_ = range.getAnchorOffset(); - - /** - * The focus node. - * @type {Node} - * @private - */ - this.focusNode_ = range.getFocusNode(); - - /** - * The focus node offset. - * @type {number} - * @private - */ - this.focusOffset_ = range.getFocusOffset(); -}; -goog.inherits(goog.dom.DomSavedTextRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.DomSavedTextRange_.prototype.restoreInternal = function() { - return goog.dom.Range.createFromNodes(this.anchorNode_, this.anchorOffset_, - this.focusNode_, this.focusOffset_); -}; - - -/** @override */ -goog.dom.DomSavedTextRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedTextRange_.superClass_.disposeInternal.call(this); - - this.anchorNode_ = null; - this.focusNode_ = null; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base deleted file mode 100644 index 12af489..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base +++ /dev/null @@ -1,127 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.TextRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.dom.ControlRange'); - goog.require('goog.dom.TextRange'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1"></div> - <div id="test2"> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - </div> - <!-- Omit whitespace here to ensure no extra text nodes are included. --> - <table id="table"><tbody id="tbody"><tr id="tr1"><td id="td11">a</td - ><td id="td12">b</td></tr><tr id="tr2"><td id="td21">c</td><td id="td22" - >d</td></tr></tbody></table> - <table id="table2"> - <tr> - <td>moof</td> - </tr> - <tr> - <td id="table2td"> - <div id="table2div">foo<img id="logo2" - src="http://www.google.com/intl/en_ALL/images/logo.gif">bar</div> - </td> - </tr> - </table> - - -<script> - var logo = goog.dom.getElement('logo'); - var logo2 = goog.dom.getElement('logo2'); - var table = goog.dom.getElement('table'); - var table2 = goog.dom.getElement('table2'); - var table2div = goog.dom.getElement('table2div'); - - function testCreateFromNodeContents() { - assertNotNull('Text range object can be created for element node', - goog.dom.TextRange.createFromNodeContents(logo)); - assertNotNull('Text range object can be created for text node', - goog.dom.TextRange.createFromNodeContents(logo2.previousSibling)); - } - - function testMoveToNodes() { - var range = goog.dom.TextRange.createFromNodeContents(table2); - range.moveToNodes(table2div, 0, table2div, 1, false); - assertEquals('Range should start in table2div', - table2div, - range.getStartNode()); - assertEquals('Range should end in table2div', - table2div, - range.getEndNode()); - assertEquals('Range start offset should be 0', - 0, - range.getStartOffset()); - assertEquals('Range end offset should be 0', - 1, - range.getEndOffset()); - assertFalse('Range should not be reversed', - range.isReversed()); - range.moveToNodes(table2div, 0, table2div, 1, true); - assertTrue('Range should be reversed', - range.isReversed()); - assertEquals('Range text should be "foo"', - 'foo', - range.getText()); - } - - function testContainsTextRange() { - var range = goog.dom.TextRange.createFromNodeContents(table2); - var range2 = goog.dom.TextRange.createFromNodeContents(table2div); - assertTrue('TextRange contains other TextRange', - range.containsRange(range2)); - assertFalse('TextRange does not contain other TextRange', - range2.containsRange(range)); - - range = goog.dom.Range.createFromNodes( - table2div.firstChild, 1, table2div.lastChild, 1); - range2 = goog.dom.TextRange.createFromNodes( - table2div.firstChild, 0, table2div.lastChild, 0); - if (!goog.userAgent.WEBKIT) { - // TODO(user): Figure out why this fails, fix it, and get the WebKit - // folks to fix it :-) - assertTrue('TextRange partially contains other TextRange', - range2.containsRange(range, true)); - } - assertFalse('TextRange does not fully contain other TextRange', - range2.containsRange(range, false)); - - } - - function testContainsControlRange() { - if (goog.userAgent.IE) { - var range = goog.dom.ControlRange.createFromElements(table2); - var range2 = goog.dom.TextRange.createFromNodeContents(table2div); - assertFalse('TextRange does not contain ControlRange', - range2.containsRange(range)); - range = goog.dom.ControlRange.createFromElements(logo2); - assertTrue('TextRange contains ControlRange', - range2.containsRange(range)); - range = goog.dom.TextRange.createFromNodeContents(table2); - range2 = goog.dom.ControlRange.createFromElements(logo, logo2); - assertTrue('TextRange partially contains ControlRange', - range2.containsRange(range, true)); - assertFalse('TextRange does not fully contain ControlRange', - range2.containsRange(range, false)); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base deleted file mode 100644 index aef7f77..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator between two DOM text range positions. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.TextRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.TagName'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {Node} startNode The starting node position. - * @param {number} startOffset The offset in to startNode. If startNode is - * an element, indicates an offset in to childNodes. If startNode is a - * text node, indicates an offset in to nodeValue. - * @param {Node} endNode The ending node position. - * @param {number} endOffset The offset in to endNode. If endNode is - * an element, indicates an offset in to childNodes. If endNode is a - * text node, indicates an offset in to nodeValue. - * @param {boolean=} opt_reverse Whether to traverse nodes in reverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.TextRangeIterator = function(startNode, startOffset, endNode, - endOffset, opt_reverse) { - var goNext; - - if (startNode) { - this.startNode_ = startNode; - this.startOffset_ = startOffset; - this.endNode_ = endNode; - this.endOffset_ = endOffset; - - // Skip to the offset nodes - being careful to special case BRs since these - // have no children but still can appear as the startContainer of a range. - if (startNode.nodeType == goog.dom.NodeType.ELEMENT && - startNode.tagName != goog.dom.TagName.BR) { - var startChildren = startNode.childNodes; - var candidate = startChildren[startOffset]; - if (candidate) { - this.startNode_ = candidate; - this.startOffset_ = 0; - } else { - if (startChildren.length) { - this.startNode_ = - /** @type {Node} */ (goog.array.peek(startChildren)); - } - goNext = true; - } - } - - if (endNode.nodeType == goog.dom.NodeType.ELEMENT) { - this.endNode_ = endNode.childNodes[endOffset]; - if (this.endNode_) { - this.endOffset_ = 0; - } else { - // The offset was past the last element. - this.endNode_ = endNode; - } - } - } - - goog.dom.RangeIterator.call(this, opt_reverse ? this.endNode_ : - this.startNode_, opt_reverse); - - if (goNext) { - try { - this.next(); - } catch (e) { - if (e != goog.iter.StopIteration) { - throw e; - } - } - } -}; -goog.inherits(goog.dom.TextRangeIterator, goog.dom.RangeIterator); - - -/** - * The first node in the selection. - * @type {Node} - * @private - */ -goog.dom.TextRangeIterator.prototype.startNode_ = null; - - -/** - * The last node in the selection. - * @type {Node} - * @private - */ -goog.dom.TextRangeIterator.prototype.endNode_ = null; - - -/** - * The offset within the first node in the selection. - * @type {number} - * @private - */ -goog.dom.TextRangeIterator.prototype.startOffset_ = 0; - - -/** - * The offset within the last node in the selection. - * @type {number} - * @private - */ -goog.dom.TextRangeIterator.prototype.endOffset_ = 0; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getStartTextOffset = function() { - // Offsets only apply to text nodes. If our current node is the start node, - // return the saved offset. Otherwise, return 0. - return this.node.nodeType != goog.dom.NodeType.TEXT ? -1 : - this.node == this.startNode_ ? this.startOffset_ : 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getEndTextOffset = function() { - // Offsets only apply to text nodes. If our current node is the end node, - // return the saved offset. Otherwise, return the length of the node. - return this.node.nodeType != goog.dom.NodeType.TEXT ? -1 : - this.node == this.endNode_ ? this.endOffset_ : this.node.nodeValue.length; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getStartNode = function() { - return this.startNode_; -}; - - -/** - * Change the start node of the iterator. - * @param {Node} node The new start node. - */ -goog.dom.TextRangeIterator.prototype.setStartNode = function(node) { - if (!this.isStarted()) { - this.setPosition(node); - } - - this.startNode_ = node; - this.startOffset_ = 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getEndNode = function() { - return this.endNode_; -}; - - -/** - * Change the end node of the iterator. - * @param {Node} node The new end node. - */ -goog.dom.TextRangeIterator.prototype.setEndNode = function(node) { - this.endNode_ = node; - this.endOffset_ = 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.isLast = function() { - return this.isStarted() && this.node == this.endNode_ && - (!this.endOffset_ || !this.isStartTag()); -}; - - -/** - * Move to the next position in the selection. - * Throws {@code goog.iter.StopIteration} when it passes the end of the range. - * @return {Node} The node at the next position. - */ -goog.dom.TextRangeIterator.prototype.next = function() { - if (this.isLast()) { - throw goog.iter.StopIteration; - } - - // Call the super function. - return goog.dom.TextRangeIterator.superClass_.next.call(this); -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.skipTag = function() { - goog.dom.TextRangeIterator.superClass_.skipTag.apply(this); - - // If the node we are skipping contains the end node, we just skipped past - // the end, so we stop the iteration. - if (goog.dom.contains(this.node, this.endNode_)) { - throw goog.iter.StopIteration; - } -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.TextRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.TextRangeIterator.prototype.copyFrom = function(other) { - this.startNode_ = other.startNode_; - this.endNode_ = other.endNode_; - this.startOffset_ = other.startOffset_; - this.endOffset_ = other.endOffset_; - this.isReversed_ = other.isReversed_; - - goog.dom.TextRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.TextRangeIterator} An identical iterator. - */ -goog.dom.TextRangeIterator.prototype.clone = function() { - var copy = new goog.dom.TextRangeIterator(this.startNode_, - this.startOffset_, this.endNode_, this.endOffset_, this.isReversed_); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base deleted file mode 100644 index 028b771..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base +++ /dev/null @@ -1,142 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.TextRangeIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.TagName'); - goog.require('goog.dom.TextRangeIterator'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<!-- - The next line goes past 80 characters to avoid ambiguity with - newlines as text nodes ---> -<div id="test"><a href="#" id="a1">T<b id="b1">e</b>xt</a><span id="span1"></span><p id="p1">Text</p></div> -<ul id="test2">foo<br>bar</ul> - -<script> - var test = goog.dom.getElement('test'); - var test2 = goog.dom.getElement('test2'); - - function testBasic() { - goog.testing.dom.assertNodesMatch( - new goog.dom.TextRangeIterator(test, 0, test, 2), - ['#a1', 'T', '#b1', 'e', '#b1', 'xt', '#a1', '#span1', - '#span1', '#p1']); - } - - function testAdjustStart() { - var iterator = new goog.dom.TextRangeIterator(test, 0, test, 2); - iterator.setStartNode(goog.dom.getElement('span1')); - - goog.testing.dom.assertNodesMatch(iterator, - ['#span1', '#span1', '#p1']); - } - - function testAdjustEnd() { - var iterator = new goog.dom.TextRangeIterator(test, 0, test, 2); - iterator.setEndNode(goog.dom.getElement('span1')); - - goog.testing.dom.assertNodesMatch(iterator, - ['#a1', 'T', '#b1', 'e', '#b1', 'xt', '#a1', '#span1']); - } - - function testOffsets() { - var iterator = new goog.dom.TextRangeIterator(test2.firstChild, 1, - test2.lastChild, 2); - - // foo - var node = iterator.next(); - assertEquals('Should have start offset at iteration step 1', 1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 1', - node.nodeValue.length, iterator.getEndTextOffset()); - - // <br> - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 2', -1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 2', -1, - iterator.getEndTextOffset()); - - // </br> - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 3', -1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 3', -1, - iterator.getEndTextOffset()); - - // bar - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 4', 0, - iterator.getStartTextOffset()); - assertEquals('Should have end offset at iteration step 4', 2, - iterator.getEndTextOffset()); - } - - function testSingleNodeOffsets() { - var iterator = new goog.dom.TextRangeIterator(test2.firstChild, 1, - test2.firstChild, 2); - - iterator.next(); - assertEquals('Should have start offset', 1, iterator.getStartTextOffset()); - assertEquals('Should have end offset', 2, iterator.getEndTextOffset()); - } - - function testEndNodeOffsetAtEnd() { - var iterator = new goog.dom.TextRangeIterator( - goog.dom.getElement('b1').firstChild, 0, goog.dom.getElement('b1'), 1); - goog.testing.dom.assertNodesMatch(iterator, ['e', '#b1']); - } - - function testSkipTagDoesNotSkipEnd() { - // Iterate over 'Tex'. - var iterator = new goog.dom.TextRangeIterator( - test.firstChild.firstChild, 0, - test.firstChild.lastChild, 1); - - var node = iterator.next(); - assertEquals('T', node.nodeValue); - - node = iterator.next(); - assertEquals(goog.dom.TagName.B, node.tagName); - - iterator.skipTag(); - - node = iterator.next(); - assertEquals('xt', node.nodeValue); - } - - function testSkipTagSkipsEnd() { - // Iterate over 'Te'. - var iterator = new goog.dom.TextRangeIterator( - test.firstChild.firstChild, 0, - test.getElementsByTagName(goog.dom.TagName.B)[0].firstChild, 1); - - var node = iterator.next(); - assertEquals('T', node.nodeValue); - - node = iterator.next(); - assertEquals(goog.dom.TagName.B, node.tagName); - - var ex = assertThrows('Should stop iteration when skipping B', function() { - iterator.skipTag(); - }); - assertEquals(goog.iter.StopIteration, ex); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base deleted file mode 100644 index db24177..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utility class that monitors viewport size changes. - * - * @author attila@google.com (Attila Bodis) - * @see ../demos/viewportsizemonitor.html - */ - -goog.provide('goog.dom.ViewportSizeMonitor'); - -goog.require('goog.dom'); -goog.require('goog.events'); -goog.require('goog.events.EventTarget'); -goog.require('goog.events.EventType'); -goog.require('goog.math.Size'); -goog.require('goog.userAgent'); - - - -/** - * This class can be used to monitor changes in the viewport size. Instances - * dispatch a {@link goog.events.EventType.RESIZE} event when the viewport size - * changes. Handlers can call {@link goog.dom.ViewportSizeMonitor#getSize} to - * get the new viewport size. - * - * Use this class if you want to execute resize/reflow logic each time the - * user resizes the browser window. This class is guaranteed to only dispatch - * {@code RESIZE} events when the pixel dimensions of the viewport change. - * (Internet Explorer fires resize events if any element on the page is resized, - * even if the viewport dimensions are unchanged, which can lead to infinite - * resize loops.) - * - * Example usage: - * <pre> - * var vsm = new goog.dom.ViewportSizeMonitor(); - * goog.events.listen(vsm, goog.events.EventType.RESIZE, function(e) { - * alert('Viewport size changed to ' + vsm.getSize()); - * }); - * </pre> - * - * Manually verified on IE6, IE7, FF2, Opera 9, and WebKit. {@code getSize} - * doesn't always return the correct viewport height on Safari 2.0.4. - * - * @param {Window=} opt_window The window to monitor; defaults to the window in - * which this code is executing. - * @constructor - * @extends {goog.events.EventTarget} - */ -goog.dom.ViewportSizeMonitor = function(opt_window) { - goog.events.EventTarget.call(this); - - // Default the window to the current window if unspecified. - this.window_ = opt_window || window; - - // Listen for window resize events. - this.listenerKey_ = goog.events.listen(this.window_, - goog.events.EventType.RESIZE, this.handleResize_, false, this); - - // Set the initial size. - this.size_ = goog.dom.getViewportSize(this.window_); - - if (this.isPollingRequired_()) { - this.windowSizePollInterval_ = window.setInterval( - goog.bind(this.checkForSizeChange_, this), - goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - } -}; -goog.inherits(goog.dom.ViewportSizeMonitor, goog.events.EventTarget); - - -/** - * Returns a viewport size monitor for the given window. A new one is created - * if it doesn't exist already. This prevents the unnecessary creation of - * multiple spooling monitors for a window. - * @param {Window=} opt_window The window to monitor; defaults to the window in - * which this code is executing. - * @return {goog.dom.ViewportSizeMonitor} Monitor for the given window. - */ -goog.dom.ViewportSizeMonitor.getInstanceForWindow = function(opt_window) { - var currentWindow = opt_window || window; - var uid = goog.getUid(currentWindow); - - return goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid] = - goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid] || - new goog.dom.ViewportSizeMonitor(currentWindow); -}; - - -/** - * Map of window hash code to viewport size monitor for that window, if - * created. - * @type {Object.<number,goog.dom.ViewportSizeMonitor>} - * @private - */ -goog.dom.ViewportSizeMonitor.windowInstanceMap_ = {}; - - -/** - * Rate in milliseconds at which to poll the window size on browsers that - * need polling. - * @type {number} - */ -goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE = 500; - - -/** - * Event listener key for window the window resize handler, as returned by - * {@link goog.events.listen}. - * @type {?number} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.listenerKey_ = null; - - -/** - * The window to monitor. Defaults to the window in which the code is running. - * @type {Window} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.window_ = null; - - -/** - * The most recently recorded size of the viewport, in pixels. - * @type {goog.math.Size?} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.size_ = null; - - -/** - * Identifier for the interval used for polling the window size on Windows - * Safari. - * @type {?number} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.windowSizePollInterval_ = null; - - -/** - * Checks if polling is required for this user agent. Opera only requires - * polling when the page is loaded within an IFRAME. - * @return {boolean} Whether polling is required. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.isPollingRequired_ = function() { - return goog.userAgent.WEBKIT && goog.userAgent.WINDOWS || - goog.userAgent.OPERA && this.window_.self != this.window_.top; -}; - - -/** - * Returns the most recently recorded size of the viewport, in pixels. May - * return null if no window resize event has been handled yet. - * @return {goog.math.Size} The viewport dimensions, in pixels. - */ -goog.dom.ViewportSizeMonitor.prototype.getSize = function() { - // Return a clone instead of the original to preserve encapsulation. - return this.size_ ? this.size_.clone() : null; -}; - - -/** @override */ -goog.dom.ViewportSizeMonitor.prototype.disposeInternal = function() { - goog.dom.ViewportSizeMonitor.superClass_.disposeInternal.call(this); - - if (this.listenerKey_) { - goog.events.unlistenByKey(this.listenerKey_); - this.listenerKey_ = null; - } - - if (this.windowSizePollInterval_) { - window.clearInterval(this.windowSizePollInterval_); - this.windowSizePollInterval_ = null; - } - - this.window_ = null; - this.size_ = null; -}; - - -/** - * Handles window resize events by measuring the dimensions of the - * viewport and dispatching a {@link goog.events.EventType.RESIZE} event if the - * current dimensions are different from the previous ones. - * @param {goog.events.Event} event The window resize event to handle. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.handleResize_ = function(event) { - this.checkForSizeChange_(); -}; - - -/** - * Measures the dimensions of the viewport and dispatches a - * {@link goog.events.EventType.RESIZE} event if the current dimensions are - * different from the previous ones. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.checkForSizeChange_ = function() { - var size = goog.dom.getViewportSize(this.window_); - if (!goog.math.Size.equals(size, this.size_)) { - this.size_ = size; - this.dispatchEvent(goog.events.EventType.RESIZE); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base deleted file mode 100644 index d9b3c5f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base +++ /dev/null @@ -1,166 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.ViewportSizeMonitor</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.ViewportSizeMonitor'); - goog.require('goog.events.Event'); - goog.require('goog.events.EventTarget'); - goog.require('goog.events.EventType'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.MockClock'); - goog.require('goog.testing.PropertyReplacer'); -</script> -</head> -<body> -<script> - var propertyReplacer, fakeWindow, viewportSizeMonitor, mockClock; - - - function FakeWindow() { - }; - goog.inherits(FakeWindow, goog.events.EventTarget); - - - FakeWindow.prototype.fireResize = function() { - return this.dispatchEvent(new FakeResizeEvent()); - }; - - - function FakeResizeEvent(obj) { - this.type = goog.events.EventType.RESIZE; - } - goog.inherits(FakeResizeEvent, goog.events.Event); - - - function getViewportSize() { - return viewportSize; - }; - - - function setViewportSize(w, h, fireEvent) { - this.viewportSize = new goog.math.Size(w, h); - if (fireEvent) { - fakeWindow.fireResize(); - } - }; - - - var eventWasFired = {}; - function getListenerFn(id) { - return function() { - propertyReplacer.set(eventWasFired, id, true); - }; - }; - - - function listenerWasCalled(id) { - return !!eventWasFired[id]; - }; - - - function setUp() { - propertyReplacer = new goog.testing.PropertyReplacer(); - propertyReplacer.set(goog.dom, 'getViewportSize', getViewportSize); - mockClock = new goog.testing.MockClock(); - mockClock.install(); - fakeWindow = new FakeWindow(); - setViewportSize(300, 300); - viewportSizeMonitor = new goog.dom.ViewportSizeMonitor(fakeWindow); - }; - - - function tearDown() { - propertyReplacer.reset(); - mockClock.uninstall(); - }; - - - function testResizeEvent() { - goog.events.listen(viewportSizeMonitor, goog.events.EventType.RESIZE, - getListenerFn(1)); - assertFalse('Listener should not be called if window was not resized', - listenerWasCalled(1)); - setViewportSize(300, 300, true); - assertFalse('Listener should not be called for bogus resize event', - listenerWasCalled(1)); - setViewportSize(301, 301, true); - assertTrue('Listener should be called for valid resize event', - listenerWasCalled(1)); - }; - - - function testPollingEvent() { - propertyReplacer.set(goog.dom.ViewportSizeMonitor.prototype, - 'isPollingRequired_', function() { return true; }); - viewportSizeMonitor = new goog.dom.ViewportSizeMonitor(fakeWindow); - goog.events.listen(viewportSizeMonitor, goog.events.EventType.RESIZE, - getListenerFn(1)); - assertFalse('Listener should not be called if window was not resized', - listenerWasCalled(1)); - mockClock.tick(goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - assertFalse('Listener should not be called if window was not resized ' + - 'during polling', listenerWasCalled(1)); - setViewportSize(301, 301, false); - mockClock.tick(goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - assertTrue('Listener should be called for valid resize during polling', - listenerWasCalled(1)); - }; - - - function testIsPollingRequired() { - propertyReplacer.set(goog.userAgent, 'WEBKIT', false); - propertyReplacer.set(goog.userAgent, 'OPERA', false); - assertFalse('Polling should not be required except for WebKit and Opera', - viewportSizeMonitor.isPollingRequired_()); - propertyReplacer.set(goog.userAgent, 'WEBKIT', true); - propertyReplacer.set(goog.userAgent, 'WINDOWS', true); - assertTrue('WebKit on Windows should require polling', - viewportSizeMonitor.isPollingRequired_()); - propertyReplacer.set(goog.userAgent, 'WEBKIT', false); - propertyReplacer.set(goog.userAgent, 'OPERA', true); - - // window.top and window.self are read-only in Opera - fakeWindow.self = fakeWindow; - fakeWindow.top = {}; - assertEquals('Opera should require polling if window.top != window.self', - viewportSizeMonitor.isPollingRequired_(), true); - fakeWindow.self = fakeWindow; - fakeWindow.top = fakeWindow; - assertEquals( - 'Opera should not require polling if window.top == window.self', - viewportSizeMonitor.isPollingRequired_(), false); - }; - - - function testInstanceGetter() { - var fakeWindow1 = new FakeWindow(); - var monitor1 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow1); - var monitor2 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow1); - assertEquals('The same window should give us the same instance monitor', - monitor1, monitor2); - - var fakeWindow2 = new FakeWindow(); - var monitor3 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow2); - assertNotEquals('Different windows should give different instances', - monitor1, monitor3); - - assertEquals('Monitors should match if opt_window is not provided', - goog.dom.ViewportSizeMonitor.getInstanceForWindow(), - goog.dom.ViewportSizeMonitor.getInstanceForWindow()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base deleted file mode 100644 index a5ab4f8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview - * XML utilities. - * - */ - -goog.provide('goog.dom.xml'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); - - -/** - * Max XML size for MSXML2. Used to prevent potential DoS attacks. - * @type {number} - */ -goog.dom.xml.MAX_XML_SIZE_KB = 2 * 1024; // In kB - - -/** - * Max XML size for MSXML2. Used to prevent potential DoS attacks. - * @type {number} - */ -goog.dom.xml.MAX_ELEMENT_DEPTH = 256; // Same default as MSXML6. - - -/** - * Creates an XML document appropriate for the current JS runtime - * @param {string=} opt_rootTagName The root tag name. - * @param {string=} opt_namespaceUri Namespace URI of the document element. - * @return {Document} The new document. - */ -goog.dom.xml.createDocument = function(opt_rootTagName, opt_namespaceUri) { - if (opt_namespaceUri && !opt_rootTagName) { - throw Error("Can't create document with namespace and no root tag"); - } - if (document.implementation && document.implementation.createDocument) { - return document.implementation.createDocument(opt_namespaceUri || '', - opt_rootTagName || '', - null); - } else if (typeof ActiveXObject != 'undefined') { - var doc = goog.dom.xml.createMsXmlDocument_(); - if (doc) { - if (opt_rootTagName) { - doc.appendChild(doc.createNode(goog.dom.NodeType.ELEMENT, - opt_rootTagName, - opt_namespaceUri || '')); - } - return doc; - } - } - throw Error('Your browser does not support creating new documents'); -}; - - -/** - * Creates an XML document from a string - * @param {string} xml The text. - * @return {Document} XML document from the text. - */ -goog.dom.xml.loadXml = function(xml) { - if (typeof DOMParser != 'undefined') { - return new DOMParser().parseFromString(xml, 'application/xml'); - } else if (typeof ActiveXObject != 'undefined') { - var doc = goog.dom.xml.createMsXmlDocument_(); - doc.loadXML(xml); - return doc; - } - throw Error('Your browser does not support loading xml documents'); -}; - - -/** - * Serializes an XML document or subtree to string. - * @param {Document|Element} xml The document or the root node of the subtree. - * @return {string} The serialized XML. - */ -goog.dom.xml.serialize = function(xml) { - // Compatible with Firefox, Opera and WebKit. - if (typeof XMLSerializer != 'undefined') { - return new XMLSerializer().serializeToString(xml); - } - // Compatible with Internet Explorer. - var text = xml.xml; - if (text) { - return text; - } - throw Error('Your browser does not support serializing XML documents'); -}; - - -/** - * Selects a single node using an Xpath expression and a root node - * @param {Node} node The root node. - * @param {string} path Xpath selector. - * @return {Node} The selected node, or null if no matching node. - */ -goog.dom.xml.selectSingleNode = function(node, path) { - if (typeof node.selectSingleNode != 'undefined') { - var doc = goog.dom.getOwnerDocument(node); - if (typeof doc.setProperty != 'undefined') { - doc.setProperty('SelectionLanguage', 'XPath'); - } - return node.selectSingleNode(path); - } else if (document.implementation.hasFeature('XPath', '3.0')) { - var doc = goog.dom.getOwnerDocument(node); - var resolver = doc.createNSResolver(doc.documentElement); - var result = doc.evaluate(path, node, resolver, - XPathResult.FIRST_ORDERED_NODE_TYPE, null); - return result.singleNodeValue; - } - return null; -}; - - -/** - * Selects multiple nodes using an Xpath expression and a root node - * @param {Node} node The root node. - * @param {string} path Xpath selector. - * @return {(NodeList,Array.<Node>)} The selected nodes, or empty array if no - * matching nodes. - */ -goog.dom.xml.selectNodes = function(node, path) { - if (typeof node.selectNodes != 'undefined') { - var doc = goog.dom.getOwnerDocument(node); - if (typeof doc.setProperty != 'undefined') { - doc.setProperty('SelectionLanguage', 'XPath'); - } - return node.selectNodes(path); - } else if (document.implementation.hasFeature('XPath', '3.0')) { - var doc = goog.dom.getOwnerDocument(node); - var resolver = doc.createNSResolver(doc.documentElement); - var nodes = doc.evaluate(path, node, resolver, - XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - var results = []; - var count = nodes.snapshotLength; - for (var i = 0; i < count; i++) { - results.push(nodes.snapshotItem(i)); - } - return results; - } else { - return []; - } -}; - - -/** - * Sets multiple attributes on an element. Differs from goog.dom.setProperties - * in that it exclusively uses the element's setAttributes method. Use this - * when you need to ensure that the exact property is available as an attribute - * and can be read later by the native getAttribute method. - * @param {!Element} element XML or DOM element to set attributes on. - * @param {!Object.<string, string>} attributes Map of property:value pairs. - */ -goog.dom.xml.setAttributes = function(element, attributes) { - for (var key in attributes) { - if (attributes.hasOwnProperty(key)) { - element.setAttribute(key, attributes[key]); - } - } -}; - - -/** - * Creates an instance of the MSXML2.DOMDocument. - * @return {Document} The new document. - * @private - */ -goog.dom.xml.createMsXmlDocument_ = function() { - var doc = new ActiveXObject('MSXML2.DOMDocument'); - if (doc) { - // Prevent potential vulnerabilities exposed by MSXML2, see - // http://b/1707300 and http://wiki/Main/ISETeamXMLAttacks for details. - doc.resolveExternals = false; - doc.validateOnParse = false; - // Add a try catch block because accessing these properties will throw an - // error on unsupported MSXML versions. This affects Windows machines - // running IE6 or IE7 that are on XP SP2 or earlier without MSXML updates. - // See http://msdn.microsoft.com/en-us/library/ms766391(VS.85).aspx for - // specific details on which MSXML versions support these properties. - try { - doc.setProperty('ProhibitDTD', true); - doc.setProperty('MaxXMLSize', goog.dom.xml.MAX_XML_SIZE_KB); - doc.setProperty('MaxElementDepth', goog.dom.xml.MAX_ELEMENT_DEPTH); - } catch (e) { - // No-op. - } - } - return doc; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base deleted file mode 100644 index 0c66d9f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base +++ /dev/null @@ -1,103 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.net.MockXhrLite</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.xml'); - goog.require('goog.string'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> -<script> - -function testSerialize() { - var doc = goog.dom.xml.createDocument(); - var node = doc.createElement('root'); - doc.appendChild(node); - - var serializedNode = goog.dom.xml.serialize(node); - assertTrue(/<root ?\/>/.test(serializedNode)); - - var serializedDoc = goog.dom.xml.serialize(doc); - assertTrue(/(<\?xml version="1.0"\?>)?<root ?\/>/.test(serializedDoc)); -} - -function testBelowMaxDepthInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_ELEMENT_DEPTH = 5; - var junk = '<a><b><c><d><e>Hello</e></d></c></b></a>'; - var doc = goog.dom.xml.loadXml(junk); - assertEquals('Should not have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testAboveMaxDepthInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_ELEMENT_DEPTH = 4; - var junk = '<a><b><c><d><e>Hello</e></d></c></b></a>'; - var doc = goog.dom.xml.loadXml(junk); - assertNotEquals('Should have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testBelowMaxSizeInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_XML_SIZE_KB = 1; - var junk = '<a>' + new Array(50).join('<b>junk</b>') + '</a>'; - var doc = goog.dom.xml.loadXml(junk); - assertEquals('Should not have caused a parse error', - 0, Number(doc.parseError)); - } -} - -function testMaxSizeInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_XML_SIZE_KB = 1; - var junk = '<a>' + new Array(1000).join('<b>junk</b>') + '</a>'; - var doc = goog.dom.xml.loadXml(junk); - assertNotEquals('Should have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testSetAttributes() { - var xmlElement = goog.dom.xml.createDocument().createElement('root'); - var domElement = document.createElement('div'); - var attrs = { - name: 'test3', - title: 'A title', - random: 'woop', - cellpadding: '123' - }; - - goog.dom.xml.setAttributes(xmlElement, attrs); - goog.dom.xml.setAttributes(domElement, attrs); - - assertEquals('test3', xmlElement.getAttribute('name')); - assertEquals('test3', domElement.getAttribute('name')); - - assertEquals('A title', xmlElement.getAttribute('title')); - assertEquals('A title', domElement.getAttribute('title')); - - assertEquals('woop', xmlElement.getAttribute('random')); - assertEquals('woop', domElement.getAttribute('random')); - - assertEquals('123', xmlElement.getAttribute('cellpadding')); - assertEquals('123', domElement.getAttribute('cellpadding')); -} - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/a11y.js b/contexts/data/lib/closure-library/closure/goog/dom/a11y.js index 1ee6463..b01ed55 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/a11y.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/a11y.js @@ -396,7 +396,6 @@ goog.dom.a11y.LivePriority = { */ goog.dom.a11y.setRole = function(element, roleName) { element.setAttribute('role', roleName); - element.roleName = roleName; }; @@ -406,7 +405,7 @@ goog.dom.a11y.setRole = function(element, roleName) { * @return {string} rolename. */ goog.dom.a11y.getRole = function(element) { - return element.roleName || ''; + return element.getAttribute('role') || ''; }; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/a11y_test.html b/contexts/data/lib/closure-library/closure/goog/dom/a11y_test.html index 9d7daba..0a29546 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/a11y_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/a11y_test.html @@ -55,9 +55,17 @@ Author: attila@google.com (Attila Bodis) goog.dom.a11y.setRole(someSpan, goog.dom.a11y.Role.MENU_ITEM); assertEquals('someDiv\'s role should be MENU', - goog.dom.a11y.Role.MENU, goog.dom.a11y.getRole(someDiv)); + goog.dom.a11y.Role.MENU, goog.dom.a11y.getRole(someDiv)); assertEquals('someSpan\'s role should be MENU_ITEM', - goog.dom.a11y.Role.MENU_ITEM, goog.dom.a11y.getRole(someSpan)); + goog.dom.a11y.Role.MENU_ITEM, goog.dom.a11y.getRole(someSpan)); + + var div = goog.dom.createElement('div'); + sandbox.appendChild(div); + div.innerHTML = '<span id="anotherSpan" role="' + + goog.dom.a11y.Role.CHECKBOX + '"></span>'; + assertEquals('anotherSpan\'s role should be CHECKBOX', + goog.dom.a11y.Role.CHECKBOX, + goog.dom.a11y.getRole(document.getElementById('anotherSpan'))); } function testGetSetState() { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/annotate.js b/contexts/data/lib/closure-library/closure/goog/dom/annotate.js index 1f5c7fc..df5ca82 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/annotate.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/annotate.js @@ -52,6 +52,9 @@ goog.dom.annotate.annotateTerms = function(node, terms, annotateFn, opt_ignoreCase, opt_classesToSkip, opt_maxMs) { + if (opt_ignoreCase) { + terms = goog.dom.annotate.lowercaseTerms_(terms); + } var stopTime = opt_maxMs > 0 ? goog.now() + opt_maxMs : 0; return goog.dom.annotate.annotateTermsInNode_( diff --git a/contexts/data/lib/closure-library/closure/goog/dom/annotate_test.html b/contexts/data/lib/closure-library/closure/goog/dom/annotate_test.html index c666494..974b80b 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/annotate_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/annotate_test.html @@ -31,6 +31,14 @@ See the COPYING file for details. <td>This <b>little</b> piggy</td> <td class="s">That little <i>pig</i>gy</td> </tr> + <tr id="t"> + <td>This <b>little</b> piggy</td> + <td class="s">That little <i>Pig</i>gy</td> + </tr> + <tr id="u"> + <td>This <b>little</b> piggy</td> + <td class="s">That little <i>Pig</i>gy</td> + </tr> </table> <div id="o"> @@ -156,6 +164,26 @@ See the COPYING file for details. assertEquals('gy', spans[0].nextSibling.nodeValue); } + function testAnnotateTermsIgnoreCase() { + var terms1 = [['pig', false]]; + assertTrue(goog.dom.annotate.annotateTerms( + $('t'), terms1, doAnnotation, true)); + var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('t')); + assertEquals(2, spans.length); + assertEquals('pig', spans[0].innerHTML); + assertEquals('gy', spans[0].nextSibling.nodeValue); + assertEquals('Pig', spans[1].innerHTML); + + var terms2 = [['Pig', false]]; + assertTrue(goog.dom.annotate.annotateTerms( + $('u'), terms2, doAnnotation, true)); + var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('u')); + assertEquals(2, spans.length); + assertEquals('pig', spans[0].innerHTML); + assertEquals('gy', spans[0].nextSibling.nodeValue); + assertEquals('Pig', spans[1].innerHTML); + } + function testAnnotateTermsInObject() { var terms = [['object', true]]; assertTrue(goog.dom.annotate.annotateTerms($('o'), terms, doAnnotation)); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/all-wcprops deleted file mode 100644 index 0e9abbd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/all-wcprops +++ /dev/null @@ -1,53 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 54 -/svn/!svn/ver/1472/trunk/closure/goog/dom/browserrange -END -geckorange.js -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/1302/trunk/closure/goog/dom/browserrange/geckorange.js -END -browserrange_test.html -K 25 -svn:wc:ra_dav:version-url -V 77 -/svn/!svn/ver/1063/trunk/closure/goog/dom/browserrange/browserrange_test.html -END -w3crange.js -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/1302/trunk/closure/goog/dom/browserrange/w3crange.js -END -ierange.js -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/1472/trunk/closure/goog/dom/browserrange/ierange.js -END -abstractrange.js -K 25 -svn:wc:ra_dav:version-url -V 70 -/svn/!svn/ver/850/trunk/closure/goog/dom/browserrange/abstractrange.js -END -browserrange.js -K 25 -svn:wc:ra_dav:version-url -V 69 -/svn/!svn/ver/850/trunk/closure/goog/dom/browserrange/browserrange.js -END -webkitrange.js -K 25 -svn:wc:ra_dav:version-url -V 69 -/svn/!svn/ver/1302/trunk/closure/goog/dom/browserrange/webkitrange.js -END -operarange.js -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/1302/trunk/closure/goog/dom/browserrange/operarange.js -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/entries b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/entries deleted file mode 100644 index 9bba77b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/entries +++ /dev/null @@ -1,300 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/dom/browserrange -http://closure-library.googlecode.com/svn - - - -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -geckorange.js -file - - - - -2011-12-23T22:42:28.277328Z -32608ce8361ab2120e925718aa1b0fff -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2957 - -browserrange_test.html -file - - - - -2011-12-23T22:42:28.278328Z -4a9a88346a273235b90033519740e3e5 -2011-06-21T16:36:03.000000Z -1063 -gboyer@google.com -has-props - - - - - - - - - - - - - - - - - - - - -25233 - -w3crange.js -file - - - - -2011-12-23T22:42:28.278328Z -9407d5f3c9c71c5130e17839c835b95c -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -11213 - -ierange.js -file - - - - -2011-12-23T22:42:28.278328Z -b7bdf260d05f57eadb0495bdb195ba18 -2011-12-13T22:20:28.000000Z -1472 -ccalabro@google.com -has-props - - - - - - - - - - - - - - - - - - - - -31972 - -abstractrange.js -file - - - - -2011-12-23T22:42:28.279328Z -42ae08c7c773bf5b8a4bcdbca52e24bf -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -10982 - -browserrange.js -file - - - - -2011-12-23T22:42:28.280328Z -ebf0a85b8094f733efe8281159181b5c -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5764 - -webkitrange.js -file - - - - -2011-12-23T22:42:28.280328Z -998fea2cccd1859ec457b0e3fcab4ec2 -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4147 - -operarange.js -file - - - - -2011-12-23T22:42:28.281328Z -5ba06fc0409e11cdf2fee7030958c5ac -2011-09-27T00:20:47.000000Z -1302 -bmccann@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2936 - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/abstractrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/abstractrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/abstractrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/browserrange_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/geckorange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/geckorange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/geckorange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/ierange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/ierange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/ierange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/operarange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/operarange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/operarange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/w3crange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/w3crange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/w3crange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/webkitrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/webkitrange.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/prop-base/webkitrange.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/abstractrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/abstractrange.js.svn-base deleted file mode 100644 index 8875b33..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/abstractrange.js.svn-base +++ /dev/null @@ -1,316 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the browser range interface. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.browserrange.AbstractRange'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.RangeEndpoint'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.TextRangeIterator'); -goog.require('goog.iter'); -goog.require('goog.string'); -goog.require('goog.string.StringBuffer'); -goog.require('goog.userAgent'); - - - -/** - * The constructor for abstract ranges. Don't call this from subclasses. - * @constructor - */ -goog.dom.browserrange.AbstractRange = function() { -}; - - -/** - * @return {goog.dom.browserrange.AbstractRange} A clone of this range. - */ -goog.dom.browserrange.AbstractRange.prototype.clone = goog.abstractMethod; - - -/** - * Returns the browser native implementation of the range. Please refrain from - * using this function - if you find you need the range please add wrappers for - * the functionality you need rather than just using the native range. - * @return {Range|TextRange} The browser native range object. - */ -goog.dom.browserrange.AbstractRange.prototype.getBrowserRange = - goog.abstractMethod; - - -/** - * Returns the deepest node in the tree that contains the entire range. - * @return {Node} The deepest node that contains the entire range. - */ -goog.dom.browserrange.AbstractRange.prototype.getContainer = - goog.abstractMethod; - - -/** - * Returns the node the range starts in. - * @return {Node} The element or text node the range starts in. - */ -goog.dom.browserrange.AbstractRange.prototype.getStartNode = - goog.abstractMethod; - - -/** - * Returns the offset into the node the range starts in. - * @return {number} The offset into the node the range starts in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.browserrange.AbstractRange.prototype.getStartOffset = - goog.abstractMethod; - - -/** - * Returns the node the range ends in. - * @return {Node} The element or text node the range ends in. - */ -goog.dom.browserrange.AbstractRange.prototype.getEndNode = - goog.abstractMethod; - - -/** - * Returns the offset into the node the range ends in. - * @return {number} The offset into the node the range ends in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.browserrange.AbstractRange.prototype.getEndOffset = - goog.abstractMethod; - - -/** - * Compares one endpoint of this range with the endpoint of another browser - * native range object. - * @param {Range|TextRange} range The browser native range to compare against. - * @param {goog.dom.RangeEndpoint} thisEndpoint The endpoint of this range - * to compare with. - * @param {goog.dom.RangeEndpoint} otherEndpoint The endpoint of the other - * range to compare with. - * @return {number} 0 if the endpoints are equal, negative if this range - * endpoint comes before the other range endpoint, and positive otherwise. - */ -goog.dom.browserrange.AbstractRange.prototype.compareBrowserRangeEndpoints = - goog.abstractMethod; - - -/** - * Tests if this range contains the given range. - * @param {goog.dom.browserrange.AbstractRange} abstractRange The range to test. - * @param {boolean=} opt_allowPartial If not set or false, the range must be - * entirely contained in the selection for this function to return true. - * @return {boolean} Whether this range contains the given range. - */ -goog.dom.browserrange.AbstractRange.prototype.containsRange = - function(abstractRange, opt_allowPartial) { - // IE sometimes misreports the boundaries for collapsed ranges. So if the - // other range is collapsed, make sure the whole range is contained. This is - // logically equivalent, and works around IE's bug. - var checkPartial = opt_allowPartial && !abstractRange.isCollapsed(); - - var range = abstractRange.getBrowserRange(); - var start = goog.dom.RangeEndpoint.START, end = goog.dom.RangeEndpoint.END; - /** {@preserveTry} */ - try { - if (checkPartial) { - // There are two ways to not overlap. Being before, and being after. - // Before is represented by this.end before range.start: comparison < 0. - // After is represented by this.start after range.end: comparison > 0. - // The below is the negation of not overlapping. - return this.compareBrowserRangeEndpoints(range, end, start) >= 0 && - this.compareBrowserRangeEndpoints(range, start, end) <= 0; - - } else { - // Return true if this range bounds the parameter range from both sides. - return this.compareBrowserRangeEndpoints(range, end, end) >= 0 && - this.compareBrowserRangeEndpoints(range, start, start) <= 0; - } - } catch (e) { - if (!goog.userAgent.IE) { - throw e; - } - // IE sometimes throws exceptions when one range is invalid, i.e. points - // to a node that has been removed from the document. Return false in this - // case. - return false; - } -}; - - -/** - * Tests if this range contains the given node. - * @param {Node} node The node to test. - * @param {boolean=} opt_allowPartial If not set or false, the node must be - * entirely contained in the selection for this function to return true. - * @return {boolean} Whether this range contains the given node. - */ -goog.dom.browserrange.AbstractRange.prototype.containsNode = function(node, - opt_allowPartial) { - return this.containsRange( - goog.dom.browserrange.createRangeFromNodeContents(node), - opt_allowPartial); -}; - - -/** - * Tests if the selection is collapsed - i.e. is just a caret. - * @return {boolean} Whether the range is collapsed. - */ -goog.dom.browserrange.AbstractRange.prototype.isCollapsed = - goog.abstractMethod; - - -/** - * @return {string} The text content of the range. - */ -goog.dom.browserrange.AbstractRange.prototype.getText = - goog.abstractMethod; - - -/** - * Returns the HTML fragment this range selects. This is slow on all browsers. - * @return {string} HTML fragment of the range, does not include context - * containing elements. - */ -goog.dom.browserrange.AbstractRange.prototype.getHtmlFragment = function() { - var output = new goog.string.StringBuffer(); - goog.iter.forEach(this, function(node, ignore, it) { - if (node.nodeType == goog.dom.NodeType.TEXT) { - output.append(goog.string.htmlEscape(node.nodeValue.substring( - it.getStartTextOffset(), it.getEndTextOffset()))); - } else if (node.nodeType == goog.dom.NodeType.ELEMENT) { - if (it.isEndTag()) { - if (goog.dom.canHaveChildren(node)) { - output.append('</' + node.tagName + '>'); - } - } else { - var shallow = node.cloneNode(false); - var html = goog.dom.getOuterHtml(shallow); - if (goog.userAgent.IE && node.tagName == goog.dom.TagName.LI) { - // For an LI, IE just returns "<li>" with no closing tag - output.append(html); - } else { - var index = html.lastIndexOf('<'); - output.append(index ? html.substr(0, index) : html); - } - } - } - }, this); - - return output.toString(); -}; - - -/** - * Returns valid HTML for this range. This is fast on IE, and semi-fast on - * other browsers. - * @return {string} Valid HTML of the range, including context containing - * elements. - */ -goog.dom.browserrange.AbstractRange.prototype.getValidHtml = - goog.abstractMethod; - - -/** - * Returns a RangeIterator over the contents of the range. Regardless of the - * direction of the range, the iterator will move in document order. - * @param {boolean=} opt_keys Unused for this iterator. - * @return {goog.dom.RangeIterator} An iterator over tags in the range. - */ -goog.dom.browserrange.AbstractRange.prototype.__iterator__ = function( - opt_keys) { - return new goog.dom.TextRangeIterator(this.getStartNode(), - this.getStartOffset(), this.getEndNode(), this.getEndOffset()); -}; - - -// SELECTION MODIFICATION - - -/** - * Set this range as the selection in its window. - * @param {boolean=} opt_reverse Whether to select the range in reverse, - * if possible. - */ -goog.dom.browserrange.AbstractRange.prototype.select = - goog.abstractMethod; - - -/** - * Removes the contents of the range from the document. As a side effect, the - * selection will be collapsed. The behavior of content removal is normalized - * across browsers. For instance, IE sometimes creates extra text nodes that - * a W3C browser does not. That behavior is corrected for. - */ -goog.dom.browserrange.AbstractRange.prototype.removeContents = - goog.abstractMethod; - - -/** - * Surrounds the text range with the specified element (on Mozilla) or with a - * clone of the specified element (on IE). Returns a reference to the - * surrounding element if the operation was successful; returns null if the - * operation failed. - * @param {Element} element The element with which the selection is to be - * surrounded. - * @return {Element} The surrounding element (same as the argument on Mozilla, - * but not on IE), or null if unsuccessful. - */ -goog.dom.browserrange.AbstractRange.prototype.surroundContents = - goog.abstractMethod; - - -/** - * Inserts a node before (or after) the range. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Node} node The node to insert. - * @param {boolean} before True to insert before, false to insert after. - * @return {Node} The node added to the document. This may be different - * than the node parameter because on IE we have to clone it. - */ -goog.dom.browserrange.AbstractRange.prototype.insertNode = - goog.abstractMethod; - - -/** - * Surrounds this range with the two given nodes. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Element} startNode The node to insert at the start. - * @param {Element} endNode The node to insert at the end. - */ -goog.dom.browserrange.AbstractRange.prototype.surroundWithNodes = - goog.abstractMethod; - - -/** - * Collapses the range to one of its boundary points. - * @param {boolean} toStart Whether to collapse to the start of the range. - */ -goog.dom.browserrange.AbstractRange.prototype.collapse = - goog.abstractMethod; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange.js.svn-base deleted file mode 100644 index 2c85777..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange.js.svn-base +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the browser range namespace and interface, as - * well as several useful utility functions. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - * - * @supported IE6, IE7, FF1.5+, Safari. - */ - - -goog.provide('goog.dom.browserrange'); -goog.provide('goog.dom.browserrange.Error'); - -goog.require('goog.dom'); -goog.require('goog.dom.browserrange.GeckoRange'); -goog.require('goog.dom.browserrange.IeRange'); -goog.require('goog.dom.browserrange.OperaRange'); -goog.require('goog.dom.browserrange.W3cRange'); -goog.require('goog.dom.browserrange.WebKitRange'); -goog.require('goog.userAgent'); - - -/** - * Common error constants. - * @enum {string} - */ -goog.dom.browserrange.Error = { - NOT_IMPLEMENTED: 'Not Implemented' -}; - - -// NOTE(robbyw): While it would be nice to eliminate the duplicate switches -// below, doing so uncovers bugs in the JsCompiler in which -// necessary code is stripped out. - - -/** - * Static method that returns the proper type of browser range. - * @param {Range|TextRange} range A browser range object. - * @return {goog.dom.browserrange.AbstractRange} A wrapper object. - */ -goog.dom.browserrange.createRange = function(range) { - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - return new goog.dom.browserrange.IeRange( - /** @type {TextRange} */ (range), - goog.dom.getOwnerDocument(range.parentElement())); - } else if (goog.userAgent.WEBKIT) { - return new goog.dom.browserrange.WebKitRange( - /** @type {Range} */ (range)); - } else if (goog.userAgent.GECKO) { - return new goog.dom.browserrange.GeckoRange( - /** @type {Range} */ (range)); - } else if (goog.userAgent.OPERA) { - return new goog.dom.browserrange.OperaRange( - /** @type {Range} */ (range)); - } else { - // Default other browsers, including Opera, to W3c ranges. - return new goog.dom.browserrange.W3cRange( - /** @type {Range} */ (range)); - } -}; - - -/** - * Static method that returns the proper type of browser range. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.AbstractRange} A wrapper object. - */ -goog.dom.browserrange.createRangeFromNodeContents = function(node) { - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - return goog.dom.browserrange.IeRange.createFromNodeContents(node); - } else if (goog.userAgent.WEBKIT) { - return goog.dom.browserrange.WebKitRange.createFromNodeContents(node); - } else if (goog.userAgent.GECKO) { - return goog.dom.browserrange.GeckoRange.createFromNodeContents(node); - } else if (goog.userAgent.OPERA) { - return goog.dom.browserrange.OperaRange.createFromNodeContents(node); - } else { - // Default other browsers to W3c ranges. - return goog.dom.browserrange.W3cRange.createFromNodeContents(node); - } -}; - - -/** - * Static method that returns the proper type of browser range. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. This is - * either the index into the childNodes array for element startNodes or - * the index into the character array for text startNodes. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. This is - * either the index into the childNodes array for element endNodes or - * the index into the character array for text endNodes. - * @return {goog.dom.browserrange.AbstractRange} A wrapper object. - */ -goog.dom.browserrange.createRangeFromNodes = function(startNode, startOffset, - endNode, endOffset) { - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - return goog.dom.browserrange.IeRange.createFromNodes(startNode, startOffset, - endNode, endOffset); - } else if (goog.userAgent.WEBKIT) { - return goog.dom.browserrange.WebKitRange.createFromNodes(startNode, - startOffset, endNode, endOffset); - } else if (goog.userAgent.GECKO) { - return goog.dom.browserrange.GeckoRange.createFromNodes(startNode, - startOffset, endNode, endOffset); - } else if (goog.userAgent.OPERA) { - return goog.dom.browserrange.OperaRange.createFromNodes(startNode, - startOffset, endNode, endOffset); - } else { - // Default other browsers to W3c ranges. - return goog.dom.browserrange.W3cRange.createFromNodes(startNode, - startOffset, endNode, endOffset); - } -}; - - -/** - * Tests whether the given node can contain a range end point. - * @param {Node} node The node to check. - * @return {boolean} Whether the given node can contain a range end point. - */ -goog.dom.browserrange.canContainRangeEndpoint = function(node) { - // NOTE(user, bloom): This is not complete, as divs with style - - // 'display:inline-block' or 'position:absolute' can also not contain range - // endpoints. A more complete check is to see if that element can be partially - // selected (can be container) or not. - return goog.dom.canHaveChildren(node) || - node.nodeType == goog.dom.NodeType.TEXT; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange_test.html.svn-base deleted file mode 100644 index fa0f556..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/browserrange_test.html.svn-base +++ /dev/null @@ -1,638 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.browserrange</title> -<script src="../../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.browserrange'); - goog.require('goog.dom.Range'); - - goog.require('goog.userAgent'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <div id="sandbox"></div> - <div id="test1">Text</div><div id="test2">abc<br id="br">def</div> - <div id="cetest" contentEditable="true"><div>abc<br id="br2"></div></div> - <div id="empty"></div> - <div id="removeTest"><div>Text that<br>will be deleted</div></div> - <div id="removeTestEmptyNode"></div> - <div id="removeTestSingleNode"><div>Text Text</div></div> - <div id="removeTestMidNode"><div>0123456789</div></div> - <div id="removeTestMidMultipleNodes"><div>0123456789</div><div>0123456789</div></div> - <div id="outer">outer<div id="inner">inner</div>outer2</div> - <div id="dynamic"></div> - <div id="onlybr"><br/></div> - -<script> - var test1 = goog.dom.getElement('test1'); - var test2 = goog.dom.getElement('test2'); - var cetest = goog.dom.getElement('cetest'); - var empty = goog.dom.getElement('empty'); - var dynamic = goog.dom.getElement('dynamic'); - var onlybrdiv = goog.dom.getElement('onlybr'); - - - function testCreate() { - assertNotNull('Browser range object can be created for node', - goog.dom.browserrange.createRangeFromNodeContents(test1)); - } - - function testRangeEndPoints() { - var container = cetest.firstChild; - var range = goog.dom.browserrange.createRangeFromNodes( - container, 2, container, 2); - range.select(); - - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - var endNode = selRange.getEndNode(); - var startOffset = selRange.getStartOffset(); - var endOffset = selRange.getEndOffset(); - if (goog.userAgent.WEBKIT) { - assertEquals('Start node should have text: abc', - 'abc', startNode.nodeValue); - assertEquals('End node should have text: abc', 'abc', endNode.nodeValue); - assertEquals('Start offset should be 3', 3, startOffset); - assertEquals('End offset should be 3', 3, endOffset); - } else { - assertEquals('Start node should be the first div', container, startNode); - assertEquals('End node should be the first div', container, endNode); - assertEquals('Start offset should be 2', 2, startOffset); - assertEquals('End offset should be 2', 2, endOffset); - } - } - - function testCreateFromNodeContents() { - var range = goog.dom.Range.createFromNodeContents(onlybrdiv); - goog.testing.dom.assertRangeEquals(onlybrdiv, 0, onlybrdiv, 1, range); - } - - function normalizeHtml(str) { - return str.toLowerCase().replace(/[\n\r\f"]/g, ''); - } - - // TODO(robbyw): We really need tests for (and code fixes for) - // createRangeFromNodes in the following cases: - // * BR boundary (before + after) - - function testCreateFromNodes() { - var start = test1.firstChild; - var range = goog.dom.browserrange.createRangeFromNodes(start, 2, - test2.firstChild, 2); - assertNotNull('Browser range object can be created for W3C node range', - range); - - assertEquals('Start node should be selected at start endpoint', start, - range.getStartNode()); - assertEquals('Selection should start at offset 2', 2, - range.getStartOffset()); - - assertEquals('Text node should be selected at end endpoint', - test2.firstChild, range.getEndNode()); - assertEquals('Selection should end at offset 2', 2, range.getEndOffset()); - - assertTrue('Text content should be "xt\\s*ab"', - /xt\s*ab/.test(range.getText())); - assertFalse('Nodes range is not collapsed', range.isCollapsed()); - assertEquals('Should contain correct html fragment', - 'xt</div><div id=test2>ab', - normalizeHtml(range.getHtmlFragment())); - assertEquals('Should contain correct valid html', - '<div id=test1>xt</div><div id=test2>ab</div>', - normalizeHtml(range.getValidHtml())); - } - - - function testTextNode() { - var range = goog.dom.browserrange.createRangeFromNodeContents( - test1.firstChild); - - assertEquals('Text node should be selected at start endpoint', 'Text', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node should be selected at end endpoint', 'Text', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 4', 'Text'.length, - range.getEndOffset()); - - assertEquals('Container should be text node', goog.dom.NodeType.TEXT, - range.getContainer().nodeType); - - assertEquals('Text content should be "Text"', 'Text', range.getText()); - assertFalse('Text range is not collapsed', range.isCollapsed()); - assertEquals('Should contain correct html fragment', 'Text', - range.getHtmlFragment()); - assertEquals('Should contain correct valid html', - 'Text', range.getValidHtml()); - - } - - function testTextNodes() { - goog.dom.removeChildren(dynamic); - dynamic.appendChild(goog.dom.createTextNode('Part1')); - dynamic.appendChild(goog.dom.createTextNode('Part2')); - var range = goog.dom.browserrange.createRangeFromNodes( - dynamic.firstChild, 0, dynamic.lastChild, 5); - - assertEquals('Text node 1 should be selected at start endpoint', 'Part1', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node 2 should be selected at end endpoint', 'Part2', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 5', 'Part2'.length, - range.getEndOffset()); - - assertEquals('Container should be DIV', goog.dom.TagName.DIV, - range.getContainer().tagName); - - assertEquals('Text content should be "Part1Part2"', 'Part1Part2', - range.getText()); - assertFalse('Text range is not collapsed', range.isCollapsed()); - assertEquals('Should contain correct html fragment', 'Part1Part2', - range.getHtmlFragment()); - assertEquals('Should contain correct valid html', - 'part1part2', - normalizeHtml(range.getValidHtml())); - - } - - function testDiv() { - var range = goog.dom.browserrange.createRangeFromNodeContents(test2); - - assertEquals('Text node "abc" should be selected at start endpoint', 'abc', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node "def" should be selected at end endpoint', 'def', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 3', 'def'.length, - range.getEndOffset()); - - assertEquals('Container should be DIV', 'DIV', - range.getContainer().tagName); - - assertTrue('Div text content should be "abc\\s*def"', - /abc\s*def/.test(range.getText())); - assertEquals('Should contain correct html fragment', 'abc<br id=br>def', - normalizeHtml(range.getHtmlFragment())); - assertEquals('Should contain correct valid html', - '<div id=test2>abc<br id=br>def</div>', - normalizeHtml(range.getValidHtml())); - assertFalse('Div range is not collapsed', range.isCollapsed()); - } - - function testEmptyNodeHtmlInsert() { - var range = goog.dom.browserrange.createRangeFromNodeContents(empty); - var html = '<b>hello</b>'; - range.insertNode(goog.dom.htmlToDocumentFragment(html)); - assertEquals('Html is not inserted correctly', html, - normalizeHtml(empty.innerHTML)); - goog.dom.removeChildren(empty); - } - - function testEmptyNode() { - var range = goog.dom.browserrange.createRangeFromNodeContents(empty); - - assertEquals('DIV be selected at start endpoint', 'DIV', - range.getStartNode().tagName); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('DIV should be selected at end endpoint', 'DIV', - range.getEndNode().tagName); - assertEquals('Selection should end at offset 0', 0, - range.getEndOffset()); - - assertEquals('Container should be DIV', 'DIV', - range.getContainer().tagName); - - assertEquals('Empty text content should be ""', '', range.getText()); - assertTrue('Empty range is collapsed', range.isCollapsed()); - assertEquals('Should contain correct valid html', '<div id=empty></div>', - normalizeHtml(range.getValidHtml())); - assertEquals('Should contain no html fragment', '', - range.getHtmlFragment()); - } - - - function testRemoveContents() { - var outer = goog.dom.getElement('removeTest'); - var range = goog.dom.browserrange.createRangeFromNodeContents( - outer.firstChild); - - range.removeContents(); - - assertEquals('Removed range content should be ""', '', range.getText()); - assertTrue('Removed range is now collapsed', range.isCollapsed()); - assertEquals('Outer div has 1 child now', 1, outer.childNodes.length); - assertEquals('Inner div is empty', 0, outer.firstChild.childNodes.length); - } - - - function testRemoveContentsEmptyNode() { - var outer = goog.dom.getElement('removeTestEmptyNode'); - var range = goog.dom.browserrange.createRangeFromNodeContents( - outer); - - range.removeContents(); - - assertEquals('Removed range content should be ""', '', range.getText()); - assertTrue('Removed range is now collapsed', range.isCollapsed()); - assertEquals('Outer div should have 0 children now', - 0, outer.childNodes.length); - } - - - function testRemoveContentsSingleNode() { - var outer = goog.dom.getElement('removeTestSingleNode'); - var range = goog.dom.browserrange.createRangeFromNodeContents( - outer.firstChild); - - range.removeContents(); - - assertEquals('Removed range content should be ""', '', range.getText()); - assertTrue('Removed range is now collapsed', range.isCollapsed()); - assertEquals('', goog.dom.getTextContent(outer)); - } - - - function testRemoveContentsMidNode() { - var outer = goog.dom.getElement('removeTestMidNode'); - var textNode = outer.firstChild.firstChild; - var range = goog.dom.browserrange.createRangeFromNodes( - textNode, 1, textNode, 4); - - assertEquals('Previous range content should be "123"', '123', - range.getText()); - range.removeContents(); - - assertEquals('Removed range content should be "0456789"', '0456789', - goog.dom.getTextContent(outer)); - } - - - function testRemoveContentsMidMultipleNodes() { - var outer = goog.dom.getElement('removeTestMidMultipleNodes'); - var firstTextNode = outer.firstChild.firstChild; - var lastTextNode = outer.lastChild.firstChild; - var range = goog.dom.browserrange.createRangeFromNodes( - firstTextNode, 1, lastTextNode, 4); - - assertEquals('Previous range content', '1234567890123', - range.getText().replace(/\s/g, '')); - range.removeContents(); - - assertEquals('Removed range content should be "0456789"', '0456789', - goog.dom.getTextContent(outer).replace(/\s/g, '')); - } - - - function testRemoveDivCaretRange() { - var outer = goog.dom.getElement('sandbox'); - outer.innerHTML = '<div>Test1</div><div></div>'; - var range = goog.dom.browserrange.createRangeFromNodes( - outer.lastChild, 0, outer.lastChild, 0); - - range.removeContents(); - range.insertNode(goog.dom.createDom('span', undefined, 'Hello'), true); - - assertEquals('Resulting contents', 'Test1Hello', - goog.dom.getTextContent(outer).replace(/\s/g, '')); - } - - - function testCollapse() { - var range = goog.dom.browserrange.createRangeFromNodeContents(test2); - assertFalse('Div range is not collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Div range is collapsed after call to empty()', - range.isCollapsed()); - - range = goog.dom.browserrange.createRangeFromNodeContents(empty); - assertTrue('Empty range is collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Empty range is still collapsed', range.isCollapsed()); - } - - - function testIdWithSpecialCharacters() { - goog.dom.removeChildren(dynamic); - dynamic.appendChild(goog.dom.createTextNode('1')); - dynamic.appendChild(goog.dom.createDom('div', {id: '<>'})); - dynamic.appendChild(goog.dom.createTextNode('2')); - var range = goog.dom.browserrange.createRangeFromNodes( - dynamic.firstChild, 0, dynamic.lastChild, 1); - - // Difference in special character handling is ok. - assertContains('Should have correct html fragment', - normalizeHtml(range.getHtmlFragment()), - [ - '1<div id=<>></div>2', // IE - '1<div id=<>></div>2', // WebKit - '1<div id=<>></div>2' // Others - ]); - } - - function testEndOfChildren() { - dynamic.innerHTML = - '<span id="a">123<br>456</span><span id="b">text</span>'; - var range = goog.dom.browserrange.createRangeFromNodes( - goog.dom.getElement('a'), 3, goog.dom.getElement('b'), 1); - assertEquals('Should have correct text.', 'text', range.getText()); - } - - function testEndOfDiv() { - dynamic.innerHTML = '<div id="a">abc</div><div id="b">def</div>'; - var a = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes(a, 1, a, 1); - var expectedStartNode = a; - var expectedStartOffset = 1; - var expectedEndNode = a; - var expectedEndOffset = 1; - assertEquals('startNode is wrong', expectedStartNode, range.getStartNode()); - assertEquals('startOffset is wrong', - expectedStartOffset, range.getStartOffset()); - assertEquals('endNode is wrong', expectedEndNode, range.getEndNode()); - assertEquals('endOffset is wrong', expectedEndOffset, range.getEndOffset()); - } - - function testRangeEndingWithBR() { - dynamic.innerHTML = '<span id="a">123<br>456</span>'; - var spanElem = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes( - spanElem, 0, spanElem, 2); - var htmlText = range.getValidHtml().toLowerCase(); - assertContains('Should include BR in HTML.', 'br', htmlText); - assertEquals('Should have correct text.', '123', range.getText()); - - range.select(); - - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Start node should be span', spanElem, startNode); - } else { - assertEquals('Startnode should have text:123', - '123', startNode.nodeValue); - } - assertEquals('Startoffset should be 0', 0, selRange.getStartOffset()); - var endNode = selRange.getEndNode(); - assertEquals('Endnode should be span', spanElem, endNode); - assertEquals('Endoffset should be 2', 2, selRange.getEndOffset()); - } - - function testRangeEndingWithBR2() { - dynamic.innerHTML = '<span id="a">123<br></span>'; - var spanElem = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes( - spanElem, 0, spanElem, 2); - var htmlText = range.getValidHtml().toLowerCase(); - assertContains('Should include BR in HTML.', 'br', htmlText); - assertEquals('Should have correct text.', '123', range.getText()); - - range.select(); - - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Start node should be span', spanElem, startNode); - } else { - assertEquals('Start node should have text:123', - '123', startNode.nodeValue); - } - assertEquals('Startoffset should be 0', 0, selRange.getStartOffset()); - var endNode = selRange.getEndNode(); - if (goog.userAgent.WEBKIT) { - assertEquals('Endnode should have text', '123', endNode.nodeValue); - assertEquals('Endoffset should be 3', 3, selRange.getEndOffset()); - } else { - assertEquals('Endnode should be span', spanElem, endNode); - assertEquals('Endoffset should be 2', 2, selRange.getEndOffset()); - } - } - - function testRangeEndingBeforeBR() { - dynamic.innerHTML = '<span id="a">123<br>456</span>'; - var spanElem = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes( - spanElem, 0, spanElem, 1); - var htmlText = range.getValidHtml().toLowerCase(); - assertNotContains('Should not include BR in HTML.', 'br', htmlText); - assertEquals('Should have correct text.', '123', range.getText()); - range.select(); - - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Start node should be span', spanElem, startNode); - } else { - assertEquals('Startnode should have text:123', - '123', startNode.nodeValue); - } - assertEquals('Startoffset should be 0', 0, selRange.getStartOffset()); - var endNode = selRange.getEndNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Endnode should be span', spanElem, endNode); - assertEquals('Endoffset should be 1', 1, selRange.getEndOffset()); - } else { - assertEquals('Endnode should have text:123', '123', endNode.nodeValue); - assertEquals('Endoffset should be 3', 3, selRange.getEndOffset()); - } - } - - function testRangeStartingWithBR() { - dynamic.innerHTML = '<span id="a">123<br>456</span>'; - var spanElem = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes( - spanElem, 1, spanElem, 3); - var htmlText = range.getValidHtml().toLowerCase(); - assertContains('Should include BR in HTML.', 'br', htmlText); - // Firefox returns '456' as the range text while IE returns '\r\n456'. - // Therefore skipping the text check. - - range.select(); - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - assertEquals('Start node should be span', spanElem, startNode); - assertEquals('Startoffset should be 1', 1, selRange.getStartOffset()); - var endNode = selRange.getEndNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Endnode should be span', spanElem, endNode); - assertEquals('Endoffset should be 3', 3, selRange.getEndOffset()); - } else { - assertEquals('Endnode should have text:456', '456', endNode.nodeValue); - assertEquals('Endoffset should be 3', 3, selRange.getEndOffset()); - } - } - - function testRangeStartingAfterBR() { - dynamic.innerHTML = '<span id="a">123<br>4567</span>'; - var spanElem = goog.dom.getElement('a'); - var range = goog.dom.browserrange.createRangeFromNodes( - spanElem, 2, spanElem, 3); - var htmlText = range.getValidHtml().toLowerCase(); - assertNotContains('Should not include BR in HTML.', 'br', htmlText); - assertEquals('Should have correct text.', '4567', range.getText()); - - range.select(); - - var selRange = goog.dom.Range.createFromWindow(); - var startNode = selRange.getStartNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Start node should be span', spanElem, startNode); - assertEquals('Startoffset should be 2', 2, selRange.getStartOffset()); - } else { - assertEquals('Startnode should have text:4567', - '4567', startNode.nodeValue); - assertEquals('Startoffset should be 0', 0, selRange.getStartOffset()); - } - var endNode = selRange.getEndNode(); - if (goog.userAgent.GECKO || - (goog.userAgent.IE && goog.userAgent.isDocumentMode(9))) { - assertEquals('Endnode should be span', spanElem, endNode); - assertEquals('Endoffset should be 3', 3, selRange.getEndOffset()); - } else { - assertEquals('Endnode should have text:4567', '4567', endNode.nodeValue); - assertEquals('Endoffset should be 4', 4, selRange.getEndOffset()); - } - - } - - function testCollapsedRangeBeforeBR() { - dynamic.innerHTML = '<span id="a">123<br>456</span>'; - var range = goog.dom.browserrange.createRangeFromNodes( - goog.dom.getElement('a'), 1, goog.dom.getElement('a'), 1); - // Firefox returns <span id="a"></span> as the range HTML while IE returns - // empty string. Therefore skipping the HTML check. - assertEquals('Should have no text.', '', range.getText()); - } - - function testCollapsedRangeAfterBR() { - dynamic.innerHTML = '<span id="a">123<br>456</span>'; - var range = goog.dom.browserrange.createRangeFromNodes( - goog.dom.getElement('a'), 2, goog.dom.getElement('a'), 2); - // Firefox returns <span id="a"></span> as the range HTML while IE returns - // empty string. Therefore skipping the HTML check. - assertEquals('Should have no text.', '', range.getText()); - } - - function testCompareBrowserRangeEndpoints() { - var outer = goog.dom.getElement('outer'); - var inner = goog.dom.getElement('inner'); - var range_outer = goog.dom.browserrange.createRangeFromNodeContents(outer); - var range_inner = goog.dom.browserrange.createRangeFromNodeContents(inner); - - assertEquals( - "The start of the inner selection should be after the outer.", - 1, - range_inner.compareBrowserRangeEndpoints( - range_outer.getBrowserRange(), - goog.dom.RangeEndpoint.START, - goog.dom.RangeEndpoint.START)); - - assertEquals( - "The start of the inner selection should be before the outer's end.", - -1, - range_inner.compareBrowserRangeEndpoints( - range_outer.getBrowserRange(), - goog.dom.RangeEndpoint.START, - goog.dom.RangeEndpoint.END)); - - assertEquals( - "The end of the inner selection should be after the outer's start.", - 1, - range_inner.compareBrowserRangeEndpoints( - range_outer.getBrowserRange(), - goog.dom.RangeEndpoint.END, - goog.dom.RangeEndpoint.START)); - - assertEquals( - "The end of the inner selection should be before the outer's end.", - -1, - range_inner.compareBrowserRangeEndpoints( - range_outer.getBrowserRange(), - goog.dom.RangeEndpoint.END, - goog.dom.RangeEndpoint.END)); - - } - - /** - * Regression test for a bug in IeRange.insertNode_ where if the node to be - * inserted was not an element (e.g. a text node), it would clone the node - * in the inserting process but return the original node instead of the newly - * created and inserted node. - */ - function testInsertNodeNonElement() { - dynamic.innerHTML = 'beforeafter'; - var range = goog.dom.browserrange.createRangeFromNodes( - dynamic.firstChild, 6, dynamic.firstChild, 6); - var newNode = goog.dom.createTextNode('INSERTED'); - var inserted = range.insertNode(newNode, false); - - assertEquals('Text should be inserted between "before" and "after"', - 'beforeINSERTEDafter', - goog.dom.getRawTextContent(dynamic)); - assertEquals('Node returned by insertNode() should be a child of the div' + - ' containing the text', - dynamic, - inserted.parentNode) - } - - function testSelectOverwritesOldSelection() { - goog.dom.browserrange.createRangeFromNodes(test1, 0, test1, 1).select(); - goog.dom.browserrange.createRangeFromNodes(test2, 0, test2, 1).select(); - assertEquals('The old selection must be replaced with the new one', - 'abc', goog.dom.Range.createFromWindow().getText()); - } - - // Following testcase is special for IE. The comparison of ranges created in - // testcases with a range over empty span using native inRange fails. So the - // fallback mechanism is needed. - function testGetContainerInTextNodesAroundEmptySpan() { - dynamic.innerHTML = 'abc<span></span>def'; - var abc = dynamic.firstChild; - var def = dynamic.lastChild; - - var range; - range = goog.dom.browserrange.createRangeFromNodes(abc, 1, abc, 1); - assertEquals('textNode abc should be the range container', - abc, range.getContainer()); - assertEquals('textNode abc should be the range start node', - abc, range.getStartNode()); - assertEquals('textNode abc should be the range end node', - abc, range.getEndNode()); - - range = goog.dom.browserrange.createRangeFromNodes(def, 1, def, 1); - assertEquals('textNode def should be the range container', - def, range.getContainer()); - assertEquals('textNode def should be the range start node', - def, range.getStartNode()); - assertEquals('textNode def should be the range end node', - def, range.getEndNode()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/geckorange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/geckorange.js.svn-base deleted file mode 100644 index 5e94b5f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/geckorange.js.svn-base +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the Gecko specific range wrapper. Inherits most - * functionality from W3CRange, but adds exceptions as necessary. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.browserrange.GeckoRange'); - -goog.require('goog.dom.browserrange.W3cRange'); - - - -/** - * The constructor for Gecko specific browser ranges. - * @param {Range} range The range object. - * @constructor - * @extends {goog.dom.browserrange.W3cRange} - */ -goog.dom.browserrange.GeckoRange = function(range) { - goog.dom.browserrange.W3cRange.call(this, range); -}; -goog.inherits(goog.dom.browserrange.GeckoRange, goog.dom.browserrange.W3cRange); - - -/** - * Creates a range object that selects the given node's text. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.GeckoRange} A Gecko range wrapper object. - */ -goog.dom.browserrange.GeckoRange.createFromNodeContents = function(node) { - return new goog.dom.browserrange.GeckoRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node)); -}; - - -/** - * Creates a range object that selects between the given nodes. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @return {goog.dom.browserrange.GeckoRange} A wrapper object. - */ -goog.dom.browserrange.GeckoRange.createFromNodes = function(startNode, - startOffset, endNode, endOffset) { - return new goog.dom.browserrange.GeckoRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(startNode, - startOffset, endNode, endOffset)); -}; - - -/** @override */ -goog.dom.browserrange.GeckoRange.prototype.selectInternal = function( - selection, reversed) { - var anchorNode = reversed ? this.getEndNode() : this.getStartNode(); - var anchorOffset = reversed ? this.getEndOffset() : this.getStartOffset(); - var focusNode = reversed ? this.getStartNode() : this.getEndNode(); - var focusOffset = reversed ? this.getStartOffset() : this.getEndOffset(); - - selection.collapse(anchorNode, anchorOffset); - if (anchorNode != focusNode || anchorOffset != focusOffset) { - selection.extend(focusNode, focusOffset); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/ierange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/ierange.js.svn-base deleted file mode 100644 index bb3fb89..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/ierange.js.svn-base +++ /dev/null @@ -1,954 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the IE browser specific range wrapper. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.browserrange.IeRange'); - -goog.require('goog.array'); -goog.require('goog.debug.Logger'); -goog.require('goog.dom'); -goog.require('goog.dom.NodeIterator'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.RangeEndpoint'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.browserrange.AbstractRange'); -goog.require('goog.iter'); -goog.require('goog.iter.StopIteration'); -goog.require('goog.string'); - - - -/** - * The constructor for IE specific browser ranges. - * @param {TextRange} range The range object. - * @param {Document} doc The document the range exists in. - * @constructor - * @extends {goog.dom.browserrange.AbstractRange} - */ -goog.dom.browserrange.IeRange = function(range, doc) { - /** - * The browser range object this class wraps. - * @type {TextRange} - * @private - */ - this.range_ = range; - - /** - * The document the range exists in. - * @type {Document} - * @private - */ - this.doc_ = doc; -}; -goog.inherits(goog.dom.browserrange.IeRange, - goog.dom.browserrange.AbstractRange); - - -/** - * Logging object. - * @type {goog.debug.Logger} - * @private - */ -goog.dom.browserrange.IeRange.logger_ = - goog.debug.Logger.getLogger('goog.dom.browserrange.IeRange'); - - -/** - * Returns a browser range spanning the given node's contents. - * @param {Node} node The node to select. - * @return {TextRange} A browser range spanning the node's contents. - * @private - */ -goog.dom.browserrange.IeRange.getBrowserRangeForNode_ = function(node) { - var nodeRange = goog.dom.getOwnerDocument(node).body.createTextRange(); - if (node.nodeType == goog.dom.NodeType.ELEMENT) { - // Elements are easy. - nodeRange.moveToElementText(node); - // Note(user) : If there are no child nodes of the element, the - // range.htmlText includes the element's outerHTML. The range created above - // is not collapsed, and should be collapsed explicitly. - // Example : node = <div></div> - // But if the node is sth like <br>, it shouldnt be collapsed. - if (goog.dom.browserrange.canContainRangeEndpoint(node) && - !node.childNodes.length) { - nodeRange.collapse(false); - } - } else { - // Text nodes are hard. - // Compute the offset from the nearest element related position. - var offset = 0; - var sibling = node; - while (sibling = sibling.previousSibling) { - var nodeType = sibling.nodeType; - if (nodeType == goog.dom.NodeType.TEXT) { - offset += sibling.length; - } else if (nodeType == goog.dom.NodeType.ELEMENT) { - // Move to the space after this element. - nodeRange.moveToElementText(sibling); - break; - } - } - - if (!sibling) { - nodeRange.moveToElementText(node.parentNode); - } - - nodeRange.collapse(!sibling); - - if (offset) { - nodeRange.move('character', offset); - } - - nodeRange.moveEnd('character', node.length); - } - - return nodeRange; -}; - - -/** - * Returns a browser range spanning the given nodes. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the start node. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the end node. - * @return {TextRange} A browser range spanning the node's contents. - * @private - */ -goog.dom.browserrange.IeRange.getBrowserRangeForNodes_ = function(startNode, - startOffset, endNode, endOffset) { - // Create a range starting at the correct start position. - var child, collapse = false; - if (startNode.nodeType == goog.dom.NodeType.ELEMENT) { - if (startOffset > startNode.childNodes.length) { - goog.dom.browserrange.IeRange.logger_.severe( - 'Cannot have startOffset > startNode child count'); - } - child = startNode.childNodes[startOffset]; - collapse = !child; - startNode = child || startNode.lastChild || startNode; - startOffset = 0; - } - var leftRange = goog.dom.browserrange.IeRange. - getBrowserRangeForNode_(startNode); - - // This happens only when startNode is a text node. - if (startOffset) { - leftRange.move('character', startOffset); - } - - - // The range movements in IE are still an approximation to the standard W3C - // behavior, and IE has its trickery when it comes to htmlText and text - // properties of the range. So we short-circuit computation whenever we can. - if (startNode == endNode && startOffset == endOffset) { - leftRange.collapse(true); - return leftRange; - } - - // This can happen only when the startNode is an element, and there is no node - // at the given offset. We start at the last point inside the startNode in - // that case. - if (collapse) { - leftRange.collapse(false); - } - - // Create a range that ends at the right position. - collapse = false; - if (endNode.nodeType == goog.dom.NodeType.ELEMENT) { - if (endOffset > endNode.childNodes.length) { - goog.dom.browserrange.IeRange.logger_.severe( - 'Cannot have endOffset > endNode child count'); - } - child = endNode.childNodes[endOffset]; - endNode = child || endNode.lastChild || endNode; - endOffset = 0; - collapse = !child; - } - var rightRange = goog.dom.browserrange.IeRange. - getBrowserRangeForNode_(endNode); - rightRange.collapse(!collapse); - if (endOffset) { - rightRange.moveEnd('character', endOffset); - } - - // Merge and return. - leftRange.setEndPoint('EndToEnd', rightRange); - return leftRange; -}; - - -/** - * Create a range object that selects the given node's text. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.IeRange} An IE range wrapper object. - */ -goog.dom.browserrange.IeRange.createFromNodeContents = function(node) { - var range = new goog.dom.browserrange.IeRange( - goog.dom.browserrange.IeRange.getBrowserRangeForNode_(node), - goog.dom.getOwnerDocument(node)); - - if (!goog.dom.browserrange.canContainRangeEndpoint(node)) { - range.startNode_ = range.endNode_ = range.parentNode_ = node.parentNode; - range.startOffset_ = goog.array.indexOf(range.parentNode_.childNodes, node); - range.endOffset_ = range.startOffset_ + 1; - } else { - // Note(user) : Emulate the behavior of W3CRange - Go to deepest possible - // range containers on both edges. It seems W3CRange did this to match the - // IE behavior, and now it is a circle. Changing W3CRange may break clients - // in all sorts of ways. - var tempNode, leaf = node; - while ((tempNode = leaf.firstChild) && - goog.dom.browserrange.canContainRangeEndpoint(tempNode)) { - leaf = tempNode; - } - range.startNode_ = leaf; - range.startOffset_ = 0; - - leaf = node; - while ((tempNode = leaf.lastChild) && - goog.dom.browserrange.canContainRangeEndpoint(tempNode)) { - leaf = tempNode; - } - range.endNode_ = leaf; - range.endOffset_ = leaf.nodeType == goog.dom.NodeType.ELEMENT ? - leaf.childNodes.length : leaf.length; - range.parentNode_ = node; - } - return range; -}; - - -/** - * Static method that returns the proper type of browser range. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the start node. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the end node. - * @return {goog.dom.browserrange.AbstractRange} A wrapper object. - */ -goog.dom.browserrange.IeRange.createFromNodes = function(startNode, - startOffset, endNode, endOffset) { - var range = new goog.dom.browserrange.IeRange( - goog.dom.browserrange.IeRange.getBrowserRangeForNodes_(startNode, - startOffset, endNode, endOffset), - goog.dom.getOwnerDocument(startNode)); - range.startNode_ = startNode; - range.startOffset_ = startOffset; - range.endNode_ = endNode; - range.endOffset_ = endOffset; - return range; -}; - - -// Even though goog.dom.TextRange does similar caching to below, keeping these -// caches allows for better performance in the get*Offset methods. - - -/** - * Lazy cache of the node containing the entire selection. - * @type {Node} - * @private - */ -goog.dom.browserrange.IeRange.prototype.parentNode_ = null; - - -/** - * Lazy cache of the node containing the start of the selection. - * @type {Node} - * @private - */ -goog.dom.browserrange.IeRange.prototype.startNode_ = null; - - -/** - * Lazy cache of the node containing the end of the selection. - * @type {Node} - * @private - */ -goog.dom.browserrange.IeRange.prototype.endNode_ = null; - - -/** - * Lazy cache of the offset in startNode_ where this range starts. - * @type {number} - * @private - */ -goog.dom.browserrange.IeRange.prototype.startOffset_ = -1; - - -/** - * Lazy cache of the offset in endNode_ where this range ends. - * @type {number} - * @private - */ -goog.dom.browserrange.IeRange.prototype.endOffset_ = -1; - - -/** - * @return {goog.dom.browserrange.IeRange} A clone of this range. - */ -goog.dom.browserrange.IeRange.prototype.clone = function() { - var range = new goog.dom.browserrange.IeRange( - this.range_.duplicate(), this.doc_); - range.parentNode_ = this.parentNode_; - range.startNode_ = this.startNode_; - range.endNode_ = this.endNode_; - return range; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getBrowserRange = function() { - return this.range_; -}; - - -/** - * Clears the cached values for containers. - * @private - */ -goog.dom.browserrange.IeRange.prototype.clearCachedValues_ = function() { - this.parentNode_ = this.startNode_ = this.endNode_ = null; - this.startOffset_ = this.endOffset_ = -1; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getContainer = function() { - if (!this.parentNode_) { - var selectText = this.range_.text; - - // If the selection ends with spaces, we need to remove these to get the - // parent container of only the real contents. This is to get around IE's - // inconsistency where it selects the spaces after a word when you double - // click, but leaves out the spaces during execCommands. - var range = this.range_.duplicate(); - // We can't use goog.string.trimRight, as that will remove other whitespace - // too. - var rightTrimmedSelectText = selectText.replace(/ +$/, ''); - var numSpacesAtEnd = selectText.length - rightTrimmedSelectText.length; - if (numSpacesAtEnd) { - range.moveEnd('character', -numSpacesAtEnd); - } - - // Get the parent node. This should be the end, but alas, it is not. - var parent = range.parentElement(); - - var htmlText = range.htmlText; - var htmlTextLen = goog.string.stripNewlines(htmlText).length; - if (this.isCollapsed() && htmlTextLen > 0) { - return (this.parentNode_ = parent); - } - - // Deal with selection bug where IE thinks one of the selection's children - // is actually the selection's parent. Relies on the assumption that the - // HTML text of the parent container is longer than the length of the - // selection's HTML text. - - // Also note IE will sometimes insert \r and \n whitespace, which should be - // disregarded. Otherwise the loop may run too long and return wrong parent - while (htmlTextLen > goog.string.stripNewlines(parent.outerHTML).length) { - parent = parent.parentNode; - } - - // Deal with IE's selecting the outer tags when you double click - // If the innerText is the same, then we just want the inner node - while (parent.childNodes.length == 1 && - parent.innerText == goog.dom.browserrange.IeRange.getNodeText_( - parent.firstChild)) { - // A container should be an element which can have children or a text - // node. Elements like IMG, BR, etc. can not be containers. - if (!goog.dom.browserrange.canContainRangeEndpoint(parent.firstChild)) { - break; - } - parent = parent.firstChild; - } - - // If the selection is empty, we may need to do extra work to position it - // properly. - if (selectText.length == 0) { - parent = this.findDeepestContainer_(parent); - } - - this.parentNode_ = parent; - } - - return this.parentNode_; -}; - - -/** - * Helper method to find the deepest parent for this range, starting - * the search from {@code node}, which must contain the range. - * @param {Node} node The node to start the search from. - * @return {Node} The deepest parent for this range. - * @private - */ -goog.dom.browserrange.IeRange.prototype.findDeepestContainer_ = function(node) { - var childNodes = node.childNodes; - for (var i = 0, len = childNodes.length; i < len; i++) { - var child = childNodes[i]; - - if (goog.dom.browserrange.canContainRangeEndpoint(child)) { - var childRange = - goog.dom.browserrange.IeRange.getBrowserRangeForNode_(child); - var start = goog.dom.RangeEndpoint.START; - var end = goog.dom.RangeEndpoint.END; - - // There are two types of erratic nodes where the range over node has - // different htmlText than the node's outerHTML. - // Case 1 - A node with magic child. In this case : - // nodeRange.htmlText shows ('<p> </p>), while - // node.outerHTML doesn't show the magic node (<p></p>). - // Case 2 - Empty span. In this case : - // node.outerHTML shows '<span></span>' - // node.htmlText is just empty string ''. - var isChildRangeErratic = (childRange.htmlText != child.outerHTML); - - // Moreover the inRange comparison fails only when the - var isNativeInRangeErratic = this.isCollapsed() && isChildRangeErratic; - - // In case 2 mentioned above, childRange is also collapsed. So we need to - // compare start of this range with both start and end of child range. - var inChildRange = isNativeInRangeErratic ? - (this.compareBrowserRangeEndpoints(childRange, start, start) >= 0 && - this.compareBrowserRangeEndpoints(childRange, start, end) <= 0) : - this.range_.inRange(childRange); - if (inChildRange) { - return this.findDeepestContainer_(child); - } - } - } - - return node; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getStartNode = function() { - if (!this.startNode_) { - this.startNode_ = this.getEndpointNode_(goog.dom.RangeEndpoint.START); - if (this.isCollapsed()) { - this.endNode_ = this.startNode_; - } - } - return this.startNode_; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getStartOffset = function() { - if (this.startOffset_ < 0) { - this.startOffset_ = this.getOffset_(goog.dom.RangeEndpoint.START); - if (this.isCollapsed()) { - this.endOffset_ = this.startOffset_; - } - } - return this.startOffset_; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getEndNode = function() { - if (this.isCollapsed()) { - return this.getStartNode(); - } - if (!this.endNode_) { - this.endNode_ = this.getEndpointNode_(goog.dom.RangeEndpoint.END); - } - return this.endNode_; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getEndOffset = function() { - if (this.isCollapsed()) { - return this.getStartOffset(); - } - if (this.endOffset_ < 0) { - this.endOffset_ = this.getOffset_(goog.dom.RangeEndpoint.END); - if (this.isCollapsed()) { - this.startOffset_ = this.endOffset_; - } - } - return this.endOffset_; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.compareBrowserRangeEndpoints = function( - range, thisEndpoint, otherEndpoint) { - return this.range_.compareEndPoints( - (thisEndpoint == goog.dom.RangeEndpoint.START ? 'Start' : 'End') + - 'To' + - (otherEndpoint == goog.dom.RangeEndpoint.START ? 'Start' : 'End'), - range); -}; - - -/** - * Recurses to find the correct node for the given endpoint. - * @param {goog.dom.RangeEndpoint} endpoint The endpoint to get the node for. - * @param {Node=} opt_node Optional node to start the search from. - * @return {Node} The deepest node containing the endpoint. - * @private - */ -goog.dom.browserrange.IeRange.prototype.getEndpointNode_ = function(endpoint, - opt_node) { - - /** @type {Node} */ - var node = opt_node || this.getContainer(); - - // If we're at a leaf in the DOM, we're done. - if (!node || !node.firstChild) { - return node; - } - - var start = goog.dom.RangeEndpoint.START, end = goog.dom.RangeEndpoint.END; - var isStartEndpoint = endpoint == start; - - // Find the first/last child that overlaps the selection. - // NOTE(user) : One of the children can be the magic node. This - // node will have only nodeType property as valid and accessible. All other - // dom related properties like ownerDocument, parentNode, nextSibling etc - // cause error when accessed. Therefore use the for-loop on childNodes to - // iterate. - for (var j = 0, length = node.childNodes.length; j < length; j++) { - var i = isStartEndpoint ? j : length - j - 1; - var child = node.childNodes[i]; - var childRange; - try { - childRange = goog.dom.browserrange.createRangeFromNodeContents(child); - } catch (e) { - // If the child is the magic node, then the above will throw - // error. The magic node exists only when editing using keyboard, so can - // not add any unit test. - continue; - } - var ieRange = childRange.getBrowserRange(); - - // Case 1 : Finding end points when this range is collapsed. - // Note that in case of collapsed range, getEnd{Node,Offset} call - // getStart{Node,Offset}. - if (this.isCollapsed()) { - // Handle situations where caret is not in a text node. In such cases, - // the adjacent child won't be a valid range endpoint container. - if (!goog.dom.browserrange.canContainRangeEndpoint(child)) { - // The following handles a scenario like <div><BR>[caret]<BR></div>, - // where point should be (div, 1). - if (this.compareBrowserRangeEndpoints(ieRange, start, start) == 0) { - this.startOffset_ = this.endOffset_ = i; - return node; - } - } else if (childRange.containsRange(this)) { - // For collapsed range, we should invert the containsRange check with - // childRange. - return this.getEndpointNode_(endpoint, child); - } - - // Case 2 - The first child encountered to have overlap this range is - // contained entirely in this range. - } else if (this.containsRange(childRange)) { - // If it is an element which can not be a range endpoint container, the - // current child offset can be used to deduce the endpoint offset. - if (!goog.dom.browserrange.canContainRangeEndpoint(child)) { - - // Container can't be any deeper, so current node is the container. - if (isStartEndpoint) { - this.startOffset_ = i; - } else { - this.endOffset_ = i + 1; - } - return node; - } - - // If child can contain range endpoints, recurse inside this child. - return this.getEndpointNode_(endpoint, child); - - // Case 3 - Partial non-adjacency overlap. - } else if (this.compareBrowserRangeEndpoints(ieRange, start, end) < 0 && - this.compareBrowserRangeEndpoints(ieRange, end, start) > 0) { - // If this child overlaps the selection partially, recurse down to find - // the first/last child the next level down that overlaps the selection - // completely. We do not consider edge-adjacency (== 0) as overlap. - return this.getEndpointNode_(endpoint, child); - } - - } - - // None of the children of this node overlapped the selection, that means - // the selection starts/ends in this node directly. - return node; -}; - - -/** - * Compares one endpoint of this range with the endpoint of a node. - * For internal methods, we should prefer this method to containsNode. - * containsNode has a lot of false negatives when we're dealing with - * {@code <br>} tags. - * - * @param {Node} node The node to compare against. - * @param {goog.dom.RangeEndpoint} thisEndpoint The endpoint of this range - * to compare with. - * @param {goog.dom.RangeEndpoint} otherEndpoint The endpoint of the node - * to compare with. - * @return {number} 0 if the endpoints are equal, negative if this range - * endpoint comes before the other node endpoint, and positive otherwise. - * @private - */ -goog.dom.browserrange.IeRange.prototype.compareNodeEndpoints_ = - function(node, thisEndpoint, otherEndpoint) { - return this.range_.compareEndPoints( - (thisEndpoint == goog.dom.RangeEndpoint.START ? 'Start' : 'End') + - 'To' + - (otherEndpoint == goog.dom.RangeEndpoint.START ? 'Start' : 'End'), - goog.dom.browserrange.createRangeFromNodeContents(node). - getBrowserRange()); -}; - - -/** - * Returns the offset into the start/end container. - * @param {goog.dom.RangeEndpoint} endpoint The endpoint to get the offset for. - * @param {Node=} opt_container The container to get the offset relative to. - * Defaults to the value returned by getStartNode/getEndNode. - * @return {number} The offset. - * @private - */ -goog.dom.browserrange.IeRange.prototype.getOffset_ = function(endpoint, - opt_container) { - var isStartEndpoint = endpoint == goog.dom.RangeEndpoint.START; - var container = opt_container || - (isStartEndpoint ? this.getStartNode() : this.getEndNode()); - - if (container.nodeType == goog.dom.NodeType.ELEMENT) { - // Find the first/last child that overlaps the selection - var children = container.childNodes; - var len = children.length; - var edge = isStartEndpoint ? 0 : len - 1; - var sign = isStartEndpoint ? 1 : - 1; - - // We find the index in the child array of the endpoint of the selection. - for (var i = edge; i >= 0 && i < len; i += sign) { - var child = children[i]; - // Ignore the child nodes, which could be end point containers. - if (goog.dom.browserrange.canContainRangeEndpoint(child)) { - continue; - } - // Stop looping when we reach the edge of the selection. - var endPointCompare = - this.compareNodeEndpoints_(child, endpoint, endpoint); - if (endPointCompare == 0) { - return isStartEndpoint ? i : i + 1; - } - } - - // When starting from the end in an empty container, we erroneously return - // -1: fix this to return 0. - return i == -1 ? 0 : i; - } else { - // Get a temporary range object. - var range = this.range_.duplicate(); - - // Create a range that selects the entire container. - var nodeRange = goog.dom.browserrange.IeRange.getBrowserRangeForNode_( - container); - - // Now, intersect our range with the container range - this should give us - // the part of our selection that is in the container. - range.setEndPoint(isStartEndpoint ? 'EndToEnd' : 'StartToStart', nodeRange); - - var rangeLength = range.text.length; - return isStartEndpoint ? container.length - rangeLength : rangeLength; - } -}; - - -/** - * Returns the text of the given node. Uses IE specific properties. - * @param {Node} node The node to retrieve the text of. - * @return {string} The node's text. - * @private - */ -goog.dom.browserrange.IeRange.getNodeText_ = function(node) { - return node.nodeType == goog.dom.NodeType.TEXT ? - node.nodeValue : node.innerText; -}; - - -/** - * Tests whether this range is valid (i.e. whether its endpoints are still in - * the document). A range becomes invalid when, after this object was created, - * either one or both of its endpoints are removed from the document. Use of - * an invalid range can lead to runtime errors, particularly in IE. - * @return {boolean} Whether the range is valid. - */ -goog.dom.browserrange.IeRange.prototype.isRangeInDocument = function() { - var range = this.doc_.body.createTextRange(); - range.moveToElementText(this.doc_.body); - - return this.containsRange( - new goog.dom.browserrange.IeRange(range, this.doc_), true); -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.isCollapsed = function() { - // Note(user) : The earlier implementation used (range.text == ''), but this - // fails when (range.htmlText == '<br>') - // Alternative: this.range_.htmlText == ''; - return this.range_.compareEndPoints('StartToEnd', this.range_) == 0; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getText = function() { - return this.range_.text; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.getValidHtml = function() { - return this.range_.htmlText; -}; - - -// SELECTION MODIFICATION - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.select = function(opt_reverse) { - // IE doesn't support programmatic reversed selections. - this.range_.select(); -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.removeContents = function() { - // NOTE: Sometimes htmlText is non-empty, but the range is actually empty. - // TODO(gboyer): The htmlText check is probably unnecessary, but I left it in - // for paranoia. - if (!this.isCollapsed() && this.range_.htmlText) { - // Store some before-removal state. - var startNode = this.getStartNode(); - var endNode = this.getEndNode(); - var oldText = this.range_.text; - - // IE sometimes deletes nodes unrelated to the selection. This trick fixes - // that problem most of the time. Even though it looks like a no-op, it is - // somehow changing IE's internal state such that empty unrelated nodes are - // no longer deleted. - var clone = this.range_.duplicate(); - clone.moveStart('character', 1); - clone.moveStart('character', -1); - - // However, sometimes moving the start back and forth ends up changing the - // range. - // TODO(gboyer): This condition used to happen for empty ranges, but (1) - // never worked, and (2) the isCollapsed call should protect against empty - // ranges better than before. However, this is left for paranoia. - if (clone.text == oldText) { - this.range_ = clone; - } - - // Use the browser's native deletion code. - this.range_.text = ''; - this.clearCachedValues_(); - - // Unfortunately, when deleting a portion of a single text node, IE creates - // an extra text node unlike other browsers which just change the text in - // the node. We normalize for that behavior here, making IE behave like all - // the other browsers. - var newStartNode = this.getStartNode(); - var newStartOffset = this.getStartOffset(); - /** @preserveTry */ - try { - var sibling = startNode.nextSibling; - if (startNode == endNode && startNode.parentNode && - startNode.nodeType == goog.dom.NodeType.TEXT && - sibling && sibling.nodeType == goog.dom.NodeType.TEXT) { - startNode.nodeValue += sibling.nodeValue; - goog.dom.removeNode(sibling); - - // Make sure to reselect the appropriate position. - this.range_ = goog.dom.browserrange.IeRange.getBrowserRangeForNode_( - newStartNode); - this.range_.move('character', newStartOffset); - this.clearCachedValues_(); - } - } catch (e) { - // IE throws errors on orphaned nodes. - } - } -}; - - -/** - * @param {TextRange} range The range to get a dom helper for. - * @return {goog.dom.DomHelper} A dom helper for the document the range - * resides in. - * @private - */ -goog.dom.browserrange.IeRange.getDomHelper_ = function(range) { - return goog.dom.getDomHelper(range.parentElement()); -}; - - -/** - * Pastes the given element into the given range, returning the resulting - * element. - * @param {TextRange} range The range to paste into. - * @param {Element} element The node to insert a copy of. - * @param {goog.dom.DomHelper=} opt_domHelper DOM helper object for the document - * the range resides in. - * @return {Element} The resulting copy of element. - * @private - */ -goog.dom.browserrange.IeRange.pasteElement_ = function(range, element, - opt_domHelper) { - opt_domHelper = opt_domHelper || goog.dom.browserrange.IeRange.getDomHelper_( - range); - - // Make sure the node has a unique id. - var id; - var originalId = id = element.id; - if (!id) { - id = element.id = goog.string.createUniqueString(); - } - - // Insert (a clone of) the node. - range.pasteHTML(element.outerHTML); - - // Pasting the outerHTML of the modified element into the document creates - // a clone of the element argument. We want to return a reference to the - // clone, not the original. However we need to remove the temporary ID - // first. - element = opt_domHelper.getElement(id); - - // If element is null here, we failed. - if (element) { - if (!originalId) { - element.removeAttribute('id'); - } - } - - return element; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.surroundContents = function(element) { - // Make sure the element is detached from the document. - goog.dom.removeNode(element); - - // IE more or less guarantees that range.htmlText is well-formed & valid. - element.innerHTML = this.range_.htmlText; - element = goog.dom.browserrange.IeRange.pasteElement_(this.range_, element); - - // If element is null here, we failed. - if (element) { - this.range_.moveToElementText(element); - } - - this.clearCachedValues_(); - - return element; -}; - - -/** - * Internal handler for inserting a node. - * @param {TextRange} clone A clone of this range's browser range object. - * @param {Node} node The node to insert. - * @param {boolean} before Whether to insert the node before or after the range. - * @param {goog.dom.DomHelper=} opt_domHelper The dom helper to use. - * @return {Node} The resulting copy of node. - * @private - */ -goog.dom.browserrange.IeRange.insertNode_ = function(clone, node, - before, opt_domHelper) { - // Get a DOM helper. - opt_domHelper = opt_domHelper || goog.dom.browserrange.IeRange.getDomHelper_( - clone); - - // If it's not an element, wrap it in one. - var isNonElement; - if (node.nodeType != goog.dom.NodeType.ELEMENT) { - isNonElement = true; - node = opt_domHelper.createDom(goog.dom.TagName.DIV, null, node); - } - - clone.collapse(before); - node = goog.dom.browserrange.IeRange.pasteElement_(clone, - /** @type {Element} */ (node), opt_domHelper); - - // If we didn't want an element, unwrap the element and return the node. - if (isNonElement) { - // pasteElement_() may have returned a copy of the wrapper div, and the - // node it wraps could also be a new copy. So we must extract that new - // node from the new wrapper. - var newNonElement = node.firstChild; - opt_domHelper.flattenElement(node); - node = newNonElement; - } - - return node; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.insertNode = function(node, before) { - var output = goog.dom.browserrange.IeRange.insertNode_( - this.range_.duplicate(), node, before); - this.clearCachedValues_(); - return output; -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.surroundWithNodes = function( - startNode, endNode) { - var clone1 = this.range_.duplicate(); - var clone2 = this.range_.duplicate(); - goog.dom.browserrange.IeRange.insertNode_(clone1, startNode, true); - goog.dom.browserrange.IeRange.insertNode_(clone2, endNode, false); - - this.clearCachedValues_(); -}; - - -/** @override */ -goog.dom.browserrange.IeRange.prototype.collapse = function(toStart) { - this.range_.collapse(toStart); - - if (toStart) { - this.endNode_ = this.startNode_; - this.endOffset_ = this.startOffset_; - } else { - this.startNode_ = this.endNode_; - this.startOffset_ = this.endOffset_; - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/operarange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/operarange.js.svn-base deleted file mode 100644 index 321c9e2..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/operarange.js.svn-base +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the Opera specific range wrapper. Inherits most - * functionality from W3CRange, but adds exceptions as necessary. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - */ - - -goog.provide('goog.dom.browserrange.OperaRange'); - -goog.require('goog.dom.browserrange.W3cRange'); - - - -/** - * The constructor for Opera specific browser ranges. - * @param {Range} range The range object. - * @constructor - * @extends {goog.dom.browserrange.W3cRange} - */ -goog.dom.browserrange.OperaRange = function(range) { - goog.dom.browserrange.W3cRange.call(this, range); -}; -goog.inherits(goog.dom.browserrange.OperaRange, goog.dom.browserrange.W3cRange); - - -/** - * Creates a range object that selects the given node's text. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.OperaRange} A Opera range wrapper object. - */ -goog.dom.browserrange.OperaRange.createFromNodeContents = function(node) { - return new goog.dom.browserrange.OperaRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node)); -}; - - -/** - * Creates a range object that selects between the given nodes. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @return {goog.dom.browserrange.OperaRange} A wrapper object. - */ -goog.dom.browserrange.OperaRange.createFromNodes = function(startNode, - startOffset, endNode, endOffset) { - return new goog.dom.browserrange.OperaRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(startNode, - startOffset, endNode, endOffset)); -}; - - -/** @override */ -goog.dom.browserrange.OperaRange.prototype.selectInternal = function( - selection, reversed) { - // Avoid using addRange as we have to removeAllRanges first, which - // blurs editable fields in Opera. - selection.collapse(this.getStartNode(), this.getStartOffset()); - if (this.getEndNode() != this.getStartNode() || - this.getEndOffset() != this.getStartOffset()) { - selection.extend(this.getEndNode(), this.getEndOffset()); - } - // This can happen if the range isn't in an editable field. - if (selection.rangeCount == 0) { - selection.addRange(this.range_); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/w3crange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/w3crange.js.svn-base deleted file mode 100644 index 71b189b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/w3crange.js.svn-base +++ /dev/null @@ -1,364 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the W3C spec following range wrapper. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.browserrange.W3cRange'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.RangeEndpoint'); -goog.require('goog.dom.browserrange.AbstractRange'); -goog.require('goog.string'); - - - -/** - * The constructor for W3C specific browser ranges. - * @param {Range} range The range object. - * @constructor - * @extends {goog.dom.browserrange.AbstractRange} - */ -goog.dom.browserrange.W3cRange = function(range) { - this.range_ = range; -}; -goog.inherits(goog.dom.browserrange.W3cRange, - goog.dom.browserrange.AbstractRange); - - -/** - * Returns a browser range spanning the given node's contents. - * @param {Node} node The node to select. - * @return {Range} A browser range spanning the node's contents. - * @protected - */ -goog.dom.browserrange.W3cRange.getBrowserRangeForNode = function(node) { - var nodeRange = goog.dom.getOwnerDocument(node).createRange(); - - if (node.nodeType == goog.dom.NodeType.TEXT) { - nodeRange.setStart(node, 0); - nodeRange.setEnd(node, node.length); - } else { - if (!goog.dom.browserrange.canContainRangeEndpoint(node)) { - var rangeParent = node.parentNode; - var rangeStartOffset = goog.array.indexOf(rangeParent.childNodes, node); - nodeRange.setStart(rangeParent, rangeStartOffset); - nodeRange.setEnd(rangeParent, rangeStartOffset + 1); - } else { - var tempNode, leaf = node; - while ((tempNode = leaf.firstChild) && - goog.dom.browserrange.canContainRangeEndpoint(tempNode)) { - leaf = tempNode; - } - nodeRange.setStart(leaf, 0); - - leaf = node; - while ((tempNode = leaf.lastChild) && - goog.dom.browserrange.canContainRangeEndpoint(tempNode)) { - leaf = tempNode; - } - nodeRange.setEnd(leaf, leaf.nodeType == goog.dom.NodeType.ELEMENT ? - leaf.childNodes.length : leaf.length); - } - } - - return nodeRange; -}; - - -/** - * Returns a browser range spanning the given nodes. - * @param {Node} startNode The node to start with - should not be a BR. - * @param {number} startOffset The offset within the start node. - * @param {Node} endNode The node to end with - should not be a BR. - * @param {number} endOffset The offset within the end node. - * @return {Range} A browser range spanning the node's contents. - * @protected - */ -goog.dom.browserrange.W3cRange.getBrowserRangeForNodes = function(startNode, - startOffset, endNode, endOffset) { - // Create and return the range. - var nodeRange = goog.dom.getOwnerDocument(startNode).createRange(); - nodeRange.setStart(startNode, startOffset); - nodeRange.setEnd(endNode, endOffset); - return nodeRange; -}; - - -/** - * Creates a range object that selects the given node's text. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.W3cRange} A Gecko range wrapper object. - */ -goog.dom.browserrange.W3cRange.createFromNodeContents = function(node) { - return new goog.dom.browserrange.W3cRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node)); -}; - - -/** - * Creates a range object that selects between the given nodes. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the start node. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the end node. - * @return {goog.dom.browserrange.W3cRange} A wrapper object. - */ -goog.dom.browserrange.W3cRange.createFromNodes = function(startNode, - startOffset, endNode, endOffset) { - return new goog.dom.browserrange.W3cRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(startNode, - startOffset, endNode, endOffset)); -}; - - -/** - * @return {goog.dom.browserrange.W3cRange} A clone of this range. - */ -goog.dom.browserrange.W3cRange.prototype.clone = function() { - return new this.constructor(this.range_.cloneRange()); -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getBrowserRange = function() { - return this.range_; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getContainer = function() { - return this.range_.commonAncestorContainer; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getStartNode = function() { - return this.range_.startContainer; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getStartOffset = function() { - return this.range_.startOffset; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getEndNode = function() { - return this.range_.endContainer; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getEndOffset = function() { - return this.range_.endOffset; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.compareBrowserRangeEndpoints = - function(range, thisEndpoint, otherEndpoint) { - return this.range_.compareBoundaryPoints( - otherEndpoint == goog.dom.RangeEndpoint.START ? - (thisEndpoint == goog.dom.RangeEndpoint.START ? - goog.global['Range'].START_TO_START : - goog.global['Range'].START_TO_END) : - (thisEndpoint == goog.dom.RangeEndpoint.START ? - goog.global['Range'].END_TO_START : - goog.global['Range'].END_TO_END), - /** @type {Range} */ (range)); -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.isCollapsed = function() { - return this.range_.collapsed; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getText = function() { - return this.range_.toString(); -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.getValidHtml = function() { - var div = goog.dom.getDomHelper(this.range_.startContainer).createDom('div'); - div.appendChild(this.range_.cloneContents()); - var result = div.innerHTML; - - if (goog.string.startsWith(result, '<') || - !this.isCollapsed() && !goog.string.contains(result, '<')) { - // We attempt to mimic IE, which returns no containing element when a - // only text nodes are selected, does return the containing element when - // the selection is empty, and does return the element when multiple nodes - // are selected. - return result; - } - - var container = this.getContainer(); - container = container.nodeType == goog.dom.NodeType.ELEMENT ? container : - container.parentNode; - - var html = goog.dom.getOuterHtml( - /** @type {Element} */ (container.cloneNode(false))); - return html.replace('>', '>' + result); -}; - - -// SELECTION MODIFICATION - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.select = function(reverse) { - var win = goog.dom.getWindow(goog.dom.getOwnerDocument(this.getStartNode())); - this.selectInternal(win.getSelection(), reverse); -}; - - -/** - * Select this range. - * @param {Selection} selection Browser selection object. - * @param {*} reverse Whether to select this range in reverse. - * @protected - */ -goog.dom.browserrange.W3cRange.prototype.selectInternal = function(selection, - reverse) { - // Browser-specific tricks are needed to create reversed selections - // programatically. For this generic W3C codepath, ignore the reverse - // parameter. - selection.removeAllRanges(); - selection.addRange(this.range_); -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.removeContents = function() { - var range = this.range_; - range.extractContents(); - - if (range.startContainer.hasChildNodes()) { - // Remove any now empty nodes surrounding the extracted contents. - var rangeStartContainer = - range.startContainer.childNodes[range.startOffset]; - if (rangeStartContainer) { - var rangePrevious = rangeStartContainer.previousSibling; - - if (goog.dom.getRawTextContent(rangeStartContainer) == '') { - goog.dom.removeNode(rangeStartContainer); - } - - if (rangePrevious && goog.dom.getRawTextContent(rangePrevious) == '') { - goog.dom.removeNode(rangePrevious); - } - } - } -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.surroundContents = function(element) { - this.range_.surroundContents(element); - return element; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.insertNode = function(node, before) { - var range = this.range_.cloneRange(); - range.collapse(before); - range.insertNode(node); - range.detach(); - - return node; -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.surroundWithNodes = function( - startNode, endNode) { - var win = goog.dom.getWindow( - goog.dom.getOwnerDocument(this.getStartNode())); - var selectionRange = goog.dom.Range.createFromWindow(win); - if (selectionRange) { - var sNode = selectionRange.getStartNode(); - var eNode = selectionRange.getEndNode(); - var sOffset = selectionRange.getStartOffset(); - var eOffset = selectionRange.getEndOffset(); - } - - var clone1 = this.range_.cloneRange(); - var clone2 = this.range_.cloneRange(); - - clone1.collapse(false); - clone2.collapse(true); - - clone1.insertNode(endNode); - clone2.insertNode(startNode); - - clone1.detach(); - clone2.detach(); - - if (selectionRange) { - // There are 4 ways that surroundWithNodes can wreck the saved - // selection object. All of them happen when an inserted node splits - // a text node, and one of the end points of the selection was in the - // latter half of that text node. - // - // Clients of this library should use saveUsingCarets to avoid this - // problem. Unfortunately, saveUsingCarets uses this method, so that's - // not really an option for us. :( We just recompute the offsets. - var isInsertedNode = function(n) { - return n == startNode || n == endNode; - }; - if (sNode.nodeType == goog.dom.NodeType.TEXT) { - while (sOffset > sNode.length) { - sOffset -= sNode.length; - do { - sNode = sNode.nextSibling; - } while (isInsertedNode(sNode)); - } - } - - if (eNode.nodeType == goog.dom.NodeType.TEXT) { - while (eOffset > eNode.length) { - eOffset -= eNode.length; - do { - eNode = eNode.nextSibling; - } while (isInsertedNode(eNode)); - } - } - - goog.dom.Range.createFromNodes( - sNode, /** @type {number} */ (sOffset), - eNode, /** @type {number} */ (eOffset)).select(); - } -}; - - -/** @override */ -goog.dom.browserrange.W3cRange.prototype.collapse = function(toStart) { - this.range_.collapse(toStart); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/webkitrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/webkitrange.js.svn-base deleted file mode 100644 index acb00a0..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/.svn/text-base/webkitrange.js.svn-base +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Definition of the WebKit specific range wrapper. Inherits most - * functionality from W3CRange, but adds exceptions as necessary. - * - * DO NOT USE THIS FILE DIRECTLY. Use goog.dom.Range instead. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.browserrange.WebKitRange'); - -goog.require('goog.dom.RangeEndpoint'); -goog.require('goog.dom.browserrange.W3cRange'); -goog.require('goog.userAgent'); - - - -/** - * The constructor for WebKit specific browser ranges. - * @param {Range} range The range object. - * @constructor - * @extends {goog.dom.browserrange.W3cRange} - */ -goog.dom.browserrange.WebKitRange = function(range) { - goog.dom.browserrange.W3cRange.call(this, range); -}; -goog.inherits(goog.dom.browserrange.WebKitRange, - goog.dom.browserrange.W3cRange); - - -/** - * Creates a range object that selects the given node's text. - * @param {Node} node The node to select. - * @return {goog.dom.browserrange.WebKitRange} A WebKit range wrapper object. - */ -goog.dom.browserrange.WebKitRange.createFromNodeContents = function(node) { - return new goog.dom.browserrange.WebKitRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNode(node)); -}; - - -/** - * Creates a range object that selects between the given nodes. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the start node. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the end node. - * @return {goog.dom.browserrange.WebKitRange} A wrapper object. - */ -goog.dom.browserrange.WebKitRange.createFromNodes = function(startNode, - startOffset, endNode, endOffset) { - return new goog.dom.browserrange.WebKitRange( - goog.dom.browserrange.W3cRange.getBrowserRangeForNodes(startNode, - startOffset, endNode, endOffset)); -}; - - -/** @override */ -goog.dom.browserrange.WebKitRange.prototype.compareBrowserRangeEndpoints = - function(range, thisEndpoint, otherEndpoint) { - // Webkit pre-528 has some bugs where compareBoundaryPoints() doesn't work the - // way it is supposed to, but if we reverse the sense of two comparisons, - // it works fine. - // https://bugs.webkit.org/show_bug.cgi?id=20738 - if (goog.userAgent.isVersion('528')) { - return (goog.dom.browserrange.WebKitRange.superClass_. - compareBrowserRangeEndpoints.call( - this, range, thisEndpoint, otherEndpoint)); - } - return this.range_.compareBoundaryPoints( - otherEndpoint == goog.dom.RangeEndpoint.START ? - (thisEndpoint == goog.dom.RangeEndpoint.START ? - goog.global['Range'].START_TO_START : - goog.global['Range'].END_TO_START) : // Sense reversed - (thisEndpoint == goog.dom.RangeEndpoint.START ? - goog.global['Range'].START_TO_END : // Sense reversed - goog.global['Range'].END_TO_END), - /** @type {Range} */ (range)); -}; - - -/** @override */ -goog.dom.browserrange.WebKitRange.prototype.selectInternal = function( - selection, reversed) { - // Unselect everything. This addresses a bug in Webkit where it sometimes - // caches the old selection. - // https://bugs.webkit.org/show_bug.cgi?id=20117 - selection.removeAllRanges(); - - if (reversed) { - selection.setBaseAndExtent(this.getEndNode(), this.getEndOffset(), - this.getStartNode(), this.getStartOffset()); - } else { - selection.setBaseAndExtent(this.getStartNode(), this.getStartOffset(), - this.getEndNode(), this.getEndOffset()); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/geckorange.js b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/geckorange.js index 5e94b5f..c1d78d0 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/geckorange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/geckorange.js @@ -70,13 +70,17 @@ goog.dom.browserrange.GeckoRange.createFromNodes = function(startNode, /** @override */ goog.dom.browserrange.GeckoRange.prototype.selectInternal = function( selection, reversed) { - var anchorNode = reversed ? this.getEndNode() : this.getStartNode(); - var anchorOffset = reversed ? this.getEndOffset() : this.getStartOffset(); - var focusNode = reversed ? this.getStartNode() : this.getEndNode(); - var focusOffset = reversed ? this.getStartOffset() : this.getEndOffset(); - - selection.collapse(anchorNode, anchorOffset); - if (anchorNode != focusNode || anchorOffset != focusOffset) { - selection.extend(focusNode, focusOffset); + if (!reversed || this.isCollapsed()) { + // The base implementation for select() is more robust, and works fine for + // collapsed and forward ranges. This works around + // https://bugzilla.mozilla.org/show_bug.cgi?id=773137, and is tested by + // range_test.html's testFocusedElementDisappears. + goog.base(this, 'selectInternal', selection, reversed); + } else { + // Reversed selection -- start with a caret on the end node, and extend it + // back to the start. Unfortunately, collapse() fails when focus is + // invalid. + selection.collapse(this.getEndNode(), this.getEndOffset()); + selection.extend(this.getStartNode(), this.getStartOffset()); } }; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/ierange.js b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/ierange.js index bb3fb89..1693c38 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/ierange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/ierange.js @@ -308,6 +308,7 @@ goog.dom.browserrange.IeRange.prototype.endOffset_ = -1; /** * @return {goog.dom.browserrange.IeRange} A clone of this range. + * @override */ goog.dom.browserrange.IeRange.prototype.clone = function() { var range = new goog.dom.browserrange.IeRange( diff --git a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/w3crange.js b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/w3crange.js index 71b189b..dc20549 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/browserrange/w3crange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/browserrange/w3crange.js @@ -134,6 +134,7 @@ goog.dom.browserrange.W3cRange.createFromNodes = function(startNode, /** * @return {goog.dom.browserrange.W3cRange} A clone of this range. + * @override */ goog.dom.browserrange.W3cRange.prototype.clone = function() { return new this.constructor(this.range_.cloneRange()); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor.js b/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor.js new file mode 100644 index 0000000..ac29f26 --- /dev/null +++ b/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor.js @@ -0,0 +1,211 @@ +// Copyright 2012 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview A viewport size monitor that buffers RESIZE events until the + * window size has stopped changing, within a specified period of time. For + * every RESIZE event dispatched, this will dispatch up to two *additional* + * events: + * - {@link #EventType.RESIZE_WIDTH} if the viewport's width has changed since + * the last buffered dispatch. + * - {@link #EventType.RESIZE_HEIGHT} if the viewport's height has changed since + * the last buffered dispatch. + * You likely only need to listen to one of the three events. But if you need + * more, just be cautious of duplicating effort. + * + */ + +goog.provide('goog.dom.BufferedViewportSizeMonitor'); + +goog.require('goog.async.Delay'); +goog.require('goog.events'); +goog.require('goog.events.EventTarget'); +goog.require('goog.events.EventType'); +goog.require('goog.math.Size'); + + + +/** + * Creates a new BufferedViewportSizeMonitor. + * @param {!goog.dom.ViewportSizeMonitor} viewportSizeMonitor The + * underlying viewport size monitor. + * @param {number=} opt_bufferMs The buffer time, in ms. If not specified, this + * value defaults to {@link #RESIZE_EVENT_DELAY_MS_}. + * @constructor + * @extends {goog.events.EventTarget} + */ +goog.dom.BufferedViewportSizeMonitor = function( + viewportSizeMonitor, opt_bufferMs) { + goog.base(this); + + /** + * The underlying viewport size monitor. + * @type {goog.dom.ViewportSizeMonitor} + * @private + */ + this.viewportSizeMonitor_ = viewportSizeMonitor; + + /** + * The current size of the viewport. + * @type {goog.math.Size} + * @private + */ + this.currentSize_ = this.viewportSizeMonitor_.getSize(); + + /** + * The previously recorded size of the viewport. + * @type {goog.math.Size} + * @private + */ + this.previousSize_ = this.currentSize_; + + /** + * The resize buffer time in ms. + * @type {number} + * @private + */ + this.resizeBufferMs_ = opt_bufferMs || + goog.dom.BufferedViewportSizeMonitor.RESIZE_EVENT_DELAY_MS_; + + goog.events.listen( + this.viewportSizeMonitor_, + goog.events.EventType.RESIZE, + this.handleResize_, + false /* opt_capture */, + this); +}; +goog.inherits(goog.dom.BufferedViewportSizeMonitor, goog.events.EventTarget); + + +/** + * Additional events to dispatch. + * @enum {string} + */ +goog.dom.BufferedViewportSizeMonitor.EventType = { + RESIZE_HEIGHT: goog.events.getUniqueId('rh'), + RESIZE_WIDTH: goog.events.getUniqueId('rw') +}; + + +/** + * Delay for the resize event. + * @type {goog.async.Delay} + * @private + */ +goog.dom.BufferedViewportSizeMonitor.prototype.resizeDelay_; + + +/** + * Whether the monitoring has been paused. + * @type {boolean} + * @private + */ +goog.dom.BufferedViewportSizeMonitor.prototype.paused_; + + +/** + * Default number of milliseconds to wait after a resize event to relayout the + * page. + * @type {number} + * @const + * @private + */ +goog.dom.BufferedViewportSizeMonitor.RESIZE_EVENT_DELAY_MS_ = 100; + + +/** @override */ +goog.dom.BufferedViewportSizeMonitor.prototype.disposeInternal = + function() { + goog.events.unlisten( + this.viewportSizeMonitor_, + goog.events.EventType.RESIZE, + this.handleResize_, + false /* opt_capture */, + this); + goog.base(this, 'disposeInternal'); +}; + + +/** + * Handles resize events on the underlying ViewportMonitor. + * @param {goog.events.Event} e The resize event. + * @private + */ +goog.dom.BufferedViewportSizeMonitor.prototype.handleResize_ = + function(e) { + if (!this.resizeDelay_) { + this.resizeDelay_ = new goog.async.Delay( + goog.bind(this.onWindowResize_, this, e), this.resizeBufferMs_); + this.registerDisposable(this.resizeDelay_); + } + this.resizeDelay_.start(); +}; + + +/** + * Window resize callback that determines whether to reflow the view contents. + * @param {goog.events.Event} e The resize event. + * @private + */ +goog.dom.BufferedViewportSizeMonitor.prototype.onWindowResize_ = + function(e) { + if (this.viewportSizeMonitor_.isDisposed()) { + return; + } + var viewportSize = this.viewportSizeMonitor_.getSize(); + if (!this.paused_ && + !goog.math.Size.equals(viewportSize, this.currentSize_)) { + if (!this.previousSize_ || + viewportSize.width != this.previousSize_.width) { + this.dispatchEvent( + goog.dom.BufferedViewportSizeMonitor.EventType.RESIZE_WIDTH); + } + if (!this.previousSize_ || + viewportSize.height != this.previousSize_.height) { + this.dispatchEvent( + goog.dom.BufferedViewportSizeMonitor.EventType.RESIZE_HEIGHT); + } + this.previousSize_ = this.currentSize_; + this.currentSize_ = viewportSize; + this.dispatchEvent(e); + } +}; + + +/** + * Returns the current size of the viewport. + * @return {goog.math.Size?} The current viewport size. + */ +goog.dom.BufferedViewportSizeMonitor.prototype.getSize = function() { + return this.currentSize_ ? this.currentSize_.clone() : null; +}; + + +/** + * Returns the previous size of the viewport. + * @return {goog.math.Size?} The previous size of the viewport on the last + * RESIZE event. + */ +goog.dom.BufferedViewportSizeMonitor.prototype.getPreviousSize = function() { + return this.previousSize_ ? this.previousSize_.clone() : null; +}; + + +/** + * Pauses and unpauses viewport size monitoring. + * @param {boolean} paused True to pause. + */ +goog.dom.BufferedViewportSizeMonitor.prototype.setPaused = function(paused) { + this.paused_ = paused; +}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor_test.html b/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor_test.html new file mode 100644 index 0000000..18a5d01 --- /dev/null +++ b/contexts/data/lib/closure-library/closure/goog/dom/bufferedviewportsizemonitor_test.html @@ -0,0 +1,151 @@ +<!DOCTYPE html> +<html> +<!-- +Copyright 2012 The Closure Library Authors. All Rights Reserved. + +Use of this source code is governed by the Apache License, Version 2.0. +See the COPYING file for details. +--> +<head> +<title>Tests for goog.dom.BufferedViewportSizeMonitor</title> +<script type="text/javascript" src="../base.js"></script> +<script type="text/javascript"> + goog.require('goog.dom.ViewportSizeMonitor'); + goog.require('goog.events'); + goog.require('goog.events.EventType'); + goog.require('goog.math.Size'); + goog.require('goog.testing.events'); + goog.require('goog.testing.events.Event'); + goog.require('goog.testing.jsunit'); + goog.require('goog.testing.MockClock'); + + goog.require('goog.dom.BufferedViewportSizeMonitor'); +</script> +</head> +<body> + +<script type="text/javascript"> + +var RESIZE_DELAY = goog.dom.BufferedViewportSizeMonitor.RESIZE_EVENT_DELAY_MS_; +var INITIAL_SIZE = new goog.math.Size(111, 111); + +var mockControl; +var viewportSizeMonitor; +var bufferedVsm; +var timer = new goog.testing.MockClock(); +var resizeEventCount = 0; +var size; + +var resizeCallback = function() { + resizeEventCount++; +}; + +function setUp() { + timer.install(); + + size = INITIAL_SIZE; + viewportSizeMonitor = new goog.dom.ViewportSizeMonitor(); + viewportSizeMonitor.getSize = function() { return size }; + bufferedVsm = new goog.dom.BufferedViewportSizeMonitor(viewportSizeMonitor); + + goog.events.listen(bufferedVsm, goog.events.EventType.RESIZE, resizeCallback); +} + +function tearDown() { + goog.events.unlisten( + bufferedVsm, goog.events.EventType.RESIZE, resizeCallback); + resizeEventCount = 0; + timer.uninstall(); +} + +function testInitialSizes() { + assertTrue(goog.math.Size.equals( + INITIAL_SIZE, bufferedVsm.getPreviousSize())); + assertTrue(goog.math.Size.equals(INITIAL_SIZE, bufferedVsm.getSize())); +} + +function testWindowResize() { + assertEquals(0, resizeEventCount); + resize(100, 100); + timer.tick(RESIZE_DELAY - 1); + assertEquals( + 'No resize expected before the delay is fired', 0, resizeEventCount); + timer.tick(1); + assertEquals('Expected resize after delay', 1, resizeEventCount); + assertTrue(goog.math.Size.equals( + INITIAL_SIZE, bufferedVsm.getPreviousSize())); + assertTrue(goog.math.Size.equals( + new goog.math.Size(100, 100), bufferedVsm.getSize())); +} + +function testWindowResize_eventBatching() { + assertEquals('No resize calls expected before resize events', + 0, resizeEventCount); + resize(100, 100); + timer.tick(RESIZE_DELAY - 1); + resize(200, 200); + assertEquals( + 'No resize expected before the delay is fired', 0, resizeEventCount); + timer.tick(1); + assertEquals( + 'No resize expected when delay is restarted', 0, resizeEventCount); + timer.tick(RESIZE_DELAY); + assertEquals('Expected resize after delay', 1, resizeEventCount); +} + +function testWindowResize_noChange() { + resize(100, 100); + timer.tick(RESIZE_DELAY); + assertEquals(1, resizeEventCount); + resize(100, 100); + timer.tick(RESIZE_DELAY); + assertEquals( + 'No resize expected when size doesn\'t change', 1, resizeEventCount); + assertTrue(goog.math.Size.equals( + INITIAL_SIZE, bufferedVsm.getPreviousSize())); + assertTrue(goog.math.Size.equals( + new goog.math.Size(100, 100), bufferedVsm.getSize())); +} + +function testWindowResize_previousSize() { + resize(100, 100); + timer.tick(RESIZE_DELAY); + assertEquals(1, resizeEventCount); + assertTrue(goog.math.Size.equals( + INITIAL_SIZE, bufferedVsm.getPreviousSize())); + assertTrue(goog.math.Size.equals( + new goog.math.Size(100, 100), bufferedVsm.getSize())); + + resize(200, 200); + timer.tick(RESIZE_DELAY); + assertEquals(2, resizeEventCount); + assertTrue(goog.math.Size.equals( + new goog.math.Size(100, 100), bufferedVsm.getPreviousSize())); + assertTrue(goog.math.Size.equals( + new goog.math.Size(200, 200), bufferedVsm.getSize())); +} + +function testWindowResize_Paused() { + assertEquals( + 'No resize calls expected before resize events', 0, resizeEventCount); + resize(100, 100); + bufferedVsm.setPaused(true); + timer.tick(RESIZE_DELAY); + assertEquals( + 'No resize expected when paused', 0, resizeEventCount); + bufferedVsm.setPaused(false); + timer.tick(RESIZE_DELAY); + assertEquals( + 'No resize expected when unpaused', 0, resizeEventCount); +} + +function resize(width, height) { + size = new goog.math.Size(width, height); + goog.testing.events.fireBrowserEvent( + new goog.testing.events.Event( + goog.events.EventType.RESIZE, viewportSizeMonitor)); +} + +</script> +</body> +</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/classes.js b/contexts/data/lib/closure-library/closure/goog/dom/classes.js index d1e7b14..d6232f2 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/classes.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/classes.js @@ -15,6 +15,9 @@ /** * @fileoverview Utilities for adding, removing and setting classes. * + * Note: these utilities are meant to operate on HTMLElements and + * will not work on elements with differing interfaces (such as SVGElements). + * */ @@ -36,15 +39,15 @@ goog.dom.classes.set = function(element, className) { /** * Gets an array of class names on an element * @param {Node} element DOM node to get class of. - * @return {Array} Class names on {@code element}. + * @return {!Array} Class names on {@code element}. Some browsers add extra + * properties to the array. Do not depend on any of these! */ goog.dom.classes.get = function(element) { var className = element.className; // Some types of elements don't have a className in IE (e.g. iframes). // Furthermore, in Firefox, className is not a string when the element is // an SVG element. - return className && typeof className.split == 'function' ? - className.split(/\s+/) : []; + return goog.isString(className) && className.match(/\S+/g) || []; }; @@ -57,11 +60,10 @@ goog.dom.classes.get = function(element) { goog.dom.classes.add = function(element, var_args) { var classes = goog.dom.classes.get(element); var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.add_(classes, args); + var expectedCount = classes.length + args.length; + goog.dom.classes.add_(classes, args); element.className = classes.join(' '); - - return b; + return classes.length == expectedCount; }; @@ -75,11 +77,9 @@ goog.dom.classes.add = function(element, var_args) { goog.dom.classes.remove = function(element, var_args) { var classes = goog.dom.classes.get(element); var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.remove_(classes, args); - element.className = classes.join(' '); - - return b; + var newClasses = goog.dom.classes.getDifference_(classes, args); + element.className = newClasses.join(' '); + return newClasses.length == classes.length - args.length; }; @@ -90,40 +90,30 @@ goog.dom.classes.remove = function(element, var_args) { * @param {Array.<string>} classes All class names for the element, will be * updated to have the classes supplied in {@code args} added. * @param {Array.<string>} args Class names to add. - * @return {boolean} Whether all classes in were added. * @private */ goog.dom.classes.add_ = function(classes, args) { - var rv = 0; for (var i = 0; i < args.length; i++) { if (!goog.array.contains(classes, args[i])) { classes.push(args[i]); - rv++; } } - return rv == args.length; }; /** * Helper method for {@link goog.dom.classes.remove} and - * {@link goog.dom.classes.addRemove}. Removes one or more classes from the - * supplied classes array. - * @param {Array.<string>} classes All class names for the element, will be - * updated to have the classes supplied in {@code args} removed. - * @param {Array.<string>} args Class names to remove. - * @return {boolean} Whether all classes in were found and removed. + * {@link goog.dom.classes.addRemove}. Calculates the difference of two arrays. + * @param {!Array.<string>} arr1 First array. + * @param {!Array.<string>} arr2 Second array. + * @return {!Array.<string>} The first array without the elements of the second + * array. * @private */ -goog.dom.classes.remove_ = function(classes, args) { - var rv = 0; - for (var i = 0; i < classes.length; i++) { - if (goog.array.contains(args, classes[i])) { - goog.array.splice(classes, i--, 1); - rv++; - } - } - return rv == args.length; +goog.dom.classes.getDifference_ = function(arr1, arr2) { + return goog.array.filter(arr1, function(item) { + return !goog.array.contains(arr2, item); + }); }; @@ -166,9 +156,9 @@ goog.dom.classes.swap = function(element, fromClass, toClass) { * more than two class names that you want to swap. * * @param {Node} element DOM node to swap classes on. - * @param {string|Array.<string>|null} classesToRemove Class or classes to + * @param {?(string|Array.<string>)} classesToRemove Class or classes to * remove, if null no classes are removed. - * @param {string|Array.<string>|null} classesToAdd Class or classes to add, if + * @param {?(string|Array.<string>)} classesToAdd Class or classes to add, if * null no classes are added. */ goog.dom.classes.addRemove = function(element, classesToRemove, classesToAdd) { @@ -176,7 +166,7 @@ goog.dom.classes.addRemove = function(element, classesToRemove, classesToAdd) { if (goog.isString(classesToRemove)) { goog.array.remove(classes, classesToRemove); } else if (goog.isArray(classesToRemove)) { - goog.dom.classes.remove_(classes, classesToRemove); + classes = goog.dom.classes.getDifference_(classes, classesToRemove); } if (goog.isString(classesToAdd) && diff --git a/contexts/data/lib/closure-library/closure/goog/dom/classes_quirks_test.html b/contexts/data/lib/closure-library/closure/goog/dom/classes_quirks_test.html new file mode 100644 index 0000000..5fbadbe --- /dev/null +++ b/contexts/data/lib/closure-library/closure/goog/dom/classes_quirks_test.html @@ -0,0 +1,64 @@ +<html> +<!-- +Copyright 2006 The Closure Library Authors. All Rights Reserved. + +Use of this source code is governed by the Apache License, Version 2.0. +See the COPYING file for details. +--> +<!-- +This is a copy of classes_test.html but without a doctype. Make sure these two +are in sync. +--> +<head> +<meta http-equiv="X-UA-Compatible" content="IE=edge"> +<title>Closure Unit Tests - goog.dom.classes</title>= +<script src="../base.js"></script> +<style type="text/css"> +#styleTest1 { + width:120px;font-weight:bold; +} +</style> +</head> +<body> + <div id="testEl"> + <span>Test Element</span> + </div> + + <div><div><div id="testEl2"></div></div></div> + + <span id="span1" class="TEST1"></span> + <span id="span2" class="TEST1"></span> + <span id="span3" class="TEST2"></span> + <span id="span4" class="TEST3"></span> + <span id="span5" class="TEST1"></span> + <span id="span6"></span> + + <p id="p1"></p> + + <div id="styleTest1"></div> + <div id="styleTest2" style="width:100px;font-weight:bold"></div> + <div id="styleTest3"></div> + + <!-- Paragraph to test element child and sibling --> + <p id="p2"> + <!-- Comment --> + a + <b id="b1">c</b> + d + <!-- Comment --> + e + <b id="b2">f</b> + g + <!-- Comment --> + </p> + <p id="p3" class="SOMECLASS + OTHERCLASS"> + h + </p> + <iframe name="frame" src="../math/math_test.html"></iframe> + +<script> + goog.require('goog.dom.classes_test'); +</script> +</body> +</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/classes_test.html b/contexts/data/lib/closure-library/closure/goog/dom/classes_test.html index 9368795..bdde043 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/classes_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/classes_test.html @@ -6,15 +6,13 @@ Copyright 2006 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by the Apache License, Version 2.0. See the COPYING file for details. --> +<!-- +When changing this, make sure that classes_quirks_test.html is kept in sync. +--> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.classes</title>= +<title>Closure Unit Tests - goog.dom.classes</title> <script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.classes'); - goog.require('goog.testing.jsunit'); -</script> <style type="text/css"> #styleTest1 { width:120px;font-weight:bold; @@ -28,11 +26,11 @@ See the COPYING file for details. <div><div><div id="testEl2"></div></div></div> - <span id="span1" class="test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1"></span> + <span id="span1" class="TEST1"></span> + <span id="span2" class="TEST1"></span> + <span id="span3" class="TEST2"></span> + <span id="span4" class="TEST3"></span> + <span id="span5" class="TEST1"></span> <span id="span6"></span> <p id="p1"></p> @@ -53,176 +51,14 @@ See the COPYING file for details. g <!-- Comment --> </p> - <p id="p3" class="someclass - otherclass"> + <p id="p3" class="SOMECLASS + OTHERCLASS"> h </p> <iframe name="frame" src="../math/math_test.html"></iframe> <script> - - var $ = goog.dom.getElement; - var classes = goog.dom.classes; - - function testSetAddHasRemove() { - var el = $('p1'); - classes.set(el, 'someclass'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - - classes.set(el, 'otherclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have someclass', classes.has(el, 'someclass')); - - classes.add(el, 'wooclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - - classes.add(el, 'aclass', 'bclass', 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertTrue('Should have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertFalse('Should not have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'aclass', 'bclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertFalse('Should not have aclass', classes.has(el, 'aclass')); - assertFalse('Should not have bclass', classes.has(el, 'bclass')); - } - - function testSwap() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - - classes.swap(el, 'first', 'second'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertTrue('Should have second class', classes.has(el, 'second')); - - classes.swap(el, 'second', 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - } - - function testEnable() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', false); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', true); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testToggle() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testAddNotAddingMultiples() { - var el = $('span6'); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'b', 'b'); - assertEquals('a b', el.className); - } - - function testAddRemoveString() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, 'a', 'b'); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, null, 'c'); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, 'c', 'd'); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, 'd', null); - assertEquals('b', el.className); - } - - function testAddRemoveArray() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b']); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, [], ['c']); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, ['c'], ['d']); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, ['d'], []); - assertEquals('b', el.className); - } - - function testAddRemoveMultiple() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b', 'c', 'd']); - assertEquals('b c d', el.className); - - goog.dom.classes.addRemove(el, [], ['e', 'f']); - assertEquals('b c d e f', el.className); - - goog.dom.classes.addRemove(el, ['c', 'e'], []); - assertEquals('b d f', el.className); - - goog.dom.classes.addRemove(el, ['b'], ['g']); - assertEquals('d f g', el.className); - } - - function testHasWithNewlines() { - var el = $('p3'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - assertTrue('Should also have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have weirdclass', classes.has(el, 'weirdclass')); - } - + goog.require('goog.dom.classes_test'); </script> </body> </html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/classes_test.js b/contexts/data/lib/closure-library/closure/goog/dom/classes_test.js new file mode 100644 index 0000000..12f19d0 --- /dev/null +++ b/contexts/data/lib/closure-library/closure/goog/dom/classes_test.js @@ -0,0 +1,231 @@ +// Copyright 2008 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Shared code for classes_test.html & classes_quirks_test.html. + */ + +goog.provide('goog.dom.classes_test'); +goog.setTestOnly('goog.dom.classes_test'); + +goog.require('goog.dom'); +goog.require('goog.dom.classes'); +goog.require('goog.testing.jsunit'); + + +var classes = goog.dom.classes; + +function testGet() { + var el = document.createElement('div'); + assertArrayEquals([], goog.dom.classes.get(el)); + el.className = 'C'; + assertArrayEquals(['C'], goog.dom.classes.get(el)); + el.className = 'C D'; + assertArrayEquals(['C', 'D'], goog.dom.classes.get(el)); + el.className = 'C\nD'; + assertArrayEquals(['C', 'D'], goog.dom.classes.get(el)); + el.className = ' C '; + assertArrayEquals(['C'], goog.dom.classes.get(el)); +} + +function testSetAddHasRemove() { + var el = goog.dom.getElement('p1'); + classes.set(el, 'SOMECLASS'); + assertTrue('Should have SOMECLASS', classes.has(el, 'SOMECLASS')); + + classes.set(el, 'OTHERCLASS'); + assertTrue('Should have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertFalse('Should not have SOMECLASS', classes.has(el, 'SOMECLASS')); + + classes.add(el, 'WOOCLASS'); + assertTrue('Should have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertTrue('Should have WOOCLASS', classes.has(el, 'WOOCLASS')); + + classes.add(el, 'ACLASS', 'BCLASS', 'CCLASS'); + assertTrue('Should have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertTrue('Should have WOOCLASS', classes.has(el, 'WOOCLASS')); + assertTrue('Should have ACLASS', classes.has(el, 'ACLASS')); + assertTrue('Should have BCLASS', classes.has(el, 'BCLASS')); + assertTrue('Should have CCLASS', classes.has(el, 'CCLASS')); + + classes.remove(el, 'CCLASS'); + assertTrue('Should have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertTrue('Should have WOOCLASS', classes.has(el, 'WOOCLASS')); + assertTrue('Should have ACLASS', classes.has(el, 'ACLASS')); + assertTrue('Should have BCLASS', classes.has(el, 'BCLASS')); + assertFalse('Should not have CCLASS', classes.has(el, 'CCLASS')); + + classes.remove(el, 'ACLASS', 'BCLASS'); + assertTrue('Should have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertTrue('Should have WOOCLASS', classes.has(el, 'WOOCLASS')); + assertFalse('Should not have ACLASS', classes.has(el, 'ACLASS')); + assertFalse('Should not have BCLASS', classes.has(el, 'BCLASS')); +} + +// While support for this isn't implied in the method documentation, +// this is a frequently used pattern. +function testAddWithSpacesInClassName() { + var el = goog.dom.getElement('p1'); + classes.add(el, 'CLASS1 CLASS2', 'CLASS3 CLASS4'); + assertTrue('Should have CLASS1', classes.has(el, 'CLASS1')); + assertTrue('Should have CLASS2', classes.has(el, 'CLASS2')); + assertTrue('Should have CLASS3', classes.has(el, 'CLASS3')); + assertTrue('Should have CLASS4', classes.has(el, 'CLASS4')); +} + +function testSwap() { + var el = goog.dom.getElement('p1'); + classes.set(el, 'SOMECLASS FIRST'); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have FIRST class', classes.has(el, 'SOMECLASS')); + assertFalse('Should not have second class', classes.has(el, 'second')); + + classes.swap(el, 'FIRST', 'second'); + + assertFalse('Should not have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have FIRST class', classes.has(el, 'SOMECLASS')); + assertTrue('Should have second class', classes.has(el, 'second')); + + classes.swap(el, 'second', 'FIRST'); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have FIRST class', classes.has(el, 'SOMECLASS')); + assertFalse('Should not have second class', classes.has(el, 'second')); +} + +function testEnable() { + var el = goog.dom.getElement('p1'); + classes.set(el, 'SOMECLASS FIRST'); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); + + classes.enable(el, 'FIRST', false); + + assertFalse('Should not have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); + + classes.enable(el, 'FIRST', true); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); +} + +function testToggle() { + var el = goog.dom.getElement('p1'); + classes.set(el, 'SOMECLASS FIRST'); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); + + classes.toggle(el, 'FIRST'); + + assertFalse('Should not have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); + + classes.toggle(el, 'FIRST'); + + assertTrue('Should have FIRST class', classes.has(el, 'FIRST')); + assertTrue('Should have SOMECLASS class', classes.has(el, 'SOMECLASS')); +} + +function testAddNotAddingMultiples() { + var el = goog.dom.getElement('span6'); + assertTrue(classes.add(el, 'A')); + assertEquals('A', el.className); + assertFalse(classes.add(el, 'A')); + assertEquals('A', el.className); + assertFalse(classes.add(el, 'B', 'B')); + assertEquals('A B', el.className); +} + +function testAddRemoveString() { + var el = goog.dom.getElement('span6'); + el.className = 'A'; + + goog.dom.classes.addRemove(el, 'A', 'B'); + assertEquals('B', el.className); + + goog.dom.classes.addRemove(el, null, 'C'); + assertEquals('B C', el.className); + + goog.dom.classes.addRemove(el, 'C', 'D'); + assertEquals('B D', el.className); + + goog.dom.classes.addRemove(el, 'D', null); + assertEquals('B', el.className); +} + +function testAddRemoveArray() { + var el = goog.dom.getElement('span6'); + el.className = 'A'; + + goog.dom.classes.addRemove(el, ['A'], ['B']); + assertEquals('B', el.className); + + goog.dom.classes.addRemove(el, [], ['C']); + assertEquals('B C', el.className); + + goog.dom.classes.addRemove(el, ['C'], ['D']); + assertEquals('B D', el.className); + + goog.dom.classes.addRemove(el, ['D'], []); + assertEquals('B', el.className); +} + +function testAddRemoveMultiple() { + var el = goog.dom.getElement('span6'); + el.className = 'A'; + + goog.dom.classes.addRemove(el, ['A'], ['B', 'C', 'D']); + assertEquals('B C D', el.className); + + goog.dom.classes.addRemove(el, [], ['E', 'F']); + assertEquals('B C D E F', el.className); + + goog.dom.classes.addRemove(el, ['C', 'E'], []); + assertEquals('B D F', el.className); + + goog.dom.classes.addRemove(el, ['B'], ['G']); + assertEquals('D F G', el.className); +} + +// While support for this isn't implied in the method documentation, +// this is a frequently used pattern. +function testAddRemoveWithSpacesInClassName() { + var el = goog.dom.getElement('p1'); + classes.addRemove(el, '', 'CLASS1 CLASS2'); + assertTrue('Should have CLASS1', classes.has(el, 'CLASS1')); + assertTrue('Should have CLASS2', classes.has(el, 'CLASS2')); +} + +function testHasWithNewlines() { + var el = goog.dom.getElement('p3'); + assertTrue('Should have SOMECLASS', classes.has(el, 'SOMECLASS')); + assertTrue('Should also have OTHERCLASS', classes.has(el, 'OTHERCLASS')); + assertFalse('Should not have WEIRDCLASS', classes.has(el, 'WEIRDCLASS')); +} + +function testEmptyClassNames() { + var el = goog.dom.getElement('span1'); + // At the very least, make sure these do not error out. + assertFalse('Should not have an empty class', classes.has(el, '')); + classes.add(el, ''); + classes.toggle(el, ''); + assertFalse('Should not remove an empty class', classes.remove(el, '')); + classes.swap(el, '', 'OTHERCLASS'); + classes.swap(el, 'TEST1', ''); + classes.addRemove(el, '', ''); +} diff --git a/contexts/data/lib/closure-library/closure/goog/dom/controlrange.js b/contexts/data/lib/closure-library/closure/goog/dom/controlrange.js index 1bced30..71a7fbb 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/controlrange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/controlrange.js @@ -113,9 +113,7 @@ goog.dom.ControlRange.prototype.clearCachedValues_ = function() { }; -/** - * @return {goog.dom.ControlRange} A clone of this range. - */ +/** @override */ goog.dom.ControlRange.prototype.clone = function() { return goog.dom.ControlRange.createFromElements.apply(this, this.getElements()); @@ -232,7 +230,7 @@ goog.dom.ControlRange.prototype.isRangeInDocument = function() { returnValue = goog.array.every(this.getElements(), function(element) { // On IE, this throws an exception when the range is detached. return goog.userAgent.IE ? - element.parentNode : + !!element.parentNode : goog.dom.contains(element.ownerDocument.body, element); }); } catch (e) { @@ -365,9 +363,7 @@ goog.dom.DomSavedControlRange_ = function(range) { goog.inherits(goog.dom.DomSavedControlRange_, goog.dom.SavedRange); -/** - * @return {goog.dom.ControlRange} The restored range. - */ +/** @override */ goog.dom.DomSavedControlRange_.prototype.restoreInternal = function() { var doc = this.elements_.length ? goog.dom.getOwnerDocument(this.elements_[0]) : document; @@ -469,6 +465,7 @@ goog.dom.ControlRangeIterator.prototype.isLast = function() { * Move to the next position in the selection. * Throws {@code goog.iter.StopIteration} when it passes the end of the range. * @return {Node} The node at the next position. + * @override */ goog.dom.ControlRangeIterator.prototype.next = function() { // Iterate over each element in the range, and all of its children. @@ -487,11 +484,7 @@ goog.dom.ControlRangeIterator.prototype.next = function() { }; -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.ControlRangeIterator} other The iterator to copy. - * @protected - */ +/** @override */ goog.dom.ControlRangeIterator.prototype.copyFrom = function(other) { this.elements_ = other.elements_; this.startNode_ = other.startNode_; @@ -503,6 +496,7 @@ goog.dom.ControlRangeIterator.prototype.copyFrom = function(other) { /** * @return {goog.dom.ControlRangeIterator} An identical iterator. + * @override */ goog.dom.ControlRangeIterator.prototype.clone = function() { var copy = new goog.dom.ControlRangeIterator(null); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/dataset.js b/contexts/data/lib/closure-library/closure/goog/dom/dataset.js index 5f9b821..ac7dc23 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/dataset.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/dataset.js @@ -25,6 +25,16 @@ goog.require('goog.string'); /** + * The DOM attribute name prefix that must be present for it to be considered + * for a dataset. + * @type {string} + * @const + * @private + */ +goog.dom.dataset.PREFIX_ = 'data-'; + + +/** * Sets a custom data attribute on an element. The key should be * in camelCase format (e.g "keyName" for the "data-key-name" attribute). * @param {Element} element DOM node to set the custom data attribute on. @@ -35,14 +45,16 @@ goog.dom.dataset.set = function(element, key, value) { if (element.dataset) { element.dataset[key] = value; } else { - element.setAttribute('data-' + goog.string.toSelectorCase(key), value); + element.setAttribute( + goog.dom.dataset.PREFIX_ + goog.string.toSelectorCase(key), + value); } }; /** * Gets a custom data attribute from an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). + * in camelCase format (e.g "keyName" for the "data-key-name" attribute). * @param {Element} element DOM node to get the custom data attribute from. * @param {string} key Key for the custom data attribute. * @return {?string} The attribute value, if it exists. @@ -51,7 +63,8 @@ goog.dom.dataset.get = function(element, key) { if (element.dataset) { return element.dataset[key]; } else { - return element.getAttribute('data-' + goog.string.toSelectorCase(key)); + return element.getAttribute(goog.dom.dataset.PREFIX_ + + goog.string.toSelectorCase(key)); } }; @@ -66,14 +79,15 @@ goog.dom.dataset.remove = function(element, key) { if (element.dataset) { delete element.dataset[key]; } else { - element.removeAttribute('data-' + goog.string.toSelectorCase(key)); + element.removeAttribute(goog.dom.dataset.PREFIX_ + + goog.string.toSelectorCase(key)); } }; /** * Checks whether custom data attribute exists on an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). + * in camelCase format (e.g "keyName" for the "data-key-name" attribute). * * @param {Element} element DOM node to get the custom data attribute from. * @param {string} key Key for the custom data attribute. @@ -83,8 +97,39 @@ goog.dom.dataset.has = function(element, key) { if (element.dataset) { return key in element.dataset; } else if (element.hasAttribute) { - return element.hasAttribute('data-' + goog.string.toSelectorCase(key)); + return element.hasAttribute(goog.dom.dataset.PREFIX_ + + goog.string.toSelectorCase(key)); + } else { + return !!(element.getAttribute(goog.dom.dataset.PREFIX_ + + goog.string.toSelectorCase(key))); + } +}; + + +/** + * Gets all custom data attributes as a string map. The attribute names will be + * camel cased (e.g., data-foo-bar -> dataset['foobar']). This operation is not + * safe for attributes having camel-cased names clashing with already existing + * properties (e.g., data-to-string -> dataset['toString']). + * @param {!Element} element DOM node to get the data attributes from. + * @return {!Object} The string map containing data attributes and their + * respective values. + */ +goog.dom.dataset.getAll = function(element) { + if (element.dataset) { + return element.dataset; } else { - return !!(element.getAttribute('data-' + goog.string.toSelectorCase(key))); + var dataset = {}; + var attributes = element.attributes; + for (var i = 0; i < attributes.length; ++i) { + var attribute = attributes[i]; + if (goog.string.startsWith(attribute.name, + goog.dom.dataset.PREFIX_)) { + // We use substr(5), since it's faster than replacing 'data-' with ''. + var key = goog.string.toCamelCase(attribute.name.substr(5)); + dataset[key] = attribute.value; + } + } + return dataset; } }; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/dataset_test.html b/contexts/data/lib/closure-library/closure/goog/dom/dataset_test.html index 0030aa6..6334345 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/dataset_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/dataset_test.html @@ -99,6 +99,19 @@ function testRemove() { } +function testGetAll() { + var el = $('el1'); + var expectedDataset = { + 'basicKey': 'basic', + 'UnusualKey1': 'unusual1', + 'unusual-Key2': 'unusual2', + '-Bizarre--Key': 'bizarre' + }; + assertHashEquals('Dataset should have basicKey, UnusualKey1, ' + + 'unusual-Key2, and -Bizarre--Key', + expectedDataset, dataset.getAll(el)); +} + </script> </body> </html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/dom.js b/contexts/data/lib/closure-library/closure/goog/dom/dom.js index dc78f3f..164a93d 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/dom.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/dom.js @@ -88,7 +88,7 @@ goog.dom.NodeType = { /** * Gets the DomHelper object for the document where the element resides. - * @param {Node|Window=} opt_element If present, gets the DomHelper for this + * @param {(Node|Window)=} opt_element If present, gets the DomHelper for this * element. * @return {!goog.dom.DomHelper} The DomHelper. */ @@ -153,7 +153,7 @@ goog.dom.$ = goog.dom.getElement; * * @param {?string=} opt_tag Element tag name. * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. + * @param {(Document|Element)=} opt_el Optional element to look in. * @return { {length: number} } Array-like list of elements (only a length * property and numerical indices are guaranteed to exist). */ @@ -167,7 +167,7 @@ goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) { * Returns an array of all the elements with the provided className. * @see {goog.dom.query} * @param {string} className the name of the class to look for. - * @param {Document|Element=} opt_el Optional element to look in. + * @param {(Document|Element)=} opt_el Optional element to look in. * @return { {length: number} } The items found with the class name provided. */ goog.dom.getElementsByClass = function(className, opt_el) { @@ -203,18 +203,13 @@ goog.dom.getElementByClass = function(className, opt_el) { /** * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and - * fast W3C Selectors API. However, the version of WebKit that shipped with - * Safari 3.1 and Chrome has a bug where it will not correctly match mixed- - * case class name selectors in quirks mode. - * @param {!Element|Document} parent The parent document object. + * fast W3C Selectors API. + * @param {!(Element|Document)} parent The parent document object. * @return {boolean} whether or not we can use parent.querySelector* APIs. * @private */ goog.dom.canUseQuerySelector_ = function(parent) { - return parent.querySelectorAll && - parent.querySelector && - (!goog.userAgent.WEBKIT || goog.dom.isCss1CompatMode_(document) || - goog.userAgent.isVersion('528')); + return !!(parent.querySelectorAll && parent.querySelector); }; @@ -223,7 +218,7 @@ goog.dom.canUseQuerySelector_ = function(parent) { * @param {!Document} doc The document to get the elements in. * @param {?string=} opt_tag Element tag name. * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. + * @param {(Document|Element)=} opt_el Optional element to look in. * @return { {length: number} } Array-like list of elements (only a length * property and numerical indices are guaranteed to exist). * @private @@ -311,7 +306,8 @@ goog.dom.setProperties = function(element, properties) { element.htmlFor = val; } else if (key in goog.dom.DIRECT_ATTRIBUTE_MAP_) { element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val); - } else if (goog.string.startsWith(key, 'aria-')) { + } else if (goog.string.startsWith(key, 'aria-') || + goog.string.startsWith(key, 'data-')) { element.setAttribute(key, val); } else { element[key] = val; @@ -332,14 +328,15 @@ goog.dom.DIRECT_ATTRIBUTE_MAP_ = { 'cellpadding': 'cellPadding', 'cellspacing': 'cellSpacing', 'colspan': 'colSpan', - 'rowspan': 'rowSpan', - 'valign': 'vAlign', - 'height': 'height', - 'width': 'width', - 'usemap': 'useMap', 'frameborder': 'frameBorder', + 'height': 'height', 'maxlength': 'maxLength', - 'type': 'type' + 'role': 'role', + 'rowspan': 'rowSpan', + 'type': 'type', + 'usemap': 'useMap', + 'valign': 'vAlign', + 'width': 'width' }; @@ -422,29 +419,7 @@ goog.dom.getViewportSize = function(opt_window) { */ goog.dom.getViewportSize_ = function(win) { var doc = win.document; - - if (goog.userAgent.WEBKIT && !goog.userAgent.isVersion('500') && - !goog.userAgent.MOBILE) { - // TODO(user): Sometimes we get something that isn't a valid window - // object. In this case we just revert to the current window. We need to - // figure out when this happens and find a real fix for it. - // See the comments on goog.dom.getWindow. - if (typeof win.innerHeight == 'undefined') { - win = window; - } - var innerHeight = win.innerHeight; - var scrollHeight = win.document.documentElement.scrollHeight; - - if (win == win.top) { - if (scrollHeight < innerHeight) { - innerHeight -= 15; // Scrollbars are 15px wide on Mac - } - } - return new goog.math.Size(win.innerWidth, innerHeight); - } - var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body; - return new goog.math.Size(el.clientWidth, el.clientHeight); }; @@ -626,11 +601,11 @@ goog.dom.getWindow_ = function(doc) { * would return a div with two child paragraphs * * @param {string} tagName Tag to create. - * @param {Object|Array.<string>|string=} opt_attributes If object, then a map + * @param {(Object|Array.<string>|string)=} opt_attributes If object, then a map * of name-value pairs for attributes. If a string, then this is the * className of the new element. If an array, the elements will be joined * together as the className of the new element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or + * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or * strings for text nodes. If one of the var_args is an array or NodeList,i * its elements will be added as childNodes instead. * @return {!Element} Reference to a DOM node. @@ -669,8 +644,13 @@ goog.dom.createDom_ = function(doc, args) { // Clone attributes map to remove 'type' without mutating the input. var clone = {}; goog.object.extend(clone, attributes); + + // JSCompiler can't see how goog.object.extend added this property, + // because it was essentially added by reflection. + // So it needs to be quoted. + delete clone['type']; + attributes = clone; - delete attributes.type; } tagNameArr.push('>'); tagName = tagNameArr.join(''); @@ -720,7 +700,7 @@ goog.dom.append_ = function(doc, parent, args, startIndex) { // If the argument is a node list, not a real array, use a clone, // because forEach can't be used to mutate a NodeList. goog.array.forEach(goog.dom.isNodeList(arg) ? - goog.array.clone(arg) : arg, + goog.array.toArray(arg) : arg, childHandler); } else { childHandler(arg); @@ -732,10 +712,10 @@ goog.dom.append_ = function(doc, parent, args, startIndex) { /** * Alias for {@code createDom}. * @param {string} tagName Tag to create. - * @param {string|Object=} opt_attributes If object, then a map of name-value + * @param {(string|Object)=} opt_attributes If object, then a map of name-value * pairs for attributes. If a string, then this is the className of the new * element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or + * @param {...(Object|string|Array|NodeList)} var_args Further DOM nodes or * strings for text nodes. If one of the var_args is an array, its * children will be added as childNodes instead. * @return {!Element} Reference to a DOM node. @@ -805,7 +785,11 @@ goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) { /** - * Converts an HTML string into a document fragment. + * Converts an HTML string into a document fragment. The string must be + * sanitized in order to avoid cross-site scripting. For example + * {@code goog.dom.htmlToDocumentFragment('<img src=x onerror=alert(0)>')} + * triggers an alert in all browsers, even if the returned document fragment + * is thrown away immediately. * * @param {string} htmlString The HTML string to convert. * @return {!Node} The resulting document fragment. @@ -913,12 +897,15 @@ goog.dom.canHaveChildren = function(node) { case goog.dom.TagName.BASE: case goog.dom.TagName.BR: case goog.dom.TagName.COL: + case goog.dom.TagName.COMMAND: + case goog.dom.TagName.EMBED: case goog.dom.TagName.FRAME: case goog.dom.TagName.HR: case goog.dom.TagName.IMG: case goog.dom.TagName.INPUT: case goog.dom.TagName.IFRAME: case goog.dom.TagName.ISINDEX: + case goog.dom.TagName.KEYGEN: case goog.dom.TagName.LINK: case goog.dom.TagName.NOFRAMES: case goog.dom.TagName.NOSCRIPT: @@ -926,7 +913,10 @@ goog.dom.canHaveChildren = function(node) { case goog.dom.TagName.OBJECT: case goog.dom.TagName.PARAM: case goog.dom.TagName.SCRIPT: + case goog.dom.TagName.SOURCE: case goog.dom.TagName.STYLE: + case goog.dom.TagName.TRACK: + case goog.dom.TagName.WBR: return false; } return true; @@ -1042,8 +1032,8 @@ goog.dom.replaceNode = function(newNode, oldNode) { * Does nothing if the element is not in the document. * @param {Element} element The element to flatten. * @return {Element|undefined} The original element, detached from the document - * tree, sans children; or undefined, if the element was not in the - * document to begin with. + * tree, sans children; or undefined, if the element was not in the document + * to begin with. */ goog.dom.flattenElement = function(element) { var child, parent = element.parentNode; @@ -1067,7 +1057,7 @@ goog.dom.flattenElement = function(element) { /** * Returns an array containing just the element children of the given element. * @param {Element} element The element whose element children we want. - * @return {Array|NodeList} An array or array-like list of just the element + * @return {!(Array|NodeList)} An array or array-like list of just the element * children of the given element. */ goog.dom.getChildren = function(element) { @@ -1299,6 +1289,16 @@ goog.dom.compareNodeOrder = function(node1, node2) { return node1.compareDocumentPosition(node2) & 2 ? 1 : -1; } + // Special case for document nodes on IE 7 and 8. + if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { + if (node1.nodeType == goog.dom.NodeType.DOCUMENT) { + return -1; + } + if (node2.nodeType == goog.dom.NodeType.DOCUMENT) { + return 1; + } + } + // Process in IE using sourceIndex - we check to see if the first node has // a source index or if its parent has one. if ('sourceIndex' in node1 || @@ -1463,7 +1463,7 @@ goog.dom.getFrameContentDocument = function(frame) { /** * Cross-browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. + * @param {Element} frame Frame element. * @return {Window} The window associated with the given frame. */ goog.dom.getFrameContentWindow = function(frame) { @@ -1546,7 +1546,7 @@ goog.dom.findNode = function(root, p) { * @param {Node} root The root of the tree to search. * @param {function(Node) : boolean} p The filter function. - * @return {Array.<Node>} The found nodes or an empty array if none are found. + * @return {!Array.<!Node>} The found nodes or an empty array if none are found. */ goog.dom.findNodes = function(root, p) { var rv = []; @@ -1560,7 +1560,7 @@ goog.dom.findNodes = function(root, p) { * using a depth first search. * @param {Node} root The root of the tree to search. * @param {function(Node) : boolean} p The filter function. - * @param {Array.<Node>} rv The found nodes are added to this array. + * @param {!Array.<!Node>} rv The found nodes are added to this array. * @param {boolean} findOne If true we exit after the first found node. * @return {boolean} Whether the search is complete or not. True in case findOne * is true and the node is found. False otherwise. @@ -1854,20 +1854,23 @@ goog.dom.isNodeList = function(val) { * tag name and/or class name. If the passed element matches the specified * criteria, the element itself is returned. * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). + * @param {?(goog.dom.TagName|string)=} opt_tag The tag name to match (or + * null/undefined to match only based on class name). * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. + * match only based on tag name). + * @return {Element} The first ancestor that matches the passed criteria, or + * null if no match is found. */ goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) { + if (!opt_tag && !opt_class) { + return null; + } var tagName = opt_tag ? opt_tag.toUpperCase() : null; - return goog.dom.getAncestor(element, + return /** @type {Element} */ (goog.dom.getAncestor(element, function(node) { return (!tagName || node.nodeName == tagName) && (!opt_class || goog.dom.classes.has(node, opt_class)); - }, true); + }, true)); }; @@ -1876,13 +1879,12 @@ goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) { * class name. If the passed element matches the specified criteria, the * element itself is returned. * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or + * @param {string} className The class name to match. + * @return {Element} The first ancestor that matches the passed criteria, or * null if none match. */ -goog.dom.getAncestorByClass = function(element, opt_class) { - return goog.dom.getAncestorByTagNameAndClass(element, null, opt_class); +goog.dom.getAncestorByClass = function(element, className) { + return goog.dom.getAncestorByTagNameAndClass(element, null, className); }; @@ -2018,7 +2020,7 @@ goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement; * * @param {?string=} opt_tag Element tag name or * for all tags. * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. + * @param {(Document|Element)=} opt_el Optional element to look in. * @return { {length: number} } Array-like list of elements (only a length * property and numerical indices are guaranteed to exist). */ @@ -2047,7 +2049,7 @@ goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) { * Returns the first element we find matching the provided class name. * @see {goog.dom.query} * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. + * @param {(Element|Document)=} opt_el Optional element to look in. * @return {Element} The first item found with the class name provided. */ goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) { @@ -2143,7 +2145,7 @@ goog.dom.DomHelper.prototype.createDom = function(tagName, /** * Alias for {@code createDom}. * @param {string} tagName Tag to create. - * @param {Object|string=} opt_attributes If object, then a map of name-value + * @param {(Object|string)=} opt_attributes If object, then a map of name-value * pairs for attributes. If a string, then this is the className of the new * element. * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for @@ -2251,6 +2253,16 @@ goog.dom.DomHelper.prototype.getDocumentScroll = function() { /** + * Determines the active element in the given document. + * @param {Document=} opt_doc The document to look in. + * @return {Element} The active element. + */ +goog.dom.DomHelper.prototype.getActiveElement = function(opt_doc) { + return goog.dom.getActiveElement(opt_doc || this.document_); +}; + + +/** * Appends a child to a node. * @param {Node} parent Parent. * @param {Node} child Child. @@ -2270,6 +2282,16 @@ goog.dom.DomHelper.prototype.append = goog.dom.append; /** + * Determines if the given node can contain children, intended to be used for + * HTML generation. + * + * @param {Node} node The node to check. + * @return {boolean} Whether the node can contain children. + */ +goog.dom.DomHelper.prototype.canHaveChildren = goog.dom.canHaveChildren; + + +/** * Removes all the child nodes on a DOM node. * @param {Node} node Node to remove children from. */ @@ -2295,6 +2317,18 @@ goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter; /** + * Insert a child at a given index. If index is larger than the number of child + * nodes that the parent currently has, the node is inserted as the last child + * node. + * @param {Element} parent The element into which to insert the child. + * @param {Node} child The element to insert. + * @param {number} index The index at which to insert the new child node. Must + * not be negative. + */ +goog.dom.DomHelper.prototype.insertChildAt = goog.dom.insertChildAt; + + +/** * Removes a node from its parent. * @param {Node} node The node to remove. * @return {Node} The node removed if removed; else, null. @@ -2322,6 +2356,15 @@ goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement; /** + * Returns an array containing just the element children of the given element. + * @param {Element} element The element whose element children we want. + * @return {!(Array|NodeList)} An array or array-like list of just the element + * children of the given element. + */ +goog.dom.DomHelper.prototype.getChildren = goog.dom.getChildren; + + +/** * Returns the first child node that is an element. * @param {Node} node The node to get the first child element of. * @return {Element} The first child node of {@code node} that is an element. @@ -2363,8 +2406,7 @@ goog.dom.DomHelper.prototype.getPreviousElementSibling = * @return {Node} The next node in the DOM tree, or null if this was the last * node. */ -goog.dom.DomHelper.prototype.getNextNode = - goog.dom.getNextNode; +goog.dom.DomHelper.prototype.getNextNode = goog.dom.getNextNode; /** @@ -2373,8 +2415,7 @@ goog.dom.DomHelper.prototype.getNextNode = * @return {Node} The previous node in the DOM tree, or null if this was the * first node. */ -goog.dom.DomHelper.prototype.getPreviousNode = - goog.dom.getPreviousNode; +goog.dom.DomHelper.prototype.getPreviousNode = goog.dom.getPreviousNode; /** @@ -2386,6 +2427,31 @@ goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike; /** + * Whether the object looks like an Element. + * @param {*} obj The object being tested for Element likeness. + * @return {boolean} Whether the object looks like an Element. + */ +goog.dom.DomHelper.prototype.isElement = goog.dom.isElement; + + +/** + * Returns true if the specified value is a Window object. This includes the + * global window for HTML pages, and iframe windows. + * @param {*} obj Variable to test. + * @return {boolean} Whether the variable is a window. + */ +goog.dom.DomHelper.prototype.isWindow = goog.dom.isWindow; + + +/** + * Returns an element's parent, if it's an Element. + * @param {Element} element The DOM element. + * @return {Element} The parent, or null if not an Element. + */ +goog.dom.DomHelper.prototype.getParentElement = goog.dom.getParentElement; + + +/** * Whether a node contains another node. * @param {Node} parent The node that should contain the other node. * @param {Node} descendant The node to test presence of. @@ -2395,6 +2461,31 @@ goog.dom.DomHelper.prototype.contains = goog.dom.contains; /** + * Compares the document order of two nodes, returning 0 if they are the same + * node, a negative number if node1 is before node2, and a positive number if + * node2 is before node1. Note that we compare the order the tags appear in the + * document so in the tree <b><i>text</i></b> the B node is considered to be + * before the I node. + * + * @param {Node} node1 The first node to compare. + * @param {Node} node2 The second node to compare. + * @return {number} 0 if the nodes are the same node, a negative number if node1 + * is before node2, and a positive number if node2 is before node1. + */ +goog.dom.DomHelper.prototype.compareNodeOrder = goog.dom.compareNodeOrder; + + +/** + * Find the deepest common ancestor of the given nodes. + * @param {...Node} var_args The nodes to find a common ancestor of. + * @return {Node} The common ancestor of the nodes, or null if there is none. + * null will only be returned if two or more of the nodes are from different + * documents. + */ +goog.dom.DomHelper.prototype.findCommonAncestor = goog.dom.findCommonAncestor; + + +/** * Returns the owner document for a node. * @param {Node} node The node to get the document for. * @return {!Document} The document owning the node. @@ -2404,8 +2495,8 @@ goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument; /** * Cross browser function for getting the document element of an iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} iframe Iframe element. - * @return {!HTMLDocument} The frame content document. + * @param {Element} iframe Iframe element. + * @return {!Document} The frame content document. */ goog.dom.DomHelper.prototype.getFrameContentDocument = goog.dom.getFrameContentDocument; @@ -2413,7 +2504,7 @@ goog.dom.DomHelper.prototype.getFrameContentDocument = /** * Cross browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. + * @param {Element} frame Frame element. * @return {Window} The window associated with the given frame. */ goog.dom.DomHelper.prototype.getFrameContentWindow = @@ -2430,11 +2521,20 @@ goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent; /** + * Gets the outerHTML of a node, which islike innerHTML, except that it + * actually contains the HTML of the node itself. + * @param {Element} element The element to get the HTML of. + * @return {string} The outerHTML of the given element. + */ +goog.dom.DomHelper.prototype.getOuterHtml = goog.dom.getOuterHtml; + + +/** * Finds the first descendant node that matches the filter function. This does * a depth first search. * @param {Node} root The root of the tree to search. * @param {function(Node) : boolean} p The filter function. - * @return {(Node, undefined)} The found node or undefined if none is found. + * @return {Node|undefined} The found node or undefined if none is found. */ goog.dom.DomHelper.prototype.findNode = goog.dom.findNode; @@ -2450,6 +2550,30 @@ goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes; /** + * Returns true if the element has a tab index that allows it to receive + * keyboard focus (tabIndex >= 0), false otherwise. Note that form elements + * natively support keyboard focus, even if they have no tab index. + * @param {Element} element Element to check. + * @return {boolean} Whether the element has a tab index that allows keyboard + * focus. + */ +goog.dom.DomHelper.prototype.isFocusableTabIndex = goog.dom.isFocusableTabIndex; + + +/** + * Enables or disables keyboard focus support on the element via its tab index. + * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true + * (or elements that natively support keyboard focus, like form elements) can + * receive keyboard focus. See http://go/tabindex for more info. + * @param {Element} element Element whose tab index is to be changed. + * @param {boolean} enable Whether to set or remove a tab index on the element + * that supports keyboard focus. + */ +goog.dom.DomHelper.prototype.setFocusableTabIndex = + goog.dom.setFocusableTabIndex; + + +/** * Returns the text contents of the current node, without markup. New lines are * stripped and whitespace is collapsed, such that each character would be * visible. @@ -2488,16 +2612,40 @@ goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset; /** + * Returns the node at a given offset in a parent node. If an object is + * provided for the optional third parameter, the node and the remainder of the + * offset will stored as properties of this object. + * @param {Node} parent The parent node. + * @param {number} offset The offset into the parent node. + * @param {Object=} opt_result Object to be used to store the return value. The + * return value will be stored in the form {node: Node, remainder: number} + * if this object is provided. + * @return {Node} The node at the given offset. + */ +goog.dom.DomHelper.prototype.getNodeAtOffset = goog.dom.getNodeAtOffset; + + +/** + * Returns true if the object is a {@code NodeList}. To qualify as a NodeList, + * the object must have a numeric length property and an item function (which + * has type 'string' on IE for some reason). + * @param {Object} val Object to test. + * @return {boolean} Whether the object is a NodeList. + */ +goog.dom.DomHelper.prototype.isNodeList = goog.dom.isNodeList; + + +/** * Walks up the DOM hierarchy returning the first ancestor that has the passed * tag name and/or class name. If the passed element matches the specified * criteria, the element itself is returned. * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). + * @param {?(goog.dom.TagName|string)=} opt_tag The tag name to match (or + * null/undefined to match only based on class name). * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. + * match only based on tag name). + * @return {Element} The first ancestor that matches the passed criteria, or + * null if no match is found. */ goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass = goog.dom.getAncestorByTagNameAndClass; @@ -2508,9 +2656,8 @@ goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass = * class name. If the passed element matches the specified criteria, the * element itself is returned. * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or + * @param {string} class The class name to match. + * @return {Element} The first ancestor that matches the passed criteria, or * null if none match. */ goog.dom.DomHelper.prototype.getAncestorByClass = diff --git a/contexts/data/lib/closure-library/closure/goog/dom/dom_test.js b/contexts/data/lib/closure-library/closure/goog/dom/dom_test.js index 614ff12..0150862 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/dom_test.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/dom_test.js @@ -22,6 +22,7 @@ goog.require('goog.dom'); goog.require('goog.dom.DomHelper'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.TagName'); +goog.require('goog.object'); goog.require('goog.testing.asserts'); goog.require('goog.userAgent'); goog.require('goog.userAgent.product'); @@ -140,7 +141,7 @@ function testGetElementByClass() { } function testSetProperties() { - var attrs = { 'name': 'test3', 'title': 'A title', 'random': 'woop' }; + var attrs = {'name': 'test3', 'title': 'A title', 'random': 'woop'}; var el = $('testEl'); var res = goog.dom.setProperties(el, attrs); @@ -160,7 +161,8 @@ function testSetPropertiesDirectAttributeMap() { function testSetPropertiesAria() { var attrs = { 'aria-hidden': 'true', - 'aria-label': 'This is a label' + 'aria-label': 'This is a label', + 'role': 'presentation' }; var el = goog.dom.createDom('div'); @@ -168,6 +170,21 @@ function testSetPropertiesAria() { assertEquals('Should be equal', 'true', el.getAttribute('aria-hidden')); assertEquals('Should be equal', 'This is a label', el.getAttribute('aria-label')); + assertEquals('Should be equal', 'presentation', el.getAttribute('role')); +} + +function testSetPropertiesData() { + var attrs = { + 'data-tooltip': 'This is a tooltip', + 'data-tooltip-delay': '100' + }; + var el = goog.dom.createDom('div'); + + goog.dom.setProperties(el, attrs); + assertEquals('Should be equal', 'This is a tooltip', + el.getAttribute('data-tooltip')); + assertEquals('Should be equal', '100', + el.getAttribute('data-tooltip-delay')); } function testSetTableProperties() { @@ -443,6 +460,11 @@ function testCompareNodeOrder() { goog.dom.compareNodeOrder(text2, text1) > 0); assertTrue('Late text node is after b1', goog.dom.compareNodeOrder(text1, $('b1')) > 0); + + assertTrue('Document node is before non-document node', + goog.dom.compareNodeOrder(document, b1) < 0); + assertTrue('Non-document node is after document node', + goog.dom.compareNodeOrder(b1, document) > 0); } function testFindCommonAncestor() { @@ -1094,32 +1116,43 @@ function testGetFrameContentWindow() { } function testCanHaveChildren() { + var EMPTY_ELEMENTS = goog.object.createSet( + goog.dom.TagName.APPLET, + goog.dom.TagName.AREA, + goog.dom.TagName.BASE, + goog.dom.TagName.BR, + goog.dom.TagName.COL, + goog.dom.TagName.COMMAND, + goog.dom.TagName.EMBED, + goog.dom.TagName.FRAME, + goog.dom.TagName.HR, + goog.dom.TagName.IMG, + goog.dom.TagName.INPUT, + goog.dom.TagName.IFRAME, + goog.dom.TagName.ISINDEX, + goog.dom.TagName.KEYGEN, + goog.dom.TagName.LINK, + goog.dom.TagName.NOFRAMES, + goog.dom.TagName.NOSCRIPT, + goog.dom.TagName.META, + goog.dom.TagName.OBJECT, + goog.dom.TagName.PARAM, + goog.dom.TagName.SCRIPT, + goog.dom.TagName.SOURCE, + goog.dom.TagName.STYLE, + goog.dom.TagName.TRACK, + goog.dom.TagName.WBR); + + // IE opens a dialog warning about using Java content if an EMBED is created. + var IE_ILLEGAL_ELEMENTS = goog.object.createSet(goog.dom.TagName.EMBED); + for (var tag in goog.dom.TagName) { - var expected = true; - switch (tag) { - case goog.dom.TagName.BASE: - case goog.dom.TagName.APPLET: - case goog.dom.TagName.AREA: - case goog.dom.TagName.BR: - case goog.dom.TagName.COL: - case goog.dom.TagName.FRAME: - case goog.dom.TagName.HR: - case goog.dom.TagName.IMG: - case goog.dom.TagName.INPUT: - case goog.dom.TagName.IFRAME: - case goog.dom.TagName.ISINDEX: - case goog.dom.TagName.LINK: - case goog.dom.TagName.NOFRAMES: - case goog.dom.TagName.NOSCRIPT: - case goog.dom.TagName.META: - case goog.dom.TagName.OBJECT: - case goog.dom.TagName.PARAM: - case goog.dom.TagName.SCRIPT: - case goog.dom.TagName.STYLE: - expected = false; - break; + if (goog.userAgent.IE && tag in IE_ILLEGAL_ELEMENTS) { + continue; } - var node = goog.dom.createDom(tag); + + var expected = !(tag in EMPTY_ELEMENTS); + var node = goog.dom.createElement(tag); assertEquals(tag + ' should ' + (expected ? '' : 'not ') + 'have children', expected, goog.dom.canHaveChildren(node)); @@ -1205,6 +1238,9 @@ function testGetAncestorByTagNameAndClass() { assertEquals(expected, goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.DIV, 'testAncestor')); + assertNull( + 'Should return null if no search criteria are given', + goog.dom.getAncestorByTagNameAndClass(elem)); } function testCreateTable() { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/forms.js b/contexts/data/lib/closure-library/closure/goog/dom/forms.js index af403f9..57ba4cb 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/forms.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/forms.js @@ -67,12 +67,20 @@ goog.dom.forms.getFormDataString = function(form) { goog.dom.forms.getFormDataHelper_ = function(form, result, fnAppend) { var els = form.elements; for (var el, i = 0; el = els[i]; i++) { - if (el.disabled || el.tagName.toLowerCase() == 'fieldset') { + if (// Make sure we don't include elements that are not part of the form. + // Some browsers include non-form elements. Check for 'form' property. + // See http://code.google.com/p/closure-library/issues/detail?id=227 + // and + // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#the-input-element + (el.form != form) || + el.disabled || + // HTMLFieldSetElement has a form property but no value. + el.tagName.toLowerCase() == 'fieldset') { continue; } + var name = el.name; - var type = el.type.toLowerCase(); - switch (type) { + switch (el.type.toLowerCase()) { case 'file': // file inputs are not supported case 'submit': @@ -403,4 +411,3 @@ goog.dom.forms.setSelectMultiple_ = function(el, opt_value) { } } }; - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/forms_test.html b/contexts/data/lib/closure-library/closure/goog/dom/forms_test.html index 67570fd..3c632df 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/forms_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/forms_test.html @@ -132,6 +132,13 @@ See the COPYING file for details. <option value="a">A</option> <option value="b">B</option> </select> + + </form> + + <form id="testform4"> + <embed ></embed> + <embed type="foo/bar"></embed> + <object></object> </form> <script> @@ -478,6 +485,11 @@ See the COPYING file for details. var result = goog.dom.forms.getValue(el); assertEquals('reset', result); } + + function testGetFormDataHelperAndNonInputElements() { + var el = goog.dom.getElement('testform4'); + goog.dom.forms.getFormDataHelper_(el, {}, goog.nullFunction); + } </script> </body> </html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/fullscreen.js b/contexts/data/lib/closure-library/closure/goog/dom/fullscreen.js new file mode 100644 index 0000000..d1f1297 --- /dev/null +++ b/contexts/data/lib/closure-library/closure/goog/dom/fullscreen.js @@ -0,0 +1,124 @@ +// Copyright 2012 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Functions for managing full screen status of the DOM. + * + */ + +goog.provide('goog.dom.fullscreen'); +goog.provide('goog.dom.fullscreen.EventType'); + +goog.require('goog.dom'); +goog.require('goog.userAgent'); +goog.require('goog.userAgent.product'); + + +/** + * Event types for full screen. + * @enum {string} + */ +goog.dom.fullscreen.EventType = { + /** Dispatched by the Document when the fullscreen status changes. */ + CHANGE: goog.userAgent.WEBKIT ? + 'webkitfullscreenchange' : + 'mozfullscreenchange' +}; + + +/** + * Determines if full screen is supported. + * @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being + * queried. If not provided, use the current DOM. + * @return {boolean} True iff full screen is supported. + */ +goog.dom.fullscreen.isSupported = function(opt_domHelper) { + var doc = goog.dom.fullscreen.getDocument_(opt_domHelper); + var body = doc.body; + return !!body.webkitRequestFullScreen || + (!!body.mozRequestFullScreen && doc.mozFullScreenEnabled); +}; + + +/** + * Requests putting the element in full screen. + * @param {!Element} element The element to put full screen. + */ +goog.dom.fullscreen.requestFullScreen = function(element) { + if (element.webkitRequestFullScreen) { + element.webkitRequestFullScreen(); + } else if (element.mozRequestFullScreen) { + element.mozRequestFullScreen(); + } +}; + + +/** + * Requests putting the element in full screen with full keyboard access. + * @param {!Element} element The element to put full screen. + */ +goog.dom.fullscreen.requestFullScreenWithKeys = function( + element) { + if (element.mozRequestFullScreenWithKeys) { + element.mozRequestFullScreenWithKeys(); + } else if (element.webkitRequestFullScreen && + element.ALLOW_KEYBOARD_INPUT && + goog.userAgent.product.CHROME) { + // Safari has the ALLOW_KEYBOARD_INPUT property but using it gives an error. + element.webkitRequestFullScreen(element.ALLOW_KEYBOARD_INPUT); + } else { + goog.dom.fullscreen.requestFullScreen(element); + } +}; + + +/** + * Exits full screen. + * @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being + * queried. If not provided, use the current DOM. + */ +goog.dom.fullscreen.exitFullScreen = function(opt_domHelper) { + var doc = goog.dom.fullscreen.getDocument_(opt_domHelper); + if (doc.webkitCancelFullScreen) { + doc.webkitCancelFullScreen(); + } else if (doc.mozCancelFullScreen) { + doc.mozCancelFullScreen(); + } +}; + + +/** + * Determines if the document is full screen. + * @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being + * queried. If not provided, use the current DOM. + * @return {boolean} Whether the document is full screen. + */ +goog.dom.fullscreen.isFullScreen = function(opt_domHelper) { + var doc = goog.dom.fullscreen.getDocument_(opt_domHelper); + return !!doc.webkitIsFullScreen || !!doc.mozFullScreen; +}; + + +/** + * Gets the document object of the dom. + * @param {!goog.dom.DomHelper=} opt_domHelper The DomHelper for the DOM being + * queried. If not provided, use the current DOM. + * @return {!Document} The dom document. + * @private + */ +goog.dom.fullscreen.getDocument_ = function(opt_domHelper) { + return opt_domHelper ? + opt_domHelper.getDocument() : + goog.dom.getDomHelper().getDocument(); +}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/multirange.js b/contexts/data/lib/closure-library/closure/goog/dom/multirange.js index 5eaa392..4e25269 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/multirange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/multirange.js @@ -142,6 +142,7 @@ goog.dom.MultiRange.prototype.clearCachedValues_ = function() { /** * @return {goog.dom.MultiRange} A clone of this range. + * @override */ goog.dom.MultiRange.prototype.clone = function() { return goog.dom.MultiRange.createFromBrowserRanges(this.browserRanges_); @@ -343,6 +344,7 @@ goog.dom.MultiRange.prototype.saveUsingDom = function() { * depending on the parameter. This will result in the number of ranges in this * multi range becoming 1. * @param {boolean} toAnchor Whether to collapse to the anchor. + * @override */ goog.dom.MultiRange.prototype.collapse = function(toAnchor) { if (!this.isCollapsed()) { @@ -384,6 +386,7 @@ goog.inherits(goog.dom.DomSavedMultiRange_, goog.dom.SavedRange); /** * @return {goog.dom.MultiRange} The restored range. + * @override */ goog.dom.DomSavedMultiRange_.prototype.restoreInternal = function() { var ranges = goog.array.map(this.savedRanges_, function(savedRange) { @@ -498,11 +501,7 @@ goog.dom.MultiRangeIterator.prototype.next = function() { }; -/** - * Replaces this iterator's values with values from another. - * @param {goog.dom.MultiRangeIterator} other The iterator to copy. - * @protected - */ +/** @override */ goog.dom.MultiRangeIterator.prototype.copyFrom = function(other) { this.iterators_ = goog.array.clone(other.iterators_); goog.dom.MultiRangeIterator.superClass_.copyFrom.call(this, other); @@ -511,6 +510,7 @@ goog.dom.MultiRangeIterator.prototype.copyFrom = function(other) { /** * @return {goog.dom.MultiRangeIterator} An identical iterator. + * @override */ goog.dom.MultiRangeIterator.prototype.clone = function() { var copy = new goog.dom.MultiRangeIterator(null); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/nodeiterator.js b/contexts/data/lib/closure-library/closure/goog/dom/nodeiterator.js index 7716b41..22453a0 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/nodeiterator.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/nodeiterator.js @@ -75,6 +75,7 @@ goog.inherits(goog.dom.NodeIterator, goog.dom.TagIterator); * Moves to the next position in the DOM tree. * @return {Node} Returns the next node, or throws a goog.iter.StopIteration * exception if the end of the iterator's range has been reached. + * @override */ goog.dom.NodeIterator.prototype.next = function() { do { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/nodeoffset.js b/contexts/data/lib/closure-library/closure/goog/dom/nodeoffset.js index 9180796..084d4b0 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/nodeoffset.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/nodeoffset.js @@ -70,6 +70,7 @@ goog.inherits(goog.dom.NodeOffset, goog.Disposable); /** * @return {string} A string representation of this object. + * @override */ goog.dom.NodeOffset.prototype.toString = function() { var strs = []; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/all-wcprops deleted file mode 100644 index ca751d5..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/all-wcprops +++ /dev/null @@ -1,95 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 48 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern -END -pattern_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/pattern_test.html -END -sequence.js -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/sequence.js -END -matcher_test.html -K 25 -svn:wc:ra_dav:version-url -V 66 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/matcher_test.html -END -tag.js -K 25 -svn:wc:ra_dav:version-url -V 55 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/tag.js -END -pattern.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/pattern.js -END -repeat.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/repeat.js -END -allchildren.js -K 25 -svn:wc:ra_dav:version-url -V 63 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/allchildren.js -END -matcher.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/matcher.js -END -text.js -K 25 -svn:wc:ra_dav:version-url -V 56 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/text.js -END -nodetype.js -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/nodetype.js -END -childmatches.js -K 25 -svn:wc:ra_dav:version-url -V 64 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/childmatches.js -END -starttag.js -K 25 -svn:wc:ra_dav:version-url -V 60 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/starttag.js -END -fulltag.js -K 25 -svn:wc:ra_dav:version-url -V 59 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/fulltag.js -END -abstractpattern.js -K 25 -svn:wc:ra_dav:version-url -V 67 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/abstractpattern.js -END -endtag.js -K 25 -svn:wc:ra_dav:version-url -V 58 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/endtag.js -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/entries b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/entries deleted file mode 100644 index 9bbd813..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/entries +++ /dev/null @@ -1,541 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/dom/pattern -http://closure-library.googlecode.com/svn - - - -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -pattern_test.html -file - - - - -2011-12-23T22:42:28.442330Z -0ee22a23e60b5d9d84bc77c473528345 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -21156 - -sequence.js -file - - - - -2011-12-23T22:42:28.443330Z -f81f21b6af6b1a6f29c239fbc1e4add0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4354 - -matcher_test.html -file - - - - -2011-12-23T22:42:28.444330Z -7394c50d44d2f961185f8c3d50245724 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5968 - -tag.js -file - - - - -2011-12-23T22:42:28.445330Z -3fb527f009acbf88f2aea69cb486e403 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4199 - -pattern.js -file - - - - -2011-12-23T22:42:28.446330Z -acaa43a7f147e5a662fb6ffc7e745727 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3256 - -repeat.js -file - - - - -2011-12-23T22:42:28.446330Z -f2b277d59a6eb581753f0f0e5d8b4fb0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -5506 - -allchildren.js -file - - - - -2011-12-23T22:42:28.446330Z -d7c33d304ae295e00df49695e8ab9cb1 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2043 - -callback -dir - -matcher.js -file - - - - -2011-12-23T22:42:28.446330Z -ffe05ff8b9aff57ee080819fa94374d9 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4299 - -text.js -file - - - - -2011-12-23T22:42:28.447330Z -66d0e84fba75b939be1f904b387978c7 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2136 - -nodetype.js -file - - - - -2011-12-23T22:42:28.447330Z -324021892dc63efd55ec8332de40e729 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1893 - -childmatches.js -file - - - - -2011-12-23T22:42:28.447330Z -65f09c4356d25bab638244ae5a8b4afe -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -4565 - -starttag.js -file - - - - -2011-12-23T22:42:28.447330Z -5719dc4b7ee18a8627b260f7913e5d8b -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1965 - -fulltag.js -file - - - - -2011-12-23T22:42:28.448330Z -d37bde6ff3151b55fc3df44a2578144c -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -3177 - -abstractpattern.js -file - - - - -2011-12-23T22:42:28.448330Z -93da7293de0954b4e127d388a1e42499 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1619 - -endtag.js -file - - - - -2011-12-23T22:42:28.448330Z -4a857170518220460dbc381b08d25b8a -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1954 - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/abstractpattern.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/abstractpattern.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/abstractpattern.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/allchildren.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/allchildren.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/allchildren.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/childmatches.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/childmatches.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/childmatches.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/endtag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/endtag.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/endtag.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/fulltag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/fulltag.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/fulltag.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/matcher_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/nodetype.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/nodetype.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/nodetype.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/pattern_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/repeat.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/repeat.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/repeat.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/sequence.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/sequence.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/sequence.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/starttag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/starttag.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/starttag.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/tag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/tag.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/tag.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/text.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/text.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/prop-base/text.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/abstractpattern.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/abstractpattern.js.svn-base deleted file mode 100644 index 6015b09..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/abstractpattern.js.svn-base +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern base class. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.AbstractPattern'); - -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Base pattern class for DOM matching. - * - * @constructor - */ -goog.dom.pattern.AbstractPattern = function() { -}; - - -/** - * The first node matched by this pattern. - * @type {Node} - */ -goog.dom.pattern.AbstractPattern.prototype.matchedNode = null; - - -/** - * Reset any internal state this pattern keeps. - */ -goog.dom.pattern.AbstractPattern.prototype.reset = function() { - // The base implementation does nothing. -}; - - -/** - * Test whether this pattern matches the given token. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} {@code MATCH} if the pattern matches. - */ -goog.dom.pattern.AbstractPattern.prototype.matchToken = function(token, type) { - return goog.dom.pattern.MatchType.NO_MATCH; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/allchildren.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/allchildren.js.svn-base deleted file mode 100644 index 75ebb5e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/allchildren.js.svn-base +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match any children of a tag. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.AllChildren'); - -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches any nodes at or below the current tree depth. - * - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.AllChildren = function() { -}; -goog.inherits(goog.dom.pattern.AllChildren, goog.dom.pattern.AbstractPattern); - - -/** - * Tracks the matcher's depth to detect the end of the tag. - * - * @type {number} - * @private - */ -goog.dom.pattern.AllChildren.prototype.depth_ = 0; - - -/** - * Test whether the given token is on the same level. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the - * same level or deeper and {@code BACKTRACK_MATCH} if not. - */ -goog.dom.pattern.AllChildren.prototype.matchToken = function(token, type) { - this.depth_ += type; - - if (this.depth_ >= 0) { - return goog.dom.pattern.MatchType.MATCHING; - } else { - this.depth_ = 0; - return goog.dom.pattern.MatchType.BACKTRACK_MATCH; - } -}; - - -/** - * Reset any internal state this pattern keeps. - */ -goog.dom.pattern.AllChildren.prototype.reset = function() { - this.depth_ = 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/childmatches.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/childmatches.js.svn-base deleted file mode 100644 index 7315ebb..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/childmatches.js.svn-base +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match any children of a tag, and - * specifically collect those that match a child pattern. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.ChildMatches'); - -goog.require('goog.dom.pattern.AllChildren'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches any nodes at or below the current tree depth. - * - * @param {goog.dom.pattern.AbstractPattern} childPattern Pattern to collect - * child matches of. - * @param {number=} opt_minimumMatches Enforce a minimum nuber of matches. - * Defaults to 0. - * @constructor - * @extends {goog.dom.pattern.AllChildren} - */ -goog.dom.pattern.ChildMatches = function(childPattern, opt_minimumMatches) { - this.childPattern_ = childPattern; - this.matches = []; - this.minimumMatches_ = opt_minimumMatches || 0; - goog.dom.pattern.AllChildren.call(this); -}; -goog.inherits(goog.dom.pattern.ChildMatches, goog.dom.pattern.AllChildren); - - -/** - * Array of matched child nodes. - * - * @type {Array.<Node>} - */ -goog.dom.pattern.ChildMatches.prototype.matches; - - -/** - * Minimum number of matches. - * - * @type {number} - * @private - */ -goog.dom.pattern.ChildMatches.prototype.minimumMatches_ = 0; - - -/** - * The child pattern to collect matches from. - * - * @type {goog.dom.pattern.AbstractPattern} - * @private - */ -goog.dom.pattern.ChildMatches.prototype.childPattern_; - - -/** - * Whether the pattern has recently matched or failed to match and will need to - * be reset when starting a new round of matches. - * - * @type {boolean} - * @private - */ -goog.dom.pattern.ChildMatches.prototype.needsReset_ = false; - - -/** - * Test whether the given token is on the same level. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the - * same level or deeper and {@code BACKTRACK_MATCH} if not. - */ -goog.dom.pattern.ChildMatches.prototype.matchToken = function(token, type) { - // Defer resets so we maintain our matches array until the last possible time. - if (this.needsReset_) { - this.reset(); - } - - // Call the super-method to ensure we stay in the child tree. - var status = - goog.dom.pattern.AllChildren.prototype.matchToken.apply(this, arguments); - - switch (status) { - case goog.dom.pattern.MatchType.MATCHING: - var backtrack = false; - - switch (this.childPattern_.matchToken(token, type)) { - case goog.dom.pattern.MatchType.BACKTRACK_MATCH: - backtrack = true; - case goog.dom.pattern.MatchType.MATCH: - // Collect the match. - this.matches.push(this.childPattern_.matchedNode); - break; - - default: - // Keep trying if we haven't hit a terminal state. - break; - } - - if (backtrack) { - // The only interesting result is a MATCH, since BACKTRACK_MATCH means - // we are hitting an infinite loop on something like a Repeat(0). - if (this.childPattern_.matchToken(token, type) == - goog.dom.pattern.MatchType.MATCH) { - this.matches.push(this.childPattern_.matchedNode); - } - } - return goog.dom.pattern.MatchType.MATCHING; - - case goog.dom.pattern.MatchType.BACKTRACK_MATCH: - // TODO(robbyw): this should return something like BACKTRACK_NO_MATCH - // when we don't meet our minimum. - this.needsReset_ = true; - return (this.matches.length >= this.minimumMatches_) ? - goog.dom.pattern.MatchType.BACKTRACK_MATCH : - goog.dom.pattern.MatchType.NO_MATCH; - - default: - this.needsReset_ = true; - return status; - } -}; - - -/** - * Reset any internal state this pattern keeps. - */ -goog.dom.pattern.ChildMatches.prototype.reset = function() { - this.needsReset_ = false; - this.matches.length = 0; - this.childPattern_.reset(); - goog.dom.pattern.AllChildren.prototype.reset.call(this); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/endtag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/endtag.js.svn-base deleted file mode 100644 index 75f9952..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/endtag.js.svn-base +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match the end of a tag. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.EndTag'); - -goog.require('goog.dom.TagWalkType'); -goog.require('goog.dom.pattern.Tag'); - - - -/** - * Pattern object that matches a closing tag. - * - * @param {string|RegExp} tag Name of the tag. Also will accept a regular - * expression to match against the tag name. - * @param {Object=} opt_attrs Optional map of attribute names to desired values. - * This pattern will only match when all attributes are present and match - * the string or regular expression value provided here. - * @param {Object=} opt_styles Optional map of CSS style names to desired - * values. This pattern will only match when all styles are present and - * match the string or regular expression value provided here. - * @param {Function=} opt_test Optional function that takes the element as a - * parameter and returns true if this pattern should match it. - * @constructor - * @extends {goog.dom.pattern.Tag} - */ -goog.dom.pattern.EndTag = function(tag, opt_attrs, opt_styles, opt_test) { - goog.dom.pattern.Tag.call( - this, - tag, - goog.dom.TagWalkType.END_TAG, - opt_attrs, - opt_styles, - opt_test); -}; -goog.inherits(goog.dom.pattern.EndTag, goog.dom.pattern.Tag); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/fulltag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/fulltag.js.svn-base deleted file mode 100644 index 8296c83..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/fulltag.js.svn-base +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a tag and all of its children. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.FullTag'); - -goog.require('goog.dom.pattern.MatchType'); -goog.require('goog.dom.pattern.StartTag'); -goog.require('goog.dom.pattern.Tag'); - - - -/** - * Pattern object that matches a full tag including all its children. - * - * @param {string|RegExp} tag Name of the tag. Also will accept a regular - * expression to match against the tag name. - * @param {Object=} opt_attrs Optional map of attribute names to desired values. - * This pattern will only match when all attributes are present and match - * the string or regular expression value provided here. - * @param {Object=} opt_styles Optional map of CSS style names to desired - * values. This pattern will only match when all styles are present and - * match the string or regular expression value provided here. - * @param {Function=} opt_test Optional function that takes the element as a - * parameter and returns true if this pattern should match it. - * @constructor - * @extends {goog.dom.pattern.StartTag} - */ -goog.dom.pattern.FullTag = function(tag, opt_attrs, opt_styles, opt_test) { - goog.dom.pattern.StartTag.call( - this, - tag, - opt_attrs, - opt_styles, - opt_test); -}; -goog.inherits(goog.dom.pattern.FullTag, goog.dom.pattern.StartTag); - - -/** - * Tracks the matcher's depth to detect the end of the tag. - * - * @type {number} - * @private - */ -goog.dom.pattern.FullTag.prototype.depth_ = 0; - - -/** - * Test whether the given token is a start tag token which matches the tag name, - * style, and attributes provided in the constructor. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> at the end of our - * tag, <code>MATCHING</code> if we are within the tag, and - * <code>NO_MATCH</code> if the starting tag does not match. - */ -goog.dom.pattern.FullTag.prototype.matchToken = function(token, type) { - if (!this.depth_) { - // If we have not yet started, make sure we match as a StartTag. - if (goog.dom.pattern.Tag.prototype.matchToken.call(this, token, type)) { - this.depth_ = type; - return goog.dom.pattern.MatchType.MATCHING; - - } else { - return goog.dom.pattern.MatchType.NO_MATCH; - } - } else { - this.depth_ += type; - - return this.depth_ ? - goog.dom.pattern.MatchType.MATCHING : - goog.dom.pattern.MatchType.MATCH; - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher.js.svn-base deleted file mode 100644 index c0c87a3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher.js.svn-base +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern matcher. Allows for simple searching of DOM - * using patterns descended from {@link goog.dom.pattern.AbstractPattern}. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.Matcher'); - -goog.require('goog.dom.TagIterator'); -goog.require('goog.dom.pattern.MatchType'); -goog.require('goog.iter'); - - -// TODO(robbyw): Allow for backtracks of size > 1. - - - -/** - * Given a set of patterns and a root node, this class tests the patterns in - * parallel. - * - * It is not (yet) a smart matcher - it doesn't do any advanced backtracking. - * Given the pattern <code>DIV, SPAN</code> the matcher will not match - * <code>DIV, DIV, SPAN</code> because it starts matching at the first - * <code>DIV</code>, fails to match <code>SPAN</code> at the second, and never - * backtracks to try again. - * - * It is also possible to have a set of complex patterns that when matched in - * parallel will miss some possible matches. Running multiple times will catch - * all matches eventually. - * - * @constructor - */ -goog.dom.pattern.Matcher = function() { - this.patterns_ = []; - this.callbacks_ = []; -}; - - -/** - * Array of patterns to attempt to match in parallel. - * - * @type {Array.<goog.dom.pattern.AbstractPattern>} - * @private - */ -goog.dom.pattern.Matcher.prototype.patterns_; - - -/** - * Array of callbacks to call when a pattern is matched. The indexing is the - * same as the {@link #patterns_} array. - * - * @type {Array.<Function>} - * @private - */ -goog.dom.pattern.Matcher.prototype.callbacks_; - - -/** - * Adds a pattern to be matched. The callback can return an object whose keys - * are processing instructions. - * - * @param {goog.dom.pattern.AbstractPattern} pattern The pattern to add. - * @param {Function} callback Function to call when a match is found. Uses - * the above semantics. - */ -goog.dom.pattern.Matcher.prototype.addPattern = function(pattern, callback) { - this.patterns_.push(pattern); - this.callbacks_.push(callback); -}; - - -/** - * Resets all the patterns. - * - * @private - */ -goog.dom.pattern.Matcher.prototype.reset_ = function() { - for (var i = 0, len = this.patterns_.length; i < len; i++) { - this.patterns_[i].reset(); - } -}; - - -/** - * Test the given node against all patterns. - * - * @param {goog.dom.TagIterator} position A position in a node walk that is - * located at the token to process. - * @return {boolean} Whether a pattern modified the position or tree - * and its callback resulted in DOM structure or position modification. - * @private - */ -goog.dom.pattern.Matcher.prototype.matchToken_ = function(position) { - for (var i = 0, len = this.patterns_.length; i < len; i++) { - var pattern = this.patterns_[i]; - switch (pattern.matchToken(position.node, position.tagType)) { - case goog.dom.pattern.MatchType.MATCH: - case goog.dom.pattern.MatchType.BACKTRACK_MATCH: - var callback = this.callbacks_[i]; - - // Callbacks are allowed to modify the current position, but must - // return true if the do. - if (callback(pattern.matchedNode, position, pattern)) { - return true; - } - - default: - // Do nothing. - break; - } - } - - return false; -}; - - -/** - * Match the set of patterns against a match tree. - * - * @param {Node} node The root node of the tree to match. - */ -goog.dom.pattern.Matcher.prototype.match = function(node) { - var position = new goog.dom.TagIterator(node); - - this.reset_(); - - goog.iter.forEach(position, function() { - while (this.matchToken_(position)) { - // Since we've moved, our old pattern statuses don't make sense any more. - // Reset them. - this.reset_(); - } - }, this); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher_test.html.svn-base deleted file mode 100644 index 67ef94c..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/matcher_test.html.svn-base +++ /dev/null @@ -1,204 +0,0 @@ -<!DOCTYPE html> - - -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.pattern.Matcher Tests</title> -<script src="../../base.js"></script> -<script type="text/javascript"> - goog.require('goog.testing.jsunit'); - - goog.require('goog.dom.pattern.EndTag'); - goog.require('goog.dom.pattern.FullTag'); - goog.require('goog.dom.pattern.Matcher'); - goog.require('goog.dom.pattern.Repeat'); - goog.require('goog.dom.pattern.Sequence'); - goog.require('goog.dom.pattern.StartTag'); - goog.require('goog.dom.pattern.callback.Counter'); - goog.require('goog.dom.pattern.callback.Test'); -</script> -</head> -<body> - <p id="p1"> - <span id="span1" style="color: red"></span> - </p> - <p id="p2"> - <span id="span2" style="color: blue">x</span> - </p> - <p id="p3">Text</p> - <p id="p4">Other Text</p> - <span></span> - - <div id="div1"><b>x</b><b>y</b><i>z</i></div> - - <p id="p5"><b id="b1">x</b><b id="b2">y</b><i id="i1">z</i></p> - -<script type="text/javascript"> - function testMatcherAndStartTag() { - var pattern = new goog.dom.pattern.StartTag('P'); - - var counter = new goog.dom.pattern.callback.Counter(); - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, counter.getCallback()); - matcher.match(document.body); - - assertEquals('StartTag(p) should match 5 times in body', 5, - counter.count); - } - - function testMatcherAndStartTagTwice() { - var pattern = new goog.dom.pattern.StartTag('P'); - - var counter = new goog.dom.pattern.callback.Counter(); - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, counter.getCallback()); - matcher.match(document.body); - - assertEquals('StartTag(p) should match 5 times in body', 5, - counter.count); - - // Make sure no state got mangled. - counter.reset(); - matcher.match(document.body); - - assertEquals('StartTag(p) should match 5 times in body again', 5, - counter.count); - } - - function testMatcherAndStartTagAttributes() { - var pattern = new goog.dom.pattern.StartTag('SPAN', {id: /./}); - - var counter = new goog.dom.pattern.callback.Counter(); - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, counter.getCallback()); - matcher.match(document.body); - - assertEquals('StartTag(span,id) should match 2 times in body', 2, - counter.count); - } - - function testMatcherWithTwoPatterns() { - var pattern1 = new goog.dom.pattern.StartTag('SPAN'); - var pattern2 = new goog.dom.pattern.StartTag('P'); - - var counter = new goog.dom.pattern.callback.Counter(); - - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern1, counter.getCallback()); - matcher.addPattern(pattern2, counter.getCallback()); - - matcher.match(document.body); - - assertEquals('StartTag(span|p) should match 8 times in body', 8, - counter.count); - } - - function testMatcherWithQuit() { - var pattern1 = new goog.dom.pattern.StartTag('SPAN'); - var pattern2 = new goog.dom.pattern.StartTag('P'); - - var count = 0; - var callback = function(node, position) { - if (node.nodeName == 'SPAN') { - throw goog.iter.StopIteration; - return true; - } - count++; - }; - - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern1, callback); - matcher.addPattern(pattern2, callback); - - matcher.match(document.body); - - assertEquals('Stopped span|p should match 1 time in body', 1, count); - } - - function testMatcherWithReplace() { - var pattern1 = new goog.dom.pattern.StartTag('B'); - var pattern2 = new goog.dom.pattern.StartTag('I'); - - var count = 0; - var callback = function(node, position) { - count++; - if (node.nodeName == 'B') { - var i = goog.dom.createDom('I'); - node.parentNode.insertBefore(i, node); - goog.dom.removeNode(node); - - position.setPosition(i); - - return true; - } - }; - - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern1, callback); - matcher.addPattern(pattern2, callback); - - matcher.match(goog.dom.getElement('div1')); - - assertEquals('i|b->i should match 5 times in div1', 5, count); - } - - function testMatcherAndFullTag() { - var pattern = new goog.dom.pattern.FullTag('P'); - - var test = new goog.dom.pattern.callback.Test(); - - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, test.getCallback()); - - matcher.match(goog.dom.getElement('p1')); - - assert('FullTag(p) should match on p1', test.matched); - - test.reset(); - matcher.match(goog.dom.getElement('div1')); - - assert('FullTag(p) should not match on div1', !test.matched); - } - - function testMatcherAndSequence() { - var pattern = new goog.dom.pattern.Sequence([ - new goog.dom.pattern.StartTag('P'), - new goog.dom.pattern.StartTag('SPAN'), - new goog.dom.pattern.EndTag('SPAN'), - new goog.dom.pattern.EndTag('P') - ], true); - - var counter = new goog.dom.pattern.callback.Counter(); - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, counter.getCallback()); - matcher.match(document.body); - - assertEquals('Sequence should match 1 times in body', 1, counter.count); - } - - function testMatcherAndRepeatFullTag() { - var pattern = new goog.dom.pattern.Repeat( - new goog.dom.pattern.FullTag('P'), 1); - - var count = 0; - var tcount = 0; - var matcher = new goog.dom.pattern.Matcher(); - matcher.addPattern(pattern, function() { - count++; - tcount += pattern.count; - }); - matcher.match(document.body); - - assertEquals('Repeated p should match 2 times in body', 2, count); - assertEquals('Repeated p should match 5 total times in body', 5, tcount); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/nodetype.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/nodetype.js.svn-base deleted file mode 100644 index 1038f96..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/nodetype.js.svn-base +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a node of the given type. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.NodeType'); - -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches any node of the given type. - * @param {goog.dom.NodeType} nodeType The node type to match. - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.NodeType = function(nodeType) { - /** - * The node type to match. - * @type {goog.dom.NodeType} - * @private - */ - this.nodeType_ = nodeType; -}; -goog.inherits(goog.dom.pattern.NodeType, goog.dom.pattern.AbstractPattern); - - -/** - * Test whether the given token is a text token which matches the string or - * regular expression provided in the constructor. - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern - * matches, <code>NO_MATCH</code> otherwise. - */ -goog.dom.pattern.NodeType.prototype.matchToken = function(token, type) { - return token.nodeType == this.nodeType_ ? - goog.dom.pattern.MatchType.MATCH : - goog.dom.pattern.MatchType.NO_MATCH; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern.js.svn-base deleted file mode 100644 index 19f4d1b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern.js.svn-base +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM patterns. Allows for description of complex DOM patterns - * using regular expression like constructs. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern'); -goog.provide('goog.dom.pattern.MatchType'); - - -/** - * Regular expression for breaking text nodes. - * @type {RegExp} - */ -goog.dom.pattern.BREAKING_TEXTNODE_RE = /^\s*$/; - - -/** - * Utility function to match a string against either a string or a regular - * expression. - * - * @param {string|RegExp} obj Either a string or a regular expression. - * @param {string} str The string to match. - * @return {boolean} Whether the strings are equal, or if the string matches - * the regular expression. - */ -goog.dom.pattern.matchStringOrRegex = function(obj, str) { - if (goog.isString(obj)) { - // Match a string - return str == obj; - } else { - // Match a regular expression - return !!(str && str.match(obj)); - } -}; - - -/** - * Utility function to match a DOM attribute against either a string or a - * regular expression. Conforms to the interface spec for - * {@link goog.object#every}. - * - * @param {string|RegExp} elem Either a string or a regular expression. - * @param {string} index The attribute name to match. - * @param {Object} orig The original map of matches to test. - * @return {boolean} Whether the strings are equal, or if the attribute matches - * the regular expression. - * @this {Element} Called using goog.object every on an Element. - */ -goog.dom.pattern.matchStringOrRegexMap = function(elem, index, orig) { - return goog.dom.pattern.matchStringOrRegex(elem, - index in this ? this[index] : - (this.getAttribute ? this.getAttribute(index) : null)); -}; - - -/** - * When matched to a token, a pattern may return any of the following statuses: - * <ol> - * <li><code>NO_MATCH</code> - The pattern does not match. This is the only - * value that evaluates to <code>false</code> in a boolean context. - * <li><code>MATCHING</code> - The token is part of an incomplete match. - * <li><code>MATCH</code> - The token completes a match. - * <li><code>BACKTRACK_MATCH</code> - The token does not match, but indicates - * the end of a repetitive match. For instance, in regular expressions, - * the pattern <code>/a+/</code> would match <code>'aaaaaaaab'</code>. - * Every <code>'a'</code> token would give a status of - * <code>MATCHING</code> while the <code>'b'</code> token would give a - * status of <code>BACKTRACK_MATCH</code>. - * </ol> - * @enum {number} - */ -goog.dom.pattern.MatchType = { - NO_MATCH: 0, - MATCHING: 1, - MATCH: 2, - BACKTRACK_MATCH: 3 -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern_test.html.svn-base deleted file mode 100644 index 542e713..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/pattern_test.html.svn-base +++ /dev/null @@ -1,614 +0,0 @@ -<!DOCTYPE html> - - -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.pattern Tests</title> -<script src="../../base.js"></script> -<script type="text/javascript"> - goog.require('goog.testing.jsunit'); - - goog.require('goog.dom.TagWalkType'); - goog.require('goog.dom.pattern.AllChildren'); - goog.require('goog.dom.pattern.ChildMatches'); - goog.require('goog.dom.pattern.EndTag'); - goog.require('goog.dom.pattern.FullTag'); - goog.require('goog.dom.pattern.MatchType'); - goog.require('goog.dom.pattern.NodeType'); - goog.require('goog.dom.pattern.Repeat'); - goog.require('goog.dom.pattern.Sequence'); - goog.require('goog.dom.pattern.StartTag'); - goog.require('goog.dom.pattern.Text'); -</script> -</head> -<body> - <div id="div1"> - <span id="span1" style="color: red"></span> - </div> - <div id="div2"> - <span id="span2" style="color: blue">x</span> - </div> - <div id="div3">Text</div> - <div id="div4">Other Text</div> - <span></span> - - <!-- This chunk gets deleted! --> - <p id="p1"><b>x</b><b>y</b><i>z</i></p> - - <div id="div5"><b id="b1">x</b><b id="b2">y</b><i id="i1">z</i></div> - - <span id="span3"><span><span>X</span></span></span> - - <div id="nodeTypes"><!-- Comment -->Text</div> - -<script type="text/javascript"> - // TODO(robbyw): write a test that checks if backtracking works in Sequence - - function testStartTag() { - var pattern = new goog.dom.pattern.StartTag('DIV'); - assertEquals( - 'StartTag(div) should match div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(div) should not match span', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(div) should not match /div', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - } - - function testStartTagCase() { - var pattern = new goog.dom.pattern.StartTag('diV'); - assertEquals( - 'StartTag(diV) should match div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(diV) should not match span', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - } - - function testStartTagRegex() { - var pattern = new goog.dom.pattern.StartTag(/D/); - assertEquals( - 'StartTag(/D/) should match div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(/D/) should not match span', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(/D/) should not match /div', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - } - - function testStartTagAttributes() { - var pattern = new goog.dom.pattern.StartTag('DIV',{id: 'div1'}); - assertEquals( - 'StartTag(div,id:div1) should match div1', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals('StartTag(div,id:div2) should not match div1', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div2'), - goog.dom.TagWalkType.START_TAG)); - } - - function testStartTagStyle() { - var pattern = new goog.dom.pattern.StartTag('SPAN',null,{color: 'red'}); - assertEquals( - 'StartTag(span,null,color:red) should match span1', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(span,null,color:blue) should not match span1', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('span2'), - goog.dom.TagWalkType.START_TAG)); - } - - function testStartTagAttributeRegex() { - var pattern = new goog.dom.pattern.StartTag('SPAN',{id: /span\d/}); - assertEquals( - 'StartTag(span,id:/span\\d/) should match span1', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'StartTag(span,id:/span\\d/) should match span2', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - } - - function testEndTag() { - var pattern = new goog.dom.pattern.EndTag('DIV'); - assertEquals( - 'EndTag should match div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - } - - function testEndTagRegex() { - var pattern = new goog.dom.pattern.EndTag(/D/); - assertEquals( - 'EndTag(/D/) should match /div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'EndTag(/D/) should not match /span', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'EndTag(/D/) should not match div', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - } - - function testChildMatches() { - var pattern = new goog.dom.pattern.ChildMatches( - new goog.dom.pattern.StartTag('DIV'), 2); - - assertEquals( - 'ChildMatches should match div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'ChildMatches should match /div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'ChildMatches should match div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div2'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'ChildMatches should match /div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div2'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'ChildMatches should finish match at /body', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - document.body, - goog.dom.TagWalkType.END_TAG)); - - assertEquals( - 'ChildMatches should match div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div2'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'ChildMatches should match /div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div2'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'ChildMatches should fail to match at /body: not enough child matches', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - document.body, - goog.dom.TagWalkType.END_TAG)); - } - - function testFullTag() { - var pattern = new goog.dom.pattern.FullTag('DIV'); - assertEquals( - 'FullTag(div) should match div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'FullTag(div) should match /div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - - assertEquals( - 'FullTag(div) should start match at div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'FullTag(div) should continue to match span', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'FullTag(div) should continue to match /span', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'FullTag(div) should finish match at /div', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - } - - function testAllChildren() { - var pattern = new goog.dom.pattern.AllChildren(); - assertEquals( - 'AllChildren(div) should match div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'AllChildren(div) should match /div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'AllChildren(div) should match at /body', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - document.body, - goog.dom.TagWalkType.END_TAG)); - - assertEquals( - 'AllChildren(div) should start match at div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'AllChildren(div) should continue to match span', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'AllChildren(div) should continue to match /span', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'AllChildren(div) should continue to match at /div', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'AllChildren(div) should finish match at /body', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - document.body, - goog.dom.TagWalkType.END_TAG)); - } - - function testText() { - var pattern = new goog.dom.pattern.Text('Text'); - assertEquals( - 'Text should match div3/text()', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div3').firstChild, - goog.dom.TagWalkType.OTHER)); - assertEquals( - 'Text should not match div4/text()', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div4').firstChild, - goog.dom.TagWalkType.OTHER)); - assertEquals( - 'Text should not match div3', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div3'), - goog.dom.TagWalkType.START_TAG)); - - } - - function testTextRegex() { - var pattern = new goog.dom.pattern.Text(/Text/); - assertEquals( - 'Text(regex) should match div3/text()', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div3').firstChild, - goog.dom.TagWalkType.OTHER)); - assertEquals( - 'Text(regex) should match div4/text()', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div4').firstChild, - goog.dom.TagWalkType.OTHER)); - } - - function testNodeType() { - var pattern = new goog.dom.pattern.NodeType(goog.dom.NodeType.COMMENT); - assertEquals('Comment matcher should match a comment', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('nodeTypes').firstChild, - goog.dom.TagWalkType.OTHER)); - assertEquals('Comment matcher should not match a text node', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('nodeTypes').lastChild, - goog.dom.TagWalkType.OTHER)); - } - - function testSequence() { - var pattern = new goog.dom.pattern.Sequence([ - new goog.dom.pattern.StartTag('DIV'), - new goog.dom.pattern.StartTag('SPAN'), - new goog.dom.pattern.EndTag('SPAN'), - new goog.dom.pattern.EndTag('DIV')]); - - assertEquals( - 'Sequence[0] should match div1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[1] should match span1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[2] should match /span1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'Sequence[3] should match /div1', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - - assertEquals( - 'Sequence[0] should match div1 again', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[1] should match span1 again', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[2] should match /span1 again', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'Sequence[3] should match /div1 again', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - - assertEquals( - 'Sequence[0] should match div1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[1] should not match div1', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - - assertEquals( - 'Sequence[0] should match div1 after failure', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[1] should match span1 after failure', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[2] should match /span1 after failure', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('span1'), - goog.dom.TagWalkType.END_TAG)); - assertEquals( - 'Sequence[3] should match /div1 after failure', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('div1'), - goog.dom.TagWalkType.END_TAG)); - } - - function testRepeat() { - var pattern = new goog.dom.pattern.Repeat( - new goog.dom.pattern.StartTag('B')); - - // Note: this test does not mimic an actual matcher because it is only - // passing the START_TAG events. - - assertEquals( - 'Repeat[B] should match b1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('b1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B] should match b2', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('b2'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B] should backtrack match i1', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - goog.dom.getElement('i1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B] should have match count of 2', - 2, - pattern.count); - - assertEquals( - 'Repeat[B] should backtrack match i1 even with no b matches', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - goog.dom.getElement('i1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B] should have match count of 0', - 0, - pattern.count); - } - - function testRepeatWithMinimum() { - var pattern = new goog.dom.pattern.Repeat( - new goog.dom.pattern.StartTag('B'), 1); - - // Note: this test does not mimic an actual matcher because it is only - // passing the START_TAG events. - - assertEquals( - 'Repeat[B,1] should match b1', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('b1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B,1] should match b2', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken( - goog.dom.getElement('b2'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B,1] should backtrack match i1', - goog.dom.pattern.MatchType.BACKTRACK_MATCH, - pattern.matchToken( - goog.dom.getElement('i1'), - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Repeat[B,1] should have match count of 2', - 2, - pattern.count); - - assertEquals( - 'Repeat[B,1] should not match i1', - goog.dom.pattern.MatchType.NO_MATCH, - pattern.matchToken( - goog.dom.getElement('i1'), - goog.dom.TagWalkType.START_TAG)); - } - - function testRepeatWithMaximum() { - var pattern = new goog.dom.pattern.Repeat( - new goog.dom.pattern.StartTag('B'), 1, 1); - - // Note: this test does not mimic an actual matcher because it is only - // passing the START_TAG events. - - assertEquals( - 'Repeat[B,1] should match b1', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken( - goog.dom.getElement('b1'), - goog.dom.TagWalkType.START_TAG)); - } - - function testSequenceBacktrack() { - var pattern = new goog.dom.pattern.Sequence([ - new goog.dom.pattern.Repeat(new goog.dom.pattern.StartTag('SPAN')), - new goog.dom.pattern.Text('X')]); - - var root = goog.dom.getElement('span3'); - assertEquals( - 'Sequence[Repeat[SPAN],"X"] should match span3', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken(root, goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken(root.firstChild, - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild.firstChild', - goog.dom.pattern.MatchType.MATCHING, - pattern.matchToken(root.firstChild.firstChild, - goog.dom.TagWalkType.START_TAG)); - assertEquals( - 'Sequence[Repeat[SPAN],"X"] should finish match text node', - goog.dom.pattern.MatchType.MATCH, - pattern.matchToken(root.firstChild.firstChild.firstChild, - goog.dom.TagWalkType.OTHER)); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/repeat.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/repeat.js.svn-base deleted file mode 100644 index d7cfbcc..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/repeat.js.svn-base +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a tag and all of its children. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.Repeat'); - -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches a repetition of another pattern. - * @param {goog.dom.pattern.AbstractPattern} pattern The pattern to - * repetitively match. - * @param {number=} opt_minimum The minimum number of times to match. Defaults - * to 0. - * @param {number=} opt_maximum The maximum number of times to match. Defaults - * to unlimited. - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.Repeat = function(pattern, - opt_minimum, - opt_maximum) { - this.pattern_ = pattern; - this.minimum_ = opt_minimum || 0; - this.maximum_ = opt_maximum || null; - this.matches = []; -}; -goog.inherits(goog.dom.pattern.Repeat, goog.dom.pattern.AbstractPattern); - - -/** - * Pattern to repetitively match. - * - * @type {goog.dom.pattern.AbstractPattern} - * @private - */ -goog.dom.pattern.Repeat.prototype.pattern_; - - -/** - * Minimum number of times to match the pattern. - * - * @private - */ -goog.dom.pattern.Repeat.prototype.minimum_ = 0; - - -/** - * Optional maximum number of times to match the pattern. A {@code null} value - * will be treated as infinity. - * - * @type {?number} - * @private - */ -goog.dom.pattern.Repeat.prototype.maximum_ = 0; - - -/** - * Number of times the pattern has matched. - * - * @type {number} - */ -goog.dom.pattern.Repeat.prototype.count = 0; - - -/** - * Whether the pattern has recently matched or failed to match and will need to - * be reset when starting a new round of matches. - * - * @type {boolean} - * @private - */ -goog.dom.pattern.Repeat.prototype.needsReset_ = false; - - -/** - * The matched nodes. - * - * @type {Array.<Node>} - */ -goog.dom.pattern.Repeat.prototype.matches; - - -/** - * Test whether the given token continues a repeated series of matches of the - * pattern given in the constructor. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern - * matches, <code>BACKTRACK_MATCH</code> if the pattern does not match - * but already had accumulated matches, <code>MATCHING</code> if the pattern - * starts a match, and <code>NO_MATCH</code> if the pattern does not match. - * @suppress {missingProperties} See the broken line below. - */ -goog.dom.pattern.Repeat.prototype.matchToken = function(token, type) { - // Reset if we're starting a new match - if (this.needsReset_) { - this.reset(); - } - - // If the option is set, ignore any whitespace only text nodes - if (token.nodeType == goog.dom.NodeType.TEXT && - token.nodeValue.match(/^\s+$/)) { - return goog.dom.pattern.MatchType.MATCHING; - } - - switch (this.pattern_.matchToken(token, type)) { - case goog.dom.pattern.MatchType.MATCH: - // Record the first token we match. - if (this.count == 0) { - this.matchedNode = token; - } - - // Mark the match - this.count++; - - // Add to the list - this.matches.push(this.pattern_.matchedNode); - - // Check if this match hits our maximum - if (this.maximum_ !== null && this.count == this.maximum_) { - this.needsReset_ = true; - return goog.dom.pattern.MatchType.MATCH; - } else { - return goog.dom.pattern.MatchType.MATCHING; - } - - case goog.dom.pattern.MatchType.MATCHING: - // This can happen when our child pattern is a sequence or a repetition. - return goog.dom.pattern.MatchType.MATCHING; - - case goog.dom.pattern.MatchType.BACKTRACK_MATCH: - // This happens if our child pattern is repetitive too. - // TODO(robbyw): Backtrack further if necessary. - this.count++; - - // NOTE(nicksantos): This line of code is broken. this.patterns_ doesn't - // exist, and this.currentPosition_ doesn't exit. When this is fixed, - // remove the missingProperties suppression above. - if (this.currentPosition_ == this.patterns_.length) { - this.needsReset_ = true; - return goog.dom.pattern.MatchType.BACKTRACK_MATCH; - } else { - // Retry the same token on the next iteration of the child pattern. - return this.matchToken(token, type); - } - - default: - this.needsReset_ = true; - if (this.count >= this.minimum_) { - return goog.dom.pattern.MatchType.BACKTRACK_MATCH; - } else { - return goog.dom.pattern.MatchType.NO_MATCH; - } - } -}; - - -/** - * Reset any internal state this pattern keeps. - */ -goog.dom.pattern.Repeat.prototype.reset = function() { - this.pattern_.reset(); - this.count = 0; - this.needsReset_ = false; - this.matches.length = 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/sequence.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/sequence.js.svn-base deleted file mode 100644 index 7f2ea3e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/sequence.js.svn-base +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a sequence of other patterns. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.Sequence'); - -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches a sequence of other patterns. - * - * @param {Array.<goog.dom.pattern.AbstractPattern>} patterns Ordered array of - * patterns to match. - * @param {boolean=} opt_ignoreWhitespace Optional flag to ignore text nodes - * consisting entirely of whitespace. The default is to not ignore them. - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.Sequence = function(patterns, opt_ignoreWhitespace) { - this.patterns = patterns; - this.ignoreWhitespace_ = !!opt_ignoreWhitespace; -}; -goog.inherits(goog.dom.pattern.Sequence, goog.dom.pattern.AbstractPattern); - - -/** - * Ordered array of patterns to match. - * - * @type {Array.<goog.dom.pattern.AbstractPattern>} - */ -goog.dom.pattern.Sequence.prototype.patterns; - - -/** - * Position in the patterns array we have reached by successful matches. - * - * @type {number} - * @private - */ -goog.dom.pattern.Sequence.prototype.currentPosition_ = 0; - - -/** - * Whether or not to ignore whitespace only Text nodes. - * - * @type {boolean} - * @private - */ -goog.dom.pattern.Sequence.prototype.ignoreWhitespace_ = false; - - -/** - * Test whether the given token starts, continues, or finishes the sequence - * of patterns given in the constructor. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern - * matches, <code>MATCHING</code> if the pattern starts a match, and - * <code>NO_MATCH</code> if the pattern does not match. - */ -goog.dom.pattern.Sequence.prototype.matchToken = function(token, type) { - // If the option is set, ignore any whitespace only text nodes - if (this.ignoreWhitespace_ && token.nodeType == goog.dom.NodeType.TEXT && - goog.dom.pattern.BREAKING_TEXTNODE_RE.test(token.nodeValue)) { - return goog.dom.pattern.MatchType.MATCHING; - } - - switch (this.patterns[this.currentPosition_].matchToken(token, type)) { - case goog.dom.pattern.MatchType.MATCH: - // Record the first token we match. - if (this.currentPosition_ == 0) { - this.matchedNode = token; - } - - // Move forward one position. - this.currentPosition_++; - - // Check if this is the last position. - if (this.currentPosition_ == this.patterns.length) { - this.reset(); - return goog.dom.pattern.MatchType.MATCH; - } else { - return goog.dom.pattern.MatchType.MATCHING; - } - - case goog.dom.pattern.MatchType.MATCHING: - // This can happen when our child pattern is a sequence or a repetition. - return goog.dom.pattern.MatchType.MATCHING; - - case goog.dom.pattern.MatchType.BACKTRACK_MATCH: - // This means a repetitive match succeeded 1 token ago. - // TODO(robbyw): Backtrack further if necessary. - this.currentPosition_++; - - if (this.currentPosition_ == this.patterns.length) { - this.reset(); - return goog.dom.pattern.MatchType.BACKTRACK_MATCH; - } else { - // Retry the same token on the next pattern. - return this.matchToken(token, type); - } - - default: - this.reset(); - return goog.dom.pattern.MatchType.NO_MATCH; - } -}; - - -/** - * Reset any internal state this pattern keeps. - */ -goog.dom.pattern.Sequence.prototype.reset = function() { - if (this.patterns[this.currentPosition_]) { - this.patterns[this.currentPosition_].reset(); - } - this.currentPosition_ = 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/starttag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/starttag.js.svn-base deleted file mode 100644 index 4ce0113..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/starttag.js.svn-base +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match the start of a tag. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.StartTag'); - -goog.require('goog.dom.TagWalkType'); -goog.require('goog.dom.pattern.Tag'); - - - -/** - * Pattern object that matches an opening tag. - * - * @param {string|RegExp} tag Name of the tag. Also will accept a regular - * expression to match against the tag name. - * @param {Object=} opt_attrs Optional map of attribute names to desired values. - * This pattern will only match when all attributes are present and match - * the string or regular expression value provided here. - * @param {Object=} opt_styles Optional map of CSS style names to desired - * values. This pattern will only match when all styles are present and - * match the string or regular expression value provided here. - * @param {Function=} opt_test Optional function that takes the element as a - * parameter and returns true if this pattern should match it. - * @constructor - * @extends {goog.dom.pattern.Tag} - */ -goog.dom.pattern.StartTag = function(tag, opt_attrs, opt_styles, opt_test) { - goog.dom.pattern.Tag.call( - this, - tag, - goog.dom.TagWalkType.START_TAG, - opt_attrs, - opt_styles, - opt_test); -}; -goog.inherits(goog.dom.pattern.StartTag, goog.dom.pattern.Tag); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/tag.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/tag.js.svn-base deleted file mode 100644 index 9c714d0..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/tag.js.svn-base +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a tag. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.Tag'); - -goog.require('goog.dom.pattern'); -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); -goog.require('goog.object'); - - - -/** - * Pattern object that matches an tag. - * - * @param {string|RegExp} tag Name of the tag. Also will accept a regular - * expression to match against the tag name. - * @param {goog.dom.TagWalkType} type Type of token to match. - * @param {Object=} opt_attrs Optional map of attribute names to desired values. - * This pattern will only match when all attributes are present and match - * the string or regular expression value provided here. - * @param {Object=} opt_styles Optional map of CSS style names to desired - * values. This pattern will only match when all styles are present and - * match the string or regular expression value provided here. - * @param {Function=} opt_test Optional function that takes the element as a - * parameter and returns true if this pattern should match it. - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.Tag = function(tag, type, opt_attrs, opt_styles, opt_test) { - if (goog.isString(tag)) { - this.tag_ = tag.toUpperCase(); - } else { - this.tag_ = tag; - } - - this.type_ = type; - - this.attrs_ = opt_attrs || null; - this.styles_ = opt_styles || null; - this.test_ = opt_test || null; -}; -goog.inherits(goog.dom.pattern.Tag, goog.dom.pattern.AbstractPattern); - - -/** - * The tag to match. - * - * @type {string|RegExp} - * @private - */ -goog.dom.pattern.Tag.prototype.tag_; - - -/** - * The type of token to match. - * - * @type {goog.dom.TagWalkType} - * @private - */ -goog.dom.pattern.Tag.prototype.type_; - - -/** - * The attributes to test for. - * - * @type {Object} - * @private - */ -goog.dom.pattern.Tag.prototype.attrs_ = null; - - -/** - * The styles to test for. - * - * @type {Object} - * @private - */ -goog.dom.pattern.Tag.prototype.styles_ = null; - - -/** - * Function that takes the element as a parameter and returns true if this - * pattern should match it. - * - * @type {Function} - * @private - */ -goog.dom.pattern.Tag.prototype.test_ = null; - - -/** - * Test whether the given token is a tag token which matches the tag name, - * style, and attributes provided in the constructor. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern - * matches, <code>NO_MATCH</code> otherwise. - */ -goog.dom.pattern.Tag.prototype.matchToken = function(token, type) { - // Check the direction and tag name. - if (type == this.type_ && - goog.dom.pattern.matchStringOrRegex(this.tag_, token.nodeName)) { - // Check the attributes. - if (this.attrs_ && - !goog.object.every( - this.attrs_, - goog.dom.pattern.matchStringOrRegexMap, - token)) { - return goog.dom.pattern.MatchType.NO_MATCH; - } - // Check the styles. - if (this.styles_ && - !goog.object.every( - this.styles_, - goog.dom.pattern.matchStringOrRegexMap, - token.style)) { - return goog.dom.pattern.MatchType.NO_MATCH; - } - - if (this.test_ && !this.test_(token)) { - return goog.dom.pattern.MatchType.NO_MATCH; - } - - // If we reach this point, we have a match and should save it. - this.matchedNode = token; - return goog.dom.pattern.MatchType.MATCH; - } - - return goog.dom.pattern.MatchType.NO_MATCH; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/text.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/text.js.svn-base deleted file mode 100644 index 5863a49..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/.svn/text-base/text.js.svn-base +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview DOM pattern to match a text node. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.Text'); - -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.pattern'); -goog.require('goog.dom.pattern.AbstractPattern'); -goog.require('goog.dom.pattern.MatchType'); - - - -/** - * Pattern object that matches text by exact matching or regular expressions. - * - * @param {string|RegExp} match String or regular expression to match against. - * @constructor - * @extends {goog.dom.pattern.AbstractPattern} - */ -goog.dom.pattern.Text = function(match) { - this.match_ = match; -}; -goog.inherits(goog.dom.pattern.Text, goog.dom.pattern.AbstractPattern); - - -/** - * The text or regular expression to match. - * - * @type {string|RegExp} - * @private - */ -goog.dom.pattern.Text.prototype.match_; - - -/** - * Test whether the given token is a text token which matches the string or - * regular expression provided in the constructor. - * - * @param {Node} token Token to match against. - * @param {goog.dom.TagWalkType} type The type of token. - * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern - * matches, <code>NO_MATCH</code> otherwise. - */ -goog.dom.pattern.Text.prototype.matchToken = function(token, type) { - if (token.nodeType == goog.dom.NodeType.TEXT && - goog.dom.pattern.matchStringOrRegex(this.match_, token.nodeValue)) { - this.matchedNode = token; - return goog.dom.pattern.MatchType.MATCH; - } - - return goog.dom.pattern.MatchType.NO_MATCH; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/allchildren.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/allchildren.js index 75ebb5e..86f8cdf 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/allchildren.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/allchildren.js @@ -52,6 +52,7 @@ goog.dom.pattern.AllChildren.prototype.depth_ = 0; * @param {goog.dom.TagWalkType} type The type of token. * @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the * same level or deeper and {@code BACKTRACK_MATCH} if not. + * @override */ goog.dom.pattern.AllChildren.prototype.matchToken = function(token, type) { this.depth_ += type; @@ -67,6 +68,7 @@ goog.dom.pattern.AllChildren.prototype.matchToken = function(token, type) { /** * Reset any internal state this pattern keeps. + * @override */ goog.dom.pattern.AllChildren.prototype.reset = function() { this.depth_ = 0; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/all-wcprops deleted file mode 100644 index 3ebfad9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/all-wcprops +++ /dev/null @@ -1,23 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 57 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/callback -END -callback.js -K 25 -svn:wc:ra_dav:version-url -V 69 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/callback/callback.js -END -test.js -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/callback/test.js -END -counter.js -K 25 -svn:wc:ra_dav:version-url -V 68 -/svn/!svn/ver/850/trunk/closure/goog/dom/pattern/callback/counter.js -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/entries b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/entries deleted file mode 100644 index edf7dfc..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/entries +++ /dev/null @@ -1,130 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/dom/pattern/callback -http://closure-library.googlecode.com/svn - - - -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -callback.js -file - - - - -2011-12-23T22:42:28.396329Z -ddf73252bf8107c58c4e3f21ae9cfd92 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -2647 - -test.js -file - - - - -2011-12-23T22:42:28.397329Z -660e3cd03c7d35ab253d3a48067374c0 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1899 - -counter.js -file - - - - -2011-12-23T22:42:28.397329Z -cbf98bf3c9f8ff1b1255ad7da33cc9a9 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -1734 - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/callback.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/callback.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/callback.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/counter.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/counter.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/counter.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/test.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/test.js.svn-base deleted file mode 100644 index 530636b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/prop-base/test.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 15 -text/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/callback.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/callback.js.svn-base deleted file mode 100644 index 7d7aa60..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/callback.js.svn-base +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Useful callback functions for the DOM matcher. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.callback'); - -goog.require('goog.dom'); -goog.require('goog.dom.TagWalkType'); -goog.require('goog.iter'); - - -/** - * Callback function for use in {@link goog.dom.pattern.Matcher.addPattern} - * that removes the matched node from the tree. Should be used in conjunciton - * with a {@link goog.dom.pattern.StartTag} pattern. - * - * @param {Node} node The node matched by the pattern. - * @param {goog.dom.TagIterator} position The position where the match - * finished. - * @return {boolean} Returns true to indicate tree changes were made. - */ -goog.dom.pattern.callback.removeNode = function(node, position) { - // Find out which position would be next. - position.setPosition(node, goog.dom.TagWalkType.END_TAG); - - goog.iter.nextOrValue(position, null); - - // Remove the node. - goog.dom.removeNode(node); - - // Correct for the depth change. - position.depth -= 1; - - // Indicate that we made position/tree changes. - return true; -}; - - -/** - * Callback function for use in {@link goog.dom.pattern.Matcher.addPattern} - * that removes the matched node from the tree and replaces it with its - * children. Should be used in conjunction with a - * {@link goog.dom.pattern.StartTag} pattern. - * - * @param {Element} node The node matched by the pattern. - * @param {goog.dom.TagIterator} position The position where the match - * finished. - * @return {boolean} Returns true to indicate tree changes were made. - */ -goog.dom.pattern.callback.flattenElement = function(node, position) { - // Find out which position would be next. - position.setPosition(node, node.firstChild ? - goog.dom.TagWalkType.START_TAG : - goog.dom.TagWalkType.END_TAG); - - goog.iter.nextOrValue(position, null); - - // Flatten the node. - goog.dom.flattenElement(node); - - // Correct for the depth change. - position.depth -= 1; - - // Indicate that we made position/tree changes. - return true; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/counter.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/counter.js.svn-base deleted file mode 100644 index a354de0..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/counter.js.svn-base +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Callback object that counts matches. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.callback.Counter'); - - - -/** - * Callback class for counting matches. - * @constructor - */ -goog.dom.pattern.callback.Counter = function() { -}; - - -/** - * The count of objects matched so far. - * - * @type {number} - */ -goog.dom.pattern.callback.Counter.prototype.count = 0; - - -/** - * The callback function. Suitable as a callback for - * {@link goog.dom.pattern.Matcher}. - * @type {Function} - * @private - */ -goog.dom.pattern.callback.Counter.prototype.callback_ = null; - - -/** - * Get a bound callback function that is suitable as a callback for - * {@link goog.dom.pattern.Matcher}. - * - * @return {Function} A callback function. - */ -goog.dom.pattern.callback.Counter.prototype.getCallback = function() { - if (!this.callback_) { - this.callback_ = goog.bind(function() { - this.count++; - return false; - }, this); - } - return this.callback_; -}; - - -/** - * Reset the counter. - */ -goog.dom.pattern.callback.Counter.prototype.reset = function() { - this.count = 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/test.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/test.js.svn-base deleted file mode 100644 index 30a58c1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/callback/.svn/text-base/test.js.svn-base +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Callback object that tests if a pattern matches at least once. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.pattern.callback.Test'); - -goog.require('goog.iter.StopIteration'); - - - -/** - * Callback class for testing for at least one match. - * @constructor - */ -goog.dom.pattern.callback.Test = function() { -}; - - -/** - * Whether or not the pattern matched. - * - * @type {boolean} - */ -goog.dom.pattern.callback.Test.prototype.matched = false; - - -/** - * The callback function. Suitable as a callback for - * {@link goog.dom.pattern.Matcher}. - * @type {Function} - * @private - */ -goog.dom.pattern.callback.Test.prototype.callback_ = null; - - -/** - * Get a bound callback function that is suitable as a callback for - * {@link goog.dom.pattern.Matcher}. - * - * @return {Function} A callback function. - */ -goog.dom.pattern.callback.Test.prototype.getCallback = function() { - if (!this.callback_) { - this.callback_ = goog.bind(function(node, position) { - // Mark our match. - this.matched = true; - - // Stop searching. - throw goog.iter.StopIteration; - }, this); - } - return this.callback_; -}; - - -/** - * Reset the counter. - */ -goog.dom.pattern.callback.Test.prototype.reset = function() { - this.matched = false; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/childmatches.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/childmatches.js index 7315ebb..72f1b51 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/childmatches.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/childmatches.js @@ -88,6 +88,7 @@ goog.dom.pattern.ChildMatches.prototype.needsReset_ = false; * @param {goog.dom.TagWalkType} type The type of token. * @return {goog.dom.pattern.MatchType} {@code MATCHING} if the token is on the * same level or deeper and {@code BACKTRACK_MATCH} if not. + * @override */ goog.dom.pattern.ChildMatches.prototype.matchToken = function(token, type) { // Defer resets so we maintain our matches array until the last possible time. @@ -143,6 +144,7 @@ goog.dom.pattern.ChildMatches.prototype.matchToken = function(token, type) { /** * Reset any internal state this pattern keeps. + * @override */ goog.dom.pattern.ChildMatches.prototype.reset = function() { this.needsReset_ = false; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/fulltag.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/fulltag.js index 8296c83..1fa2230 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/fulltag.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/fulltag.js @@ -71,6 +71,7 @@ goog.dom.pattern.FullTag.prototype.depth_ = 0; * @return {goog.dom.pattern.MatchType} <code>MATCH</code> at the end of our * tag, <code>MATCHING</code> if we are within the tag, and * <code>NO_MATCH</code> if the starting tag does not match. + * @override */ goog.dom.pattern.FullTag.prototype.matchToken = function(token, type) { if (!this.depth_) { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/nodetype.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/nodetype.js index 1038f96..b13bbe1 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/nodetype.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/nodetype.js @@ -49,6 +49,7 @@ goog.inherits(goog.dom.pattern.NodeType, goog.dom.pattern.AbstractPattern); * @param {goog.dom.TagWalkType} type The type of token. * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern * matches, <code>NO_MATCH</code> otherwise. + * @override */ goog.dom.pattern.NodeType.prototype.matchToken = function(token, type) { return token.nodeType == this.nodeType_ ? diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/repeat.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/repeat.js index d7cfbcc..5a47de0 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/repeat.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/repeat.js @@ -112,6 +112,7 @@ goog.dom.pattern.Repeat.prototype.matches; * but already had accumulated matches, <code>MATCHING</code> if the pattern * starts a match, and <code>NO_MATCH</code> if the pattern does not match. * @suppress {missingProperties} See the broken line below. + * @override */ goog.dom.pattern.Repeat.prototype.matchToken = function(token, type) { // Reset if we're starting a new match @@ -179,6 +180,7 @@ goog.dom.pattern.Repeat.prototype.matchToken = function(token, type) { /** * Reset any internal state this pattern keeps. + * @override */ goog.dom.pattern.Repeat.prototype.reset = function() { this.pattern_.reset(); diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/sequence.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/sequence.js index 7f2ea3e..df40fd6 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/sequence.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/sequence.js @@ -78,6 +78,7 @@ goog.dom.pattern.Sequence.prototype.ignoreWhitespace_ = false; * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern * matches, <code>MATCHING</code> if the pattern starts a match, and * <code>NO_MATCH</code> if the pattern does not match. + * @override */ goog.dom.pattern.Sequence.prototype.matchToken = function(token, type) { // If the option is set, ignore any whitespace only text nodes @@ -130,6 +131,7 @@ goog.dom.pattern.Sequence.prototype.matchToken = function(token, type) { /** * Reset any internal state this pattern keeps. + * @override */ goog.dom.pattern.Sequence.prototype.reset = function() { if (this.patterns[this.currentPosition_]) { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/tag.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/tag.js index 9c714d0..d04ccd3 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/tag.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/tag.js @@ -114,6 +114,7 @@ goog.dom.pattern.Tag.prototype.test_ = null; * @param {goog.dom.TagWalkType} type The type of token. * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern * matches, <code>NO_MATCH</code> otherwise. + * @override */ goog.dom.pattern.Tag.prototype.matchToken = function(token, type) { // Check the direction and tag name. diff --git a/contexts/data/lib/closure-library/closure/goog/dom/pattern/text.js b/contexts/data/lib/closure-library/closure/goog/dom/pattern/text.js index 5863a49..5b625ab 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/pattern/text.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/pattern/text.js @@ -57,6 +57,7 @@ goog.dom.pattern.Text.prototype.match_; * @param {goog.dom.TagWalkType} type The type of token. * @return {goog.dom.pattern.MatchType} <code>MATCH</code> if the pattern * matches, <code>NO_MATCH</code> otherwise. + * @override */ goog.dom.pattern.Text.prototype.matchToken = function(token, type) { if (token.nodeType == goog.dom.NodeType.TEXT && diff --git a/contexts/data/lib/closure-library/closure/goog/dom/range_test.html b/contexts/data/lib/closure-library/closure/goog/dom/range_test.html index 14070be..503e684 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/range_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/range_test.html @@ -41,9 +41,20 @@ See the COPYING file for details. <div id='breaksAroundNode'><br />abcde<br /></div> </div> + <!-- A focusable element to help restore focus to a sane state. --> + <input id="focusableElement"> + <script> var assertRangeEquals = goog.testing.dom.assertRangeEquals; + function setUp() { + // Reset the focus; some tests may invalidate the focus to exercise various + // browser bugs. + var focusableElement = goog.dom.getElement('focusableElement'); + focusableElement.focus(); + focusableElement.blur(); + } + function normalizeHtml(str) { return str.toLowerCase().replace(/[\n\r\f"]/g, '') .replace(/<\/li>/g, ''); // " for emacs @@ -491,7 +502,12 @@ See the COPYING file for details. goog.dom.removeNode(node); var newRange = goog.dom.Range.createFromWindow(window); - if (goog.userAgent.WEBKIT) { + + // In Chrome 14 and below (<= Webkit 535.1), newRange will be null. + // In Chrome 16 and above (>= Webkit 535.7), newRange will be collapsed + // like on other browsers. + // We didn't bother testing in between. + if (goog.userAgent.WEBKIT && !goog.userAgent.isVersion('535.7')) { assertNull('Webkit supports rangeCount == 0', newRange); } else { assertTrue('The other browsers will just have an empty range.', @@ -691,6 +707,23 @@ See the COPYING file for details. assertRangeEquals(container, 0, container, 0, range); } + function testFocusedElementDisappears() { + // This reproduces a failure case specific to Gecko, where an element is + // created, contentEditable is set, is focused, and removed. After that + // happens, calling selection.collapse fails. + // https://bugzilla.mozilla.org/show_bug.cgi?id=773137 + var disappearingElement = goog.dom.createDom('div'); + document.body.appendChild(disappearingElement); + disappearingElement.contentEditable = true; + disappearingElement.focus(); + document.body.removeChild(disappearingElement); + var container = goog.dom.getElement('empty'); + var caret = goog.dom.Range.createCaret(container, 0); + // This should not throw. + caret.select(); + assertEquals(0, caret.getStartOffset()); + } + function assertNodeEquals(expected, actual) { assertEquals( 'Expected: ' + goog.testing.dom.exposeNode(expected) + diff --git a/contexts/data/lib/closure-library/closure/goog/dom/tagiterator.js b/contexts/data/lib/closure-library/closure/goog/dom/tagiterator.js index b4c22e6..cd7787d 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/tagiterator.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/tagiterator.js @@ -191,7 +191,8 @@ goog.dom.TagIterator.prototype.setPosition = function(node, /** - * Replace this iterator's values with values from another. + * Replace this iterator's values with values from another. The two iterators + * must be of the same type. * @param {goog.dom.TagIterator} other The iterator to copy. * @protected */ @@ -243,6 +244,7 @@ goog.dom.TagIterator.prototype.restartTag = function() { * Move to the next position in the DOM tree. * @return {Node} Returns the next node, or throws a goog.iter.StopIteration * exception if the end of the iterator's range has been reached. + * @override */ goog.dom.TagIterator.prototype.next = function() { var node; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/tagname.js b/contexts/data/lib/closure-library/closure/goog/dom/tagname.js index 23bdd42..77a9b47 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/tagname.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/tagname.js @@ -14,15 +14,20 @@ /** * @fileoverview Defines the goog.dom.TagName enum. This enumerates - * all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html. + * all HTML tag names specified in either the the W3C HTML 4.01 index of + * elements or the HTML5 draft specification. + * + * References: + * http://www.w3.org/TR/html401/index/elements.html + * http://dev.w3.org/html5/spec/section-index.html + * */ goog.provide('goog.dom.TagName'); /** - * Enum of all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html + * Enum of all html tag names specified by the W3C HTML4.01 and HTML5 + * specifications. * @enum {string} */ goog.dom.TagName = { @@ -32,9 +37,13 @@ goog.dom.TagName = { ADDRESS: 'ADDRESS', APPLET: 'APPLET', AREA: 'AREA', + ARTICLE: 'ARTICLE', + ASIDE: 'ASIDE', + AUDIO: 'AUDIO', B: 'B', BASE: 'BASE', BASEFONT: 'BASEFONT', + BDI: 'BDI', BDO: 'BDO', BIG: 'BIG', BLOCKQUOTE: 'BLOCKQUOTE', @@ -48,16 +57,25 @@ goog.dom.TagName = { CODE: 'CODE', COL: 'COL', COLGROUP: 'COLGROUP', + COMMAND: 'COMMAND', + DATA: 'DATA', + DATALIST: 'DATALIST', DD: 'DD', DEL: 'DEL', + DETAILS: 'DETAILS', DFN: 'DFN', + DIALOG: 'DIALOG', DIR: 'DIR', DIV: 'DIV', DL: 'DL', DT: 'DT', EM: 'EM', + EMBED: 'EMBED', FIELDSET: 'FIELDSET', + FIGCAPTION: 'FIGCAPTION', + FIGURE: 'FIGURE', FONT: 'FONT', + FOOTER: 'FOOTER', FORM: 'FORM', FRAME: 'FRAME', FRAMESET: 'FRAMESET', @@ -68,6 +86,8 @@ goog.dom.TagName = { H5: 'H5', H6: 'H6', HEAD: 'HEAD', + HEADER: 'HEADER', + HGROUP: 'HGROUP', HR: 'HR', HTML: 'HTML', I: 'I', @@ -77,34 +97,48 @@ goog.dom.TagName = { INS: 'INS', ISINDEX: 'ISINDEX', KBD: 'KBD', + KEYGEN: 'KEYGEN', LABEL: 'LABEL', LEGEND: 'LEGEND', LI: 'LI', LINK: 'LINK', MAP: 'MAP', + MARK: 'MARK', + MATH: 'MATH', MENU: 'MENU', META: 'META', + METER: 'METER', + NAV: 'NAV', NOFRAMES: 'NOFRAMES', NOSCRIPT: 'NOSCRIPT', OBJECT: 'OBJECT', OL: 'OL', OPTGROUP: 'OPTGROUP', OPTION: 'OPTION', + OUTPUT: 'OUTPUT', P: 'P', PARAM: 'PARAM', PRE: 'PRE', + PROGRESS: 'PROGRESS', Q: 'Q', + RP: 'RP', + RT: 'RT', + RUBY: 'RUBY', S: 'S', SAMP: 'SAMP', SCRIPT: 'SCRIPT', + SECTION: 'SECTION', SELECT: 'SELECT', SMALL: 'SMALL', + SOURCE: 'SOURCE', SPAN: 'SPAN', STRIKE: 'STRIKE', STRONG: 'STRONG', STYLE: 'STYLE', SUB: 'SUB', + SUMMARY: 'SUMMARY', SUP: 'SUP', + SVG: 'SVG', TABLE: 'TABLE', TBODY: 'TBODY', TD: 'TD', @@ -112,10 +146,14 @@ goog.dom.TagName = { TFOOT: 'TFOOT', TH: 'TH', THEAD: 'THEAD', + TIME: 'TIME', TITLE: 'TITLE', TR: 'TR', + TRACK: 'TRACK', TT: 'TT', U: 'U', UL: 'UL', - VAR: 'VAR' + VAR: 'VAR', + VIDEO: 'VIDEO', + WBR: 'WBR' }; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/tagname_test.html b/contexts/data/lib/closure-library/closure/goog/dom/tagname_test.html index 464a193..dfd0985 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/tagname_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/tagname_test.html @@ -23,7 +23,7 @@ See the COPYING file for details. <script> function testCorrectNumberOfTagNames() { - assertEquals(92, goog.object.getCount(goog.dom.TagName)); + assertEquals(125, goog.object.getCount(goog.dom.TagName)); } function testPropertyNamesEqualValues() { diff --git a/contexts/data/lib/closure-library/closure/goog/dom/textrange.js b/contexts/data/lib/closure-library/closure/goog/dom/textrange.js index 5f96bd3..1be6b57 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/textrange.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/textrange.js @@ -207,6 +207,7 @@ goog.dom.TextRange.prototype.isReversed_ = false; /** * @return {goog.dom.TextRange} A clone of this range. + * @override */ goog.dom.TextRange.prototype.clone = function() { var range = new goog.dom.TextRange(); @@ -462,6 +463,7 @@ goog.dom.TextRange.prototype.getPastableHtml = function() { * the direction of the range, the iterator will move in document order. * @param {boolean=} opt_keys Unused for this iterator. * @return {goog.dom.TextRangeIterator} An iterator over tags in the range. + * @override */ goog.dom.TextRange.prototype.__iterator__ = function(opt_keys) { return new goog.dom.TextRangeIterator(this.getStartNode(), @@ -595,6 +597,7 @@ goog.inherits(goog.dom.DomSavedTextRange_, goog.dom.SavedRange); /** * @return {goog.dom.AbstractRange} The restored range. + * @override */ goog.dom.DomSavedTextRange_.prototype.restoreInternal = function() { return goog.dom.Range.createFromNodes(this.anchorNode_, this.anchorOffset_, diff --git a/contexts/data/lib/closure-library/closure/goog/dom/textrangeiterator.js b/contexts/data/lib/closure-library/closure/goog/dom/textrangeiterator.js index aef7f77..b8d49b8 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/textrangeiterator.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/textrangeiterator.js @@ -196,6 +196,7 @@ goog.dom.TextRangeIterator.prototype.isLast = function() { * Move to the next position in the selection. * Throws {@code goog.iter.StopIteration} when it passes the end of the range. * @return {Node} The node at the next position. + * @override */ goog.dom.TextRangeIterator.prototype.next = function() { if (this.isLast()) { @@ -219,11 +220,7 @@ goog.dom.TextRangeIterator.prototype.skipTag = function() { }; -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.TextRangeIterator} other The iterator to copy. - * @protected - */ +/** @override */ goog.dom.TextRangeIterator.prototype.copyFrom = function(other) { this.startNode_ = other.startNode_; this.endNode_ = other.endNode_; @@ -237,6 +234,7 @@ goog.dom.TextRangeIterator.prototype.copyFrom = function(other) { /** * @return {goog.dom.TextRangeIterator} An identical iterator. + * @override */ goog.dom.TextRangeIterator.prototype.clone = function() { var copy = new goog.dom.TextRangeIterator(this.startNode_, diff --git a/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor.js b/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor.js index db24177..8bc2423 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor.js +++ b/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor.js @@ -100,6 +100,20 @@ goog.dom.ViewportSizeMonitor.getInstanceForWindow = function(opt_window) { /** + * Removes and disposes a viewport size monitor for the given window if one + * exists. + * @param {Window=} opt_window The window whose monitor should be removed; + * defaults to the window in which this code is executing. + */ +goog.dom.ViewportSizeMonitor.removeInstanceForWindow = function(opt_window) { + var uid = goog.getUid(opt_window || window); + + goog.dispose(goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid]); + delete goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid]; +}; + + +/** * Map of window hash code to viewport size monitor for that window, if * created. * @type {Object.<number,goog.dom.ViewportSizeMonitor>} diff --git a/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor_test.html b/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor_test.html index d9b3c5f..eddb8ac 100644 --- a/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor_test.html +++ b/contexts/data/lib/closure-library/closure/goog/dom/viewportsizemonitor_test.html @@ -161,6 +161,20 @@ See the COPYING file for details. goog.dom.ViewportSizeMonitor.getInstanceForWindow()); } + + function testRemoveInstanceForWindow() { + var fakeWindow1 = new FakeWindow(); + var monitor1 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( + fakeWindow1); + + goog.dom.ViewportSizeMonitor.removeInstanceForWindow(fakeWindow1); + assertTrue(monitor1.isDisposed()); + + var monitor2 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( + fakeWindow1); + assertNotEquals(monitor1, monitor2); + }; + </script> </body> </html> |