├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── NOTICE ├── README.md ├── analysis_options.yaml ├── doc └── Comparison.md ├── lib ├── dquery.dart └── src │ ├── cookie.dart │ ├── css.dart │ ├── data.dart │ ├── dimension.dart │ ├── dquery_api.dart │ ├── dquery_impl.dart │ ├── event.dart │ ├── manipulation.dart │ ├── offset.dart │ ├── selector.dart │ ├── traversing.dart │ └── util │ └── util.dart ├── pubspec.yaml ├── testcase ├── pubspec.yaml └── web │ ├── core-01-html.dart │ ├── core-01-html.html │ ├── css-01.dart │ ├── css-01.html │ ├── data-01.dart │ ├── data-01.html │ ├── event-01.dart │ ├── event-01.html │ ├── event-02-blur.dart │ ├── event-02-blur.html │ ├── event-03-namespace.dart │ ├── event-03-namespace.html │ ├── event-04-massive.dart │ ├── event-04-massive.html │ ├── event-05-on-off.dart │ ├── event-05-on-off.html │ ├── index.html │ ├── manipulation-01.dart │ ├── manipulation-01.html │ ├── manipulation-02.dart │ ├── manipulation-02.html │ ├── offset-01.dart │ └── offset-01.html └── tool ├── d2d ├── d2j └── lib ├── exclude.lst └── html.sed /.gitattributes: -------------------------------------------------------------------------------- 1 | *.dart text eol=lf 2 | *.html text eol=lf 3 | *.css text eof=lf 4 | *.less text eof=lf 5 | *.xml text eol=lf 6 | *.md text eol=lf 7 | *.yaml text eol=lf 8 | *.txt text eol=lf 9 | *.js text eof=lf 10 | *.lst text eof=lf 11 | d2d text eof=lf 12 | d2j text eof=lf 13 | l2c text eof=lf 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .pub 3 | .idea/ 4 | .packages 5 | debug 6 | codegen 7 | *.local 8 | *.class 9 | Thumbs.db 10 | .project 11 | .children 12 | *.dart.js 13 | *.dart.js_ 14 | *.dart.js.map 15 | *.dart.js.deps 16 | out.js 17 | out.js.map 18 | out.js.deps 19 | out 20 | *.bak 21 | ~$*.pptx 22 | ~$*.docx 23 | ~$*.xlsx 24 | *.tmp 25 | packages 26 | packages/ 27 | pubspec.lock 28 | .pub 29 | dquery.iml 30 | .dart_tool 31 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGES 2 | **4.0.0** 3 | * Dart 3.7 required 4 | 5 | **3.0.1** 6 | * Fixed ConcurrentModificationError when detach element 7 | 8 | **3.0.0** 9 | * Dart 3 required 10 | 11 | **2.0.4** 12 | Add "key" and "code" getter for keyboard input 13 | 14 | **2.0.3** 15 | Fixed concurrent modification error when detach element 16 | 17 | **2.0.2** 18 | Remove dart:html_common package 19 | 20 | **2.0.1** 21 | * Fixed set a wrong offsetTop 22 | * Fixed relatedTarget cast error 23 | 24 | **2.0.0** 25 | * Migrate to null safety 26 | 27 | **1.0.1** 28 | * Fixed type errors for Dart 2 29 | * Fixed get css value by property name 30 | 31 | **1.0.0** 32 | * Dart 2 required 33 | 34 | **0.8.6** 35 | * Fixed QueryEvent missing overrides 36 | 37 | **0.8.5** 38 | 39 | * QueryEvent.shiftKey introduced. 40 | 41 | **0.8.4** 42 | 43 | * Deprecate QueryEvent.type since Dart 1.16 doesn't support MouseEvent.which, and it is not non-standard. 44 | * Deprecate keyLocation. Use location instead. 45 | 46 | **0.8.3** 47 | 48 | * Remove QueryEvent's isDefaultPrevented and isPropagationStopped. Please use defaultPrevented and propagationStopped instead. 49 | 50 | **0.8.2** 51 | 52 | * Remove QueryEvent's which and clipboardData to be compatible with Dart 1.16 53 | 54 | **0.8.1** 55 | 56 | * Close #11: QueryEvent implements Event 57 | # Fixed client error when access pageX (Firefox) 58 | 59 | **0.8.0 60 | 61 | * Refector: DQuery doesn't depend on Event.target/type for basic event handling 62 | 63 | **0.7.1** 64 | 65 | * Focus/blur event bubbling ready. 66 | * Fix mouseenter/mouseleave delegate event. 67 | * Fix delegate target not found error. 68 | * Removed deprecated event API. 69 | * Fine tune QueryEvent constructor. 70 | 71 | **0.7.0** 72 | 73 | * #6: DocumentQuery supported cookie API. 74 | * #2: QueryEvent supported keystroke API. 75 | 76 | **0.6.1** 77 | 78 | * Fix event memory issue. 79 | 80 | **0.6.0** 81 | 82 | * Query was added for query any object including shadow roots. 83 | * DocumentQuery and WindowQuery were removed, and replaced with DQuery. 84 | * DQueryEvent was renamed to QueryEvent. 85 | * Data.space() became a getter: Date.space 86 | 87 | **0.5.4** 88 | 89 | * Fix event name space. 90 | * Fix data remove. 91 | * Fine tune JavaScript compatibility. 92 | 93 | **0.5.2** 94 | 95 | * Add getter/setter of offset, getter of offsetLeft, offsetTop 96 | * Add getter of offsetParent 97 | * Add getter/setter of html, text 98 | * Add .clone() 99 | * Add .append(), .prepend(), .after(), .before() 100 | * Add .appendTo(), .prependTo() 101 | * Minor bug fixes 102 | 103 | **0.5.1** 104 | 105 | * Add $(html) support. 106 | * Add getter, setter of scrollLeft, scrollTop 107 | * Add .css() 108 | * Add getter of width, height 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Rikulo DQuery 2 | Copyright 2013 Potix corporation 3 | 4 | Portions of this software were developed based on the following: 5 | - Copyright 2013 jQuery Foundation and other contributors 6 | http://jquery.com/ 7 | MIT License 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DQuery 2 | 3 | DQuery is a porting of [jQuery](http://jquery.com/) in Dart. 4 | 5 | 6 | * [API Reference](https://pub.dev/documentation/dquery/latest/) 7 | * [Git Repository](https://github.com/rikulo/dquery) 8 | * [Discussion](http://stackoverflow.com/questions/tagged/rikulo) 9 | * [Issues](https://github.com/rikulo/dquery/issues) 10 | 11 | ## Install from Dart Pub Repository 12 | 13 | Include the following in your `pubspec.yaml`: 14 | 15 | dependencies: 16 | dquery: any 17 | 18 | Then run the [Pub Package Manager](http://pub.dartlang.org/doc) in Dart Editor (Tool > Pub Install). If you are using a different editor, run the command 19 | (comes with the Dart SDK): 20 | 21 | pub install 22 | 23 | ## Usage 24 | 25 | You can create a query object by selector. With context provided, the query will be based on different element. 26 | 27 | // selects all elements containing 'active' in CSS class 28 | ElementQuery $elems = $('.active'); 29 | 30 | // selects all descendant elements of div containing 'active' in CSS class 31 | ElementQuery $elems = $('.active', div); 32 | 33 | It implements List. 34 | 35 | $('.active')[0]; 36 | $('.active').isEmpty; 37 | for (Element e in $('.active')) { ... } 38 | 39 | Create another query object with traversing API, including [find](https://pub.dev/documentation/dquery/latest/dquery/Query/find.html), [closest](https://pub.dev/documentation/dquery/latest/dquery/ElementQuery/closest.html), [parent](https://pub.dev/documentation/dquery/latest/dquery/ElementQuery/parent.html), [children](https://pub.dev/documentation/dquery/latest/dquery/ElementQuery/children.html). 40 | 41 | $('.active').closest('ul'); 42 | $('#myDiv').find('a.btn'); 43 | 44 | Manipulate selected elements. 45 | 46 | $('.active').removeClass('active'); 47 | $('.fade').hide(); 48 | 49 | Register event handlers on queried elements, or trigger an event by API. 50 | 51 | $('#myBtn').on('click', (QueryEvent e) { 52 | ... 53 | }); 54 | $('#myBtn').trigger('click', data: 'my data'); 55 | 56 | There are query objects of `Document` and `Window` too. 57 | 58 | Query $doc = $document(); 59 | Query $win = $window(); 60 | 61 | Check the [API reference](https://pub.dev/documentation/dquery/latest/dquery/dquery-library.html) for more features. 62 | 63 | ## Comparison to jQuery 64 | 65 | See [here](https://github.com/rikulo/dquery/blob/master/doc/Comparison.md). 66 | 67 | ## Notes to Contributors 68 | 69 | ### Test and Debug 70 | 71 | You are welcome to submit [bugs and feature requests](https://github.com/rikulo/dquery/issues). Or even better if you can fix or implement them! 72 | 73 | ### Fork DQuery 74 | 75 | If you'd like to contribute back to the core, you can [fork this repository](https://help.github.com/articles/fork-a-repo) and send us a pull request, when it is ready. 76 | 77 | Please be aware that one of Rikulo's design goals is to keep the sphere of API as neat and consistency as possible. Strong enhancement always demands greater consensus. 78 | 79 | If you are new to Git or GitHub, please read [this guide](https://help.github.com/) first. 80 | 81 | ## Who Uses 82 | 83 | * [Quire](https://quire.io) - a simple, collaborative, multi-level task management tool. 84 | * [Keikai](https://keikai.io) - a sophisticated spreadsheet for big data 85 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | errors: 3 | todo: ignore 4 | linter: 5 | rules: 6 | - annotate_overrides 7 | - avoid_init_to_null 8 | - camel_case_types 9 | - constant_identifier_names 10 | -------------------------------------------------------------------------------- /doc/Comparison.md: -------------------------------------------------------------------------------- 1 | ###Member Functions 2 | 3 | | jQuery | DQuery | History | Note | 4 | |:-----------|:------------|:------------|:------------| 5 | | [.add()](http://api.jquery.com/add/) | *Dart List API* | since 0.5.0 | 6 | | [.addClass()](http://api.jquery.com/addClass/) | .addClass() | since 0.5.0 | 7 | | [.after()](http://api.jquery.com/after/) | .after() | since 0.5.2 | 8 | | [.append()](http://api.jquery.com/append/) | .append() | since 0.5.2 | 9 | | [.appendTo()](http://api.jquery.com/appendTo/) | .appendTo() | since 0.5.2 | 10 | | [.before()](http://api.jquery.com/before/) | .before() | since 0.5.2 | 11 | | [.bind()](http://api.jquery.com/bind/) | -- | | (Use .on() instead) 12 | | [.blur()](http://api.jquery.com/blur/) | | | (Later) 13 | | [.change()](http://api.jquery.com/change/) | | | (Later) 14 | | [.children()](http://api.jquery.com/children/) | .children() | since 0.5.0 | 15 | | [.click()](http://api.jquery.com/click/) | | | (Later) 16 | | [.clone()](http://api.jquery.com/clone/) | .clone() | since 0.5.2 | 17 | | [.closest()](http://api.jquery.com/closest/) | .closest() | since 0.5.0 | 18 | | [.css()](http://api.jquery.com/css/) | .css() | since 0.5.1 | 19 | | [.data()](http://api.jquery.com/data/) | .data.get() | since 0.5.0 | get data 20 | | | .data.set() | since 0.5.0 | set data 21 | | | .data.space() | since 0.5.0 | set all data map 22 | | [.dblclick()](http://api.jquery.com/dblclick/) | | | (Later) 23 | | [.delegate()](http://api.jquery.com/delegate/) | -- | | (Use .on() instead) 24 | | [.detach()](http://api.jquery.com/detach/) | .detach() | since 0.5.1 | 25 | | [.each()](http://api.jquery.com/each/) | *Dart List API* | since 0.5.0 | 26 | | [.empty()](http://api.jquery.com/empty/) | .empty() | since 0.5.1 | 27 | | [.end()](http://api.jquery.com/end/) | .end() | since 0.5.0 | 28 | | [.eq()](http://api.jquery.com/eq/) | | | (Later) 29 | | [.filter()](http://api.jquery.com/filter/) | | | (Later) 30 | | [.find()](http://api.jquery.com/find/) | .find() | since 0.5.0 | 31 | | [.first()](http://api.jquery.com/first/) | | | (Later) 32 | | [.focus()](http://api.jquery.com/focus/) | | | (Later) 33 | | [.focusin()](http://api.jquery.com/focusin/) | | | (Later) 34 | | [.focusout()](http://api.jquery.com/focusout/) | | | (Later) 35 | | [.get()](http://api.jquery.com/get/) | *Dart List API* | since 0.5.0 | 36 | | [.has()](http://api.jquery.com/has/) | | | (Later) 37 | | [.hasClass()](http://api.jquery.com/hasClass/) | .hasClass() | since 0.5.0 | 38 | | [.height()](http://api.jquery.com/height/) | get height | since 0.5.1 | (Only getter part) 39 | | [.hide()](http://api.jquery.com/hide/) | .hide() | since 0.5.0 | (No animation) 40 | | [.hover()](http://api.jquery.com/hover/) | | | (Later) 41 | | [.html()](http://api.jquery.com/html/) | get html | since 0.5.2 | 42 | | | set html | since 0.5.2 | (String value only) 43 | | [.index()](http://api.jquery.com/index/) | *Dart List API* | since 0.5.0 | 44 | | [.is()](http://api.jquery.com/is/) | | | (Later) 45 | | [.keydown()](http://api.jquery.com/keydown/) | | | (Later) 46 | | [.keypress()](http://api.jquery.com/keypress/) | | | (Later) 47 | | [.keyup()](http://api.jquery.com/keyup/) | | | (Later) 48 | | [.last()](http://api.jquery.com/last/) | | | (Later) 49 | | [.length](http://api.jquery.com/length/) | *Dart List API* | since 0.5.0 | 50 | | [.map()](http://api.jquery.com/map/) | *Dart List API* | since 0.5.0 | 51 | | [.mousedown()](http://api.jquery.com/mousedown/) | | | (Later) 52 | | [.mouseenter()](http://api.jquery.com/mouseenter/) | | | (Later) 53 | | [.mouseleave()](http://api.jquery.com/mouseleave/) | | | (Later) 54 | | [.mousemove()](http://api.jquery.com/mousemove/) | | | (Later) 55 | | [.mouseout()](http://api.jquery.com/mouseout/) | | | (Later) 56 | | [.mouseover()](http://api.jquery.com/mouseover/) | | | (Later) 57 | | [.mouseup()](http://api.jquery.com/mouseup/) | | | (Later) 58 | | [.next()](http://api.jquery.com/next/) | | | (Later) 59 | | [.nextAll()](http://api.jquery.com/nextAll/) | | | (Later) 60 | | [.nextUntil()](http://api.jquery.com/nextUntil/) | | | (Later) 61 | | [.not()](http://api.jquery.com/not/) | | | (Later) 62 | | [.off()](http://api.jquery.com/off/) | .off() | since 0.5.0 | 63 | | [.offset()](http://api.jquery.com/offset/) | get offset | since 0.5.2 | 64 | | | set offset | since 0.5.2 | (Point only) 65 | | | set offsetLeft | since 0.5.2 | (numeric value only) 66 | | | set offsetTop | since 0.5.2 | (numeric value only) 67 | | [.offsetParent()](http://api.jquery.com/offsetParent/) | get offsetParent | since 0.5.2 | 68 | | [.on()](http://api.jquery.com/on/) | .on() | since 0.5.0 | 69 | | [.one()](http://api.jquery.com/one/) | .one() | since 0.5.0 | 70 | | [.parent()](http://api.jquery.com/parent/) | .parent() | since 0.5.0 | 71 | | [.parentsUntil()](http://api.jquery.com/parentsUntil/) | | | (Later) 72 | | [.position()](http://api.jquery.com/position/) | get position | since 0.5.2 | 73 | | [.prepend()](http://api.jquery.com/prepend/) | .prepend() | since 0.5.2 | 74 | | [.prependTo()](http://api.jquery.com/prependTo/) | .prependTo() | since 0.5.2 | 75 | | [.prev()](http://api.jquery.com/prev/) | | | (Later) 76 | | [.prevAll()](http://api.jquery.com/prevAll/) | | | (Later) 77 | | [.prevUntil()](http://api.jquery.com/prevUntil/) | | | (Later) 78 | | [.pushStack()](http://api.jquery.com/pushStack/) | .pushStack() | since 0.5.0 | 79 | | [.ready()](http://api.jquery.com/ready/) | | | (Later) 80 | | [.remove()](http://api.jquery.com/remove/) | -- | | (Merged into .detach() API) 81 | | [.removeClass()](http://api.jquery.com/removeClass/) | .removeClass() | since 0.5.0 | 82 | | [.removeData()](http://api.jquery.com/removeData/) | .removeData() | since 0.5.0 | 83 | | [.resize()](http://api.jquery.com/resize/) | | | (Later) 84 | | [.scroll()](http://api.jquery.com/scroll/) | | | (Later) 85 | | [.scrollLeft()](http://api.jquery.com/scrollLeft/) | get scrollLeft | since 0.5.1 | 86 | | | set scrollLeft | since 0.5.1 | 87 | | [.scrollTop()](http://api.jquery.com/scrollTop/) | get scrollTop | since 0.5.1 | 88 | | | set scrollTop | since 0.5.1 | 89 | | [.select()](http://api.jquery.com/select/) | | | (Later) 90 | | [.show()](http://api.jquery.com/show/) | .show() | since 0.5.0 | (No animation) 91 | | [.siblings()](http://api.jquery.com/siblings/) | | | (Later) 92 | | [.slice()](http://api.jquery.com/slice/) | | | (Later) 93 | | [.submit()](http://api.jquery.com/submit/) | | | (Later) 94 | | [.text()](http://api.jquery.com/text/) | get text | since 0.5.2 | 95 | | | set text | since 0.5.2 | (String value only) 96 | | [.toggle()](http://api.jquery.com/toggle/) | .toggle() | since 0.5.0 | (No animation) 97 | | [.toggleClass()](http://api.jquery.com/toggleClass/) | .toggleClass() | since 0.5.0 | 98 | | [.trigger()](http://api.jquery.com/trigger/) | .trigger() | since 0.5.0 | 99 | | [.triggerHandler()](http://api.jquery.com/triggerHandler/) | .triggerHandler() | since 0.5.0 | 100 | | [.unbind()](http://api.jquery.com/unbind/) | -- | | (Use .off() instead) 101 | | [.undelegate()](http://api.jquery.com/undelegate/) | -- | | (Use .off() instead) 102 | | [.unload()](http://api.jquery.com/unload/) | | | (Later) 103 | | [.unwrap()](http://api.jquery.com/unwrap/) | | | (Later) 104 | | [.width()](http://api.jquery.com/width/) | get width | since 0.5.1 | (Only getter part) 105 | | [.wrap()](http://api.jquery.com/wrap/) | | | (Later) 106 | | [.wrapAll()](http://api.jquery.com/wrapAll/) | | | (Later) 107 | | [.wrapInner()](http://api.jquery.com/wrapInner/) | | | (Later) 108 | 109 | ###Static Functions 110 | 111 | | jQuery | DQuery | History | 112 | |:-----------|:------------|:------------| 113 | | [jQuery.unique()](http://api.jquery.com/jQuery.unique/) | DQuery.unique() | since 0.5.0 | 114 | -------------------------------------------------------------------------------- /lib/dquery.dart: -------------------------------------------------------------------------------- 1 | library dquery; 2 | 3 | import 'dart:math'; 4 | import 'package:web/web.dart'; 5 | 6 | import 'dart:collection'; 7 | 8 | import 'dart:js_interop'; 9 | import "package:intl/intl.dart" show DateFormat; 10 | 11 | part 'src/util/util.dart'; 12 | part 'src/dquery_api.dart'; 13 | part 'src/dquery_impl.dart'; 14 | part 'src/selector.dart'; 15 | part 'src/traversing.dart'; 16 | part 'src/dimension.dart'; 17 | part 'src/offset.dart'; 18 | part 'src/manipulation.dart'; 19 | part 'src/css.dart'; 20 | part 'src/data.dart'; 21 | part 'src/event.dart'; 22 | part 'src/cookie.dart'; 23 | 24 | /** Return an [ElementQuery] based on given [selector] and [context]. 25 | */ 26 | ElementQuery $(selector, [context]) { 27 | if (selector is String) 28 | selector = selector.trim(); 29 | 30 | if (selector == null || selector == '') 31 | return ElementQuery([]); 32 | 33 | if (selector is String) { 34 | // html 35 | if (selector.startsWith('<')) { 36 | final template = HTMLTemplateElement(); 37 | template.innerHTML = selector.toJS; 38 | return ElementQuery(JSImmutableListWrapper( 39 | template.content.childNodes).toList().cast()); 40 | } 41 | 42 | if (context == null) 43 | return _rootDQuery.find(selector); 44 | 45 | if (context is DQuery) 46 | return context.find(selector); 47 | 48 | if (context is JSObject) { 49 | if (context.isA()) 50 | return $document(context as Document).find(selector); 51 | 52 | if (context.isA()) 53 | return ElementQuery([context as HTMLElement]).find(selector); 54 | } 55 | 56 | throw ArgumentError("Context type should be Document, Element, or DQuery: $context"); 57 | } 58 | 59 | if (selector is JSObject) { 60 | if (selector.isA()) 61 | return ElementQuery([selector as Element]); 62 | 63 | if (selector.isA() || selector.isA()) 64 | return ElementQuery(JSImmutableListWrapper(selector)); 65 | } 66 | 67 | if (selector is List) 68 | return ElementQuery(selector); 69 | 70 | throw ArgumentError("Selector type should be String, Element, or List: $selector"); 71 | } 72 | 73 | /** Return a [DocumentQuery] wrapping the given [document]. If [document] is 74 | * omitted, the default document instance is assumed. 75 | */ 76 | DocumentQuery $document([Document? document]) => _DocumentQuery(document); 77 | 78 | /** Return a [WindowQuery] wrapping the given [window]. If [window] is omitted, 79 | * the default window instance is used. 80 | */ 81 | DQuery $window([Window? window]) => _WindowQuery(window); 82 | 83 | /** Return a [WindowQuery] wrapping the given [window]. If [window] is omitted, 84 | * the default window instance is used. 85 | */ 86 | Query $shadowRoot(ShadowRoot shadowRoot) => _ShadowRootQuery(shadowRoot); 87 | -------------------------------------------------------------------------------- /lib/src/cookie.dart: -------------------------------------------------------------------------------- 1 | //Copyright (C) 2014 Potix Corporation. All Rights Reserved. 2 | //History: Wed, Jun 18, 2014 12:07:42 PM 3 | // Author: tomyeh 4 | part of dquery; 5 | 6 | //--The code is ported from Carhartl's jquery-cookie--// 7 | 8 | String _encode(String s) => Uri.encodeComponent(s); 9 | String _decode(String s) => Uri.decodeComponent(s); 10 | 11 | _getCookie(Document doc, [String? key]) { 12 | final cookies = key != null ? null: {}; 13 | String? value = doc.cookie; 14 | for (final cookie in value.split('; ')) { 15 | final i = cookie.indexOf('='); 16 | if (i < 0) continue; //just in case 17 | 18 | final name = _decode(cookie.substring(0, i)); 19 | value = _parseCookieValue(cookie.substring(i + 1)); 20 | 21 | if (key == null) { 22 | if (value != null) 23 | cookies![name] = value; 24 | } else if (key == name) { 25 | return value; 26 | } 27 | } 28 | return cookies; 29 | } 30 | 31 | String? _parseCookieValue(String value) { 32 | if (value.startsWith('"')) { 33 | // This is a quoted cookie as according to RFC2068, unescape... 34 | value = value.substring(1, value.length - 1) 35 | .replaceAll(_reQuot, '"').replaceAll(_reBS, r'\'); 36 | } 37 | 38 | try { 39 | // Replace server-side written pluses with spaces. 40 | return _decode(value.replaceAll(_rePlus, ' ')); 41 | } catch (_) { 42 | return null; 43 | } 44 | } 45 | final RegExp _reQuot = new RegExp(r'\\"'), _reBS = new RegExp(r'\\\\'), 46 | _rePlus = new RegExp(r'\+'); 47 | 48 | 49 | void _setCookie(Document doc, String name, String value, Duration? expires, 50 | String? path, bool? secure) { 51 | final buf = [_encode(name), '=', _encode(value)]; 52 | 53 | if (expires != null) 54 | buf..add("; expires=") 55 | ..add(_utcfmt.format(new DateTime.now().add(expires).toUtc())) 56 | ..add(" GMT"); 57 | if (path != null) 58 | buf..add("; path=")..add(path); 59 | if (secure == true) 60 | buf.add("; secure"); 61 | 62 | document.cookie = buf.join(""); 63 | } 64 | final _utcfmt = new DateFormat("E dd MMM yyyy kk:mm:ss", "en_US"); 65 | -------------------------------------------------------------------------------- /lib/src/css.dart: -------------------------------------------------------------------------------- 1 | part of dquery; 2 | 3 | final Map _elemDisplay = { 4 | 'body': 'block' 5 | }; 6 | 7 | bool _isHidden(Element elem) => 8 | (elem as HTMLElement).style.display == 'none' || 9 | window.getComputedStyle(elem).display == 'none' || 10 | elem.ownerDocument?.contains(elem) != true; // TODO: do experiment 11 | 12 | void _showHide(List elements, bool show) { 13 | 14 | final values = {}; 15 | 16 | for (final elem in elements.cast()) { 17 | final oldDisplay = _dataPriv.get(elem, 'olddisplay'); 18 | if (oldDisplay != null) 19 | values[elem] = oldDisplay; 20 | final display = elem.style.display; 21 | 22 | if (show) { 23 | // jQuery: Reset the inline display of this element to learn if it is 24 | // being hidden by cascaded rules or not 25 | if (oldDisplay == null && display == "none") 26 | elem.style.display = ''; 27 | 28 | // jQuery: Set elements which have been overridden with display: none 29 | // in a stylesheet to whatever the default browser style is 30 | // for such an element 31 | if (elem.style.display == '' && _isHidden(elem)) 32 | _dataPriv.set(elem, 'olddisplay', values[elem] = _cssDefaultDisplay(elem.tagName)); 33 | 34 | } else if (!values.containsKey(elem)) { 35 | final hidden = _isHidden(elem); 36 | if (display.isNotEmpty && display != 'none' || !hidden) 37 | _dataPriv.set(elem, 'olddisplay', hidden ? display : elem.style.display); 38 | 39 | } 40 | 41 | } 42 | 43 | // Set the display of most of the elements in a second loop 44 | // to avoid the constant reflow 45 | for (final elem in elements.cast()) { 46 | final String display = elem.style.display; 47 | if (!show || display == 'none' || display == '') 48 | elem.style.display = show ? (values[elem] ?? '') : 'none'; 49 | } 50 | 51 | } 52 | 53 | // Try to determine the default display value of an element 54 | String _cssDefaultDisplay(String nodeName) { 55 | var display = _elemDisplay[nodeName]; 56 | if (display == null) { 57 | display = _actualDisplay(nodeName, document); 58 | 59 | // TODO: later (handle iframe) 60 | /* 61 | // If the simple way fails, read from inside an iframe 62 | if ( display == "none" || !display ) { 63 | // Use the already-created iframe if possible 64 | iframe = ( iframe || 65 | jQuery("