This put-selector/put module/package provides a high-performance, lightweight
(~1.5KB minified, ~0.7KB gzipped with other code) function for creating
and manipulating DOM elements with succinct, elegant, familiar CSS selector-based
syntax across all browsers and platforms (including HTML generation on NodeJS).
The single function from the module creates or updates DOM elements by providing
a series of arguments that can include reference elements, selector strings, properties,
and text content. The put() function utilizes the proven techniques for optimal performance
on modern browsers to ensure maximum speed.
Installation/Usage
----------------
The put.js module can be simply downloaded and used a plain script (creates a global
put() function), as an AMD module (exports the put() function), or as a NodeJS (or any
server side JS environment) module.
It can also be installed with <a href="https://github.com/kriszyp/cpm">CPM</a>:
cpm install put-selector
and then reference the "put-selector" module as a dependency.
or installed for Node with NPM:
npm install put-selector
and then:
put = require("put-selector");
Creating Elements
----------------
Type selector syntax (no prefix) can be used to indicate the type of element to be created. For example:
newDiv = put("div");
will create a new <div> element. We can put a reference element in front of the selector
string and the <div> will be appended as a child to the provided element:
put(parent, "div");
The selector .class-name can be used to assign the class name. For example:
put("div.my-class")
would create an element <div class="my-class"> (an element with a class of "my-class").
The selector #id can be used to assign an id and [name=value] can be used to
assign additional attributes to the element. For example:
newInput = put(parent, "input.my-input#address[type=checkbox]");
Would create an input element with a class name of "my-input", an id of "address",
and the type attribute set to "checkbox". The attribute assignment will always use
setAttribute to assign the attribute to the element. Multiple attributes and classes
can be assigned to a single element.
The put function returns the last top level element created or referenced. In the
examples above, the newly create element would be returned.
Modifying Elements
----------------
One can also modify elements with selectors. If the tag name is omitted (and no
combinators have been used), the reference element will be modified by the selector.
For example, to add the class "foo" to element, we could write:
put(element, ".foo");
Likewise, we could set attributes, here we set the "role" attribute to "presentation":
put(element, "[role=presentation]");
And these can be combined also. For example, we could set the id and an attribute in
one statement:
put(element, "#id[tabIndex=2]");
One can also remove classes from elements by using the "!" operator in place of a ".".
To remove the "foo" class from an element, we could write:
put(element, "!foo");
We can also use the "!" operator to remove attributes as well. Prepending an attribute name
with "!" within brackets will remove it. To remove the "role" attribute, we could write:
put(element, "[!role]");
Deleting Elements
--------------
To delete an element, we can simply use the "!" operator by itself as the entire selector:
put(elementToDelete, "!");
This will destroy the element from the DOM (using parent innerHTML destruction that reduces memory leaks in IE).
Text Content
-----------
The put() arguments may also include a subsequent string (or any primitive value including
boolean and numbers) argument immediately
following a selector, in which case it is used as the text inside of the new/referenced element.
For example, here we could create a new <div> with the text "Hello, World" inside.
newDiv = put(parent, "div", "Hello, World");
The text is escaped, so any string will show up as is, and will not be parsed as HTML.
Children and Combinators
-----------------------
CSS combinators can be used to create child elements and sibling elements. For example,
we can use the child operator (or the descendant operator, it acts the same here) to
create nested elements:
spanInsideOfDiv = put(reference, "div.outer span.inner");
This would create a new span element (with a class name of "inner") as a child of a
new div element (with a class name of "outer") as a child of the reference element. The
span element would be returned. We can also use the sibling operator to reference
the last created element or the reference element. In the example we indicate that
we want to create sibling of the reference element:
newSpan = put(reference, "+span");
Would create a new span element directly after the reference element (reference and
newSpan would be siblings.) We can also use the "-" operator to indicate that the new element
should go before:
newSpan = put(reference, "-span");
This new span element will be inserted before the reference element in the DOM order.
Note that "-" is valid character in tags and classes, so it will only be interpreted as a
combinator if it is the first character or if it is preceded by a space.
The sibling operator can reference the last created element as well. For example
to add two td element to a table row:
put(tableRow, "td+td");
The last created td will be returned.
The parent operator, "<" can be used to reference the parent of the last created
element or reference element. In this example, we go crazy, and create a full table,
using the parent operator (applied twice) to traverse back up the DOM to create another table row
after creating a td element:
newTable = put(referenceElement, "table.class-name#id tr td[colSpan=2]<<tr td+td<<");
We also use a parent operator twice at the end, so that we move back up two parents
to return the table element (instead of the td element).
Finally, we can use the comma operator to create multiple elements, each basing their selector
scope on the reference element. For example we could add two more rows to our table
without having to use the double parent operator:
put(newTable, "tr td,tr td+td");
Appending/Inserting Existing Elements
---------------------------------
Existing elements may be referenced in the arguments after selectors as well as before.
If an existing element is included in the arguments after a selector, the existing element will
be appended to the last create/referenced element or it will be inserted according to
a trailing combinator. For example, we could create a <div> and then append
the "child" element to the new <div>:
put("div", child);
Or we can do a simple append of an existing element to another element:
put(parent, ">", child);
We could also use sibling combinators to place the referenced element. We could place
the "second" element after (as the next sibling) the "first" element:
put(first, "+", second);
Or we could create a <div> and place "first" before it using the previous sibling combinator:
put(parent, "div.second -", first);
The put() function takes an unlimited number of arguments, so we could combine as
many selectors and elements as we want:
put(parent, "div.child", grandchild, "div.great-grandchild", gggrandchild);
Variable Substitution
-------------------
The put() function also supports variable substitution, by using the "$" symbol in selectors.
The "$" can be used for attribute values and to represent text content. When a "$"
is encountered in a selector, the next argument value is consumed and used in it's
place. To create an element with a title that comes from the variable "title", we could write:
put("div[title=$]", title);
The value of title may have any characters (including ']'), no escaping is needed.
This approach can simplify selector string construction and avoids the need for complicated
escaping mechanisms.
The "$" may be used as a child entity to in
没有合适的资源?快使用搜索试试~ 我知道了~
ArcGIS Server JavaScript API 3.1离线包
共4939个文件
js:2975个
css:624个
png:478个
5星 · 超过95%的资源 需积分: 10 15 下载量 56 浏览量
2012-09-19
13:28:05
上传
评论
收藏 3.17MB 7Z 举报
温馨提示
ArcGIS Server Javascript API 3.1 jsapi普通模式的离线包,里面有API和新增的功能说明,包括CSS文件夹、image文件夹,js文件夹等 不包含jsapicompact包
资源推荐
资源详情
资源评论
收起资源包目录
ArcGIS Server JavaScript API 3.1离线包 (4939个子文件)
africa 11KB
antarctica 3KB
Storage.as 12KB
DojoExternalInterface.as 5KB
ExpressInstall.as 2KB
Default.ashx 961B
asia 26KB
australasia 11KB
backward 4KB
build.bat 997B
claro.css 112KB
dijit.css 85KB
iphone-app.css 77KB
android-app.css 77KB
nihilo.css 76KB
tundra.css 75KB
soria.css 74KB
custom.css 74KB
iphone.css 72KB
blackberry.css 72KB
android.css 71KB
base.css 66KB
EnhancedGrid.css 34KB
tundraEnhancedGrid.css 34KB
EnhancedGrid.css 33KB
claroEnhancedGrid.css 33KB
dijit.css 29KB
domButtons.css 22KB
custom-compat.css 20KB
android-app-compat.css 20KB
blackberry-compat.css 20KB
iphone-app-compat.css 20KB
android-compat.css 20KB
iphone-compat.css 20KB
Calendar.css 17KB
base.css 16KB
EnhancedGrid.css 16KB
base.css 16KB
base.css 15KB
base.css 15KB
claroGrid.css 14KB
FilePickerTextBox.css 12KB
tundraGrid.css 12KB
TabContainer.css 12KB
soriaGrid.css 12KB
nihiloGrid.css 11KB
claro_rtl.css 11KB
TabContainer.css 10KB
gantt.css 10KB
TabContainer.css 10KB
transitions.css 9KB
Slider.css 9KB
Grid.css 7KB
PopupMobile.css 7KB
Popup.css 7KB
jsdoc.css 7KB
EnhancedGrid_rtl.css 6KB
image.css 6KB
Calendar.css 6KB
base-compat.css 6KB
Calendar.css 6KB
CheckedMultiSelect.css 6KB
domButtons-compat.css 6KB
TabContainer.css 6KB
Opener.css 5KB
ExpandoPane.css 5KB
nihilo_rtl.css 5KB
Opener.css 5KB
soria_rtl.css 5KB
Filter.css 5KB
Opener.css 5KB
Sorter.css 5KB
base-compat.css 5KB
IconContainer.css 5KB
Opener.css 5KB
Toolbar.css 5KB
base-compat.css 5KB
FilePicker.css 5KB
IconContainer.css 5KB
base-compat.css 5KB
IconContainer.css 5KB
IconContainer.css 5KB
tundra_rtl.css 5KB
jsapi.css 5KB
toolbar.css 5KB
commonIcons.css 4KB
Switch.css 4KB
TabBar.css 4KB
Portlet.css 4KB
Common.css 4KB
Switch.css 4KB
Switch.css 4KB
Switch.css 4KB
Slider.css 4KB
Slider.css 4KB
Slider.css 4KB
commonIcons_rtl.css 4KB
TabBar.css 4KB
firebug.css 4KB
FloatingPane.css 4KB
共 4939 条
- 1
- 2
- 3
- 4
- 5
- 6
- 50
资源评论
- wbh01252013-08-15没什么说的,内容如题,资源可用
- 地理小子2013-02-23感谢提供,资源可用
不怎么迷糊
- 粉丝: 23
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MAE-Masked Autoencoders Are Scalable Vision Learners
- quark(夸克)正版下载
- ssoPlusFrontdsfdsfdsfsadawsdad
- 基于ARM Cortex-M3 内核的 STM32F103C8T6 系统板为载体,实现了的智能点阵屏的设计【课程设计/毕业设计】(源码+论文)
- Hierarchical Consensus Hashing for Cross-Modal Retrieval
- 基于 C++ OpenCV视觉库实现的计算机视觉分析,得到手掌上五根手指的长度与宽度、手掌虎口的角度、手掌的宽度以及手腕的宽度 完成对手掌各个参数的精确测量课程设计(源码+报告)
- 联想7400打印机更换定影组件.jpg
- 基于servlet+jsp+mysql实现的影视管理系统课程设计
- 正点原子RK3568卡片电脑ATOMPI-CA1的ubuntu-22.04.5最小安装包,特别适合运行板级ROS2环境iron
- GUIdemo.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功