├── LICENSE ├── README.md ├── demo ├── back-phone.png ├── onepage-scroll.css ├── phones.png ├── tilted-phone.png ├── zepto.js ├── zepto.onepagescroll.js └── zepto_onepage_scroll_demo.html ├── onepage-scroll.css ├── zepto.onepagescroll.js └── zepto.onepagescroll.min.js /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Zepto One Page Scroll by Pete R. 2 | A Zepto JS plugin that creates an Apple-like one page scroll website (iPhone 5S website) 3 | 4 | Created by [Pete R.](http://www.thepetedesign.com), Founder of [Travelistly](http://www.Travelistly.com) and [BucketListly](http://www.bucketlistly.com) 5 | 6 | License: [Attribution-ShareAlike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/deed.en_US) 7 | 8 | ## Requirement 9 | 10 | - [Zepto JS (1.1.3 or later)](http://zeptojs.com/) 11 | - [Zepto JS FX Module](https://github.com/madrobby/zepto/blob/master/src/fx.js#files) 12 | 13 | ## Demo 14 | [View demo](http://peachananr.github.io/zepto-onepage-scroll/demo/zepto_onepage_scroll_demo.html) 15 | 16 | ##Looking for a Pure JS version? 17 | [Pure JS Version](http://peachananr.github.io/purejs-onepage-scroll/demo/purejs_onepage_scroll_demo.html) 18 | 19 | ##Looking for a jQuery version? 20 | [jQuery Version](http://peachananr.github.io/onepage-scroll/Demo/demo.html) 21 | 22 | 23 | ## Compatibility 24 | Modern browsers such as Chrome, Firefox, and Safari on both desktop and smartphones have been tested. Not tested on IE. 25 | 26 | ## Basic Usage 27 | One Page Scroll let you transform your website into a one page scroll website that allows users to scroll one page at a time. It is perfect for creating a website in which you want to present something to the viewers. For example, [Apple's iPhone 5S website](http://www.apple.com/iphone-5s/) uses the same technique. 28 | 29 | 30 | To add this to your website, simply include the latest ZeptoJS library together with ZeptoJS FX Module, `zepto.onepage-scroll.js`, `onepage-scroll.css` into your document's `` and call the function as follows: 31 | 32 | ````html 33 | 34 | ... 35 |
36 |
...
37 |
...
38 | ... 39 |
40 | ... 41 | 42 | ```` 43 | Container "Main" must be one level below the `body` tag in order to make it work full page. Now call the function to activate as follows: 44 | 45 | ````javascript 46 | Zepto(".main").onePageScroll({ 47 | sectionContainer: "section", // sectionContainer accepts any kind of selector in case you don't want to use section 48 | easing: "ease", // Easing options accepts the CSS3 easing animation such "ease", "linear", "ease-in", 49 | // "ease-out", "ease-in-out", or even cubic bezier value such as "cubic-bezier(0.175, 0.885, 0.420, 1.310)" 50 | animationTime: 1000, // AnimationTime let you define how long each section takes to animate 51 | pagination: true, // You can either show or hide the pagination. Toggle true for show, false for hide. 52 | updateURL: false, // Toggle this true if you want the URL to be updated automatically when the user scroll to each page. 53 | beforeMove: function(index) {}, // This option accepts a callback function. The function will be called before the page moves. 54 | afterMove: function(index) {}, // This option accepts a callback function. The function will be called after the page moves. 55 | loop: false, // You can have the page loop back to the top/bottom when the user navigates at up/down on the first/last page. 56 | keyboard: true, // You can activate the keyboard controls 57 | responsiveFallback: false // You can fallback to normal page scroll by defining the width of the browser in which 58 | // you want the responsive fallback to be triggered. For example, set this to 600 and whenever 59 | // the browser's width is less than 600, the fallback will kick in. 60 | }); 61 | ```` 62 | And that's it. Now, your website should work the same way Apple's iPhone 5S website does. You should be able to swipe up/down as well (thanks to [Eike Send](https://github.com/eikes) for his swipe events!) when viewing your website on mobile phones. 63 | 64 | ## Public Methods 65 | You can also trigger page move programmatically as well: 66 | 67 | ### Zepto.fn.moveUp() 68 | This method allows you to move the page up by one. This action is equivalent to scrolling up/swiping down. 69 | 70 | ````javascript 71 | Zepto(".main").moveUp(); 72 | ```` 73 | 74 | ### Zepto.fn.moveDown() 75 | This method allows you to move the page down by one. This action is equivalent to scrolling down/swiping up. 76 | 77 | ````javascript 78 | Zepto(".main").moveDown(); 79 | ```` 80 | 81 | ### Zepto.fn.moveTo(page_index) 82 | This method allows you to move to the specified page index programatically. 83 | 84 | ````javascript 85 | Zepto(".main").moveTo(3); 86 | ```` 87 | 88 | ## Callbacks 89 | You can use callbacks to perform actions before or after the page move. 90 | 91 | ### beforeMove(next_page_index, next_section_element) 92 | This callback gets called before the plugin performs its move. 93 | 94 | ````javascript 95 | Zepto(".main").onepage_scroll({ 96 | beforeMove: function(index, next_el) { 97 | ... 98 | } 99 | }); 100 | ```` 101 | 102 | ### afterMove(next_page_index, next_section_element) 103 | This callback gets called after the move animation was performed. 104 | 105 | ````javascript 106 | Zepto(".main").onepage_scroll({ 107 | afterMove: function(index, next_el) { 108 | ... 109 | } 110 | }); 111 | ```` 112 | 113 | If you want to see more of my plugins, visit [The Pete Design](http://www.thepetedesign.com/#design), or follow me on [Twitter](http://www.twitter.com/peachananr) and [Github](http://www.github.com/peachananr). 114 | 115 | ## Other Resources 116 | - [Pure JS Version](http://www.thepetedesign.com/demos/purejs_onepage_scroll_demo.html) 117 | - [jQuery Version](http://www.thepetedesign.com/demos/onepage_scroll_demo.html) 118 | - [OnePageScroll.js: Creating an Apple’s iPhone 5S Website](http://www.onextrapixel.com/2013/09/18/onepagescroll-js-creating-an-apples-iphone-5s-website/) 119 | - [Eike Send's jQuery Swipe Events](https://github.com/eikes/jquery.swipe-events.js) 120 | - [CSS Easing generator by Matthew Lein](http://matthewlein.com/ceaser/) 121 | -------------------------------------------------------------------------------- /demo/back-phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peachananr/zepto-onepage-scroll/cda4bd802fdd202d6bf88a471cac0fa963fb2222/demo/back-phone.png -------------------------------------------------------------------------------- /demo/onepage-scroll.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin: 0; 3 | overflow: hidden; 4 | -webkit-transition: opacity 400ms; 5 | -moz-transition: opacity 400ms; 6 | transition: opacity 400ms; 7 | } 8 | 9 | body, .onepage-wrapper, html { 10 | display: block; 11 | position: static; 12 | padding: 0; 13 | width: 100%; 14 | height: 100%; 15 | } 16 | 17 | .onepage-wrapper { 18 | width: 100%; 19 | height: 100%; 20 | display: block; 21 | position: relative; 22 | padding: 0; 23 | -webkit-transform-style: preserve-3d; 24 | } 25 | 26 | .onepage-wrapper .ops-section { 27 | width: 100%; 28 | height: 100%; 29 | position: relative; 30 | } 31 | 32 | .onepage-pagination { 33 | position: absolute; 34 | right: 10px; 35 | top: 50%; 36 | z-index: 5; 37 | list-style: none; 38 | margin: 0; 39 | padding: 0; 40 | } 41 | .onepage-pagination li { 42 | padding: 0; 43 | text-align: center; 44 | } 45 | .onepage-pagination li a{ 46 | padding: 10px; 47 | width: 4px; 48 | height: 4px; 49 | display: block; 50 | 51 | } 52 | .onepage-pagination li a:before{ 53 | content: ''; 54 | position: absolute; 55 | width: 4px; 56 | height: 4px; 57 | background: rgba(0,0,0,0.85); 58 | border-radius: 10px; 59 | -webkit-border-radius: 10px; 60 | -moz-border-radius: 10px; 61 | } 62 | 63 | .onepage-pagination li a.active:before{ 64 | width: 10px; 65 | height: 10px; 66 | background: none; 67 | border: 1px solid black; 68 | margin-top: -4px; 69 | left: 8px; 70 | } 71 | 72 | .disabled-onepage-scroll, .disabled-onepage-scroll .wrapper { 73 | overflow: auto; 74 | } 75 | 76 | .disabled-onepage-scroll .onepage-wrapper .ops-section { 77 | position: relative !important; 78 | top: auto !important; 79 | } 80 | .disabled-onepage-scroll .onepage-wrapper { 81 | -webkit-transform: none !important; 82 | -moz-transform: none !important; 83 | transform: none !important; 84 | -ms-transform: none !important; 85 | min-height: 100%; 86 | } 87 | 88 | 89 | .disabled-onepage-scroll .onepage-pagination { 90 | display: none; 91 | } 92 | 93 | body.disabled-onepage-scroll, .disabled-onepage-scroll .onepage-wrapper, html { 94 | position: inherit; 95 | } -------------------------------------------------------------------------------- /demo/phones.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peachananr/zepto-onepage-scroll/cda4bd802fdd202d6bf88a471cac0fa963fb2222/demo/phones.png -------------------------------------------------------------------------------- /demo/tilted-phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peachananr/zepto-onepage-scroll/cda4bd802fdd202d6bf88a471cac0fa963fb2222/demo/tilted-phone.png -------------------------------------------------------------------------------- /demo/zepto.js: -------------------------------------------------------------------------------- 1 | /* Zepto v1.1.3 - zepto event ajax form ie - zeptojs.com/license */ 2 | 3 | 4 | var Zepto = (function() { 5 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, 6 | document = window.document, 7 | elementDisplay = {}, classCache = {}, 8 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, 9 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, 10 | singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, 11 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, 12 | rootNodeRE = /^(?:body|html)$/i, 13 | capitalRE = /([A-Z])/g, 14 | 15 | // special attributes that should be get/set via method calls 16 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], 17 | 18 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], 19 | table = document.createElement('table'), 20 | tableRow = document.createElement('tr'), 21 | containers = { 22 | 'tr': document.createElement('tbody'), 23 | 'tbody': table, 'thead': table, 'tfoot': table, 24 | 'td': tableRow, 'th': tableRow, 25 | '*': document.createElement('div') 26 | }, 27 | readyRE = /complete|loaded|interactive/, 28 | simpleSelectorRE = /^[\w-]*$/, 29 | class2type = {}, 30 | toString = class2type.toString, 31 | zepto = {}, 32 | camelize, uniq, 33 | tempParent = document.createElement('div'), 34 | propMap = { 35 | 'tabindex': 'tabIndex', 36 | 'readonly': 'readOnly', 37 | 'for': 'htmlFor', 38 | 'class': 'className', 39 | 'maxlength': 'maxLength', 40 | 'cellspacing': 'cellSpacing', 41 | 'cellpadding': 'cellPadding', 42 | 'rowspan': 'rowSpan', 43 | 'colspan': 'colSpan', 44 | 'usemap': 'useMap', 45 | 'frameborder': 'frameBorder', 46 | 'contenteditable': 'contentEditable' 47 | }, 48 | isArray = Array.isArray || 49 | function(object){ return object instanceof Array } 50 | 51 | zepto.matches = function(element, selector) { 52 | if (!selector || !element || element.nodeType !== 1) return false 53 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || 54 | element.oMatchesSelector || element.matchesSelector 55 | if (matchesSelector) return matchesSelector.call(element, selector) 56 | // fall back to performing a selector: 57 | var match, parent = element.parentNode, temp = !parent 58 | if (temp) (parent = tempParent).appendChild(element) 59 | match = ~zepto.qsa(parent, selector).indexOf(element) 60 | temp && tempParent.removeChild(element) 61 | return match 62 | } 63 | 64 | function type(obj) { 65 | return obj == null ? String(obj) : 66 | class2type[toString.call(obj)] || "object" 67 | } 68 | 69 | function isFunction(value) { return type(value) == "function" } 70 | function isWindow(obj) { return obj != null && obj == obj.window } 71 | function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } 72 | function isObject(obj) { return type(obj) == "object" } 73 | function isPlainObject(obj) { 74 | return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype 75 | } 76 | function likeArray(obj) { return typeof obj.length == 'number' } 77 | 78 | function compact(array) { return filter.call(array, function(item){ return item != null }) } 79 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } 80 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } 81 | function dasherize(str) { 82 | return str.replace(/::/g, '/') 83 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') 84 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') 85 | .replace(/_/g, '-') 86 | .toLowerCase() 87 | } 88 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } 89 | 90 | function classRE(name) { 91 | return name in classCache ? 92 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) 93 | } 94 | 95 | function maybeAddPx(name, value) { 96 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value 97 | } 98 | 99 | function defaultDisplay(nodeName) { 100 | var element, display 101 | if (!elementDisplay[nodeName]) { 102 | element = document.createElement(nodeName) 103 | document.body.appendChild(element) 104 | display = getComputedStyle(element, '').getPropertyValue("display") 105 | element.parentNode.removeChild(element) 106 | display == "none" && (display = "block") 107 | elementDisplay[nodeName] = display 108 | } 109 | return elementDisplay[nodeName] 110 | } 111 | 112 | function children(element) { 113 | return 'children' in element ? 114 | slice.call(element.children) : 115 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) 116 | } 117 | 118 | // `$.zepto.fragment` takes a html string and an optional tag name 119 | // to generate DOM nodes nodes from the given html string. 120 | // The generated DOM nodes are returned as an array. 121 | // This function can be overriden in plugins for example to make 122 | // it compatible with browsers that don't support the DOM fully. 123 | zepto.fragment = function(html, name, properties) { 124 | var dom, nodes, container 125 | 126 | // A special case optimization for a single tag 127 | if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1)) 128 | 129 | if (!dom) { 130 | if (html.replace) html = html.replace(tagExpanderRE, "<$1>") 131 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 132 | if (!(name in containers)) name = '*' 133 | 134 | container = containers[name] 135 | container.innerHTML = '' + html 136 | dom = $.each(slice.call(container.childNodes), function(){ 137 | container.removeChild(this) 138 | }) 139 | } 140 | 141 | if (isPlainObject(properties)) { 142 | nodes = $(dom) 143 | $.each(properties, function(key, value) { 144 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) 145 | else nodes.attr(key, value) 146 | }) 147 | } 148 | 149 | return dom 150 | } 151 | 152 | // `$.zepto.Z` swaps out the prototype of the given `dom` array 153 | // of nodes with `$.fn` and thus supplying all the Zepto functions 154 | // to the array. Note that `__proto__` is not supported on Internet 155 | // Explorer. This method can be overriden in plugins. 156 | zepto.Z = function(dom, selector) { 157 | dom = dom || [] 158 | dom.__proto__ = $.fn 159 | dom.selector = selector || '' 160 | return dom 161 | } 162 | 163 | // `$.zepto.isZ` should return `true` if the given object is a Zepto 164 | // collection. This method can be overriden in plugins. 165 | zepto.isZ = function(object) { 166 | return object instanceof zepto.Z 167 | } 168 | 169 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and 170 | // takes a CSS selector and an optional context (and handles various 171 | // special cases). 172 | // This method can be overriden in plugins. 173 | zepto.init = function(selector, context) { 174 | var dom 175 | // If nothing given, return an empty Zepto collection 176 | if (!selector) return zepto.Z() 177 | // Optimize for string selectors 178 | else if (typeof selector == 'string') { 179 | selector = selector.trim() 180 | // If it's a html fragment, create nodes from it 181 | // Note: In both Chrome 21 and Firefox 15, DOM error 12 182 | // is thrown if the fragment doesn't begin with < 183 | if (selector[0] == '<' && fragmentRE.test(selector)) 184 | dom = zepto.fragment(selector, RegExp.$1, context), selector = null 185 | // If there's a context, create a collection on that context first, and select 186 | // nodes from there 187 | else if (context !== undefined) return $(context).find(selector) 188 | // If it's a CSS selector, use it to select nodes. 189 | else dom = zepto.qsa(document, selector) 190 | } 191 | // If a function is given, call it when the DOM is ready 192 | else if (isFunction(selector)) return $(document).ready(selector) 193 | // If a Zepto collection is given, just return it 194 | else if (zepto.isZ(selector)) return selector 195 | else { 196 | // normalize array if an array of nodes is given 197 | if (isArray(selector)) dom = compact(selector) 198 | // Wrap DOM nodes. 199 | else if (isObject(selector)) 200 | dom = [selector], selector = null 201 | // If it's a html fragment, create nodes from it 202 | else if (fragmentRE.test(selector)) 203 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null 204 | // If there's a context, create a collection on that context first, and select 205 | // nodes from there 206 | else if (context !== undefined) return $(context).find(selector) 207 | // And last but no least, if it's a CSS selector, use it to select nodes. 208 | else dom = zepto.qsa(document, selector) 209 | } 210 | // create a new Zepto collection from the nodes found 211 | return zepto.Z(dom, selector) 212 | } 213 | 214 | // `$` will be the base `Zepto` object. When calling this 215 | // function just call `$.zepto.init, which makes the implementation 216 | // details of selecting nodes and creating Zepto collections 217 | // patchable in plugins. 218 | $ = function(selector, context){ 219 | return zepto.init(selector, context) 220 | } 221 | 222 | function extend(target, source, deep) { 223 | for (key in source) 224 | if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 225 | if (isPlainObject(source[key]) && !isPlainObject(target[key])) 226 | target[key] = {} 227 | if (isArray(source[key]) && !isArray(target[key])) 228 | target[key] = [] 229 | extend(target[key], source[key], deep) 230 | } 231 | else if (source[key] !== undefined) target[key] = source[key] 232 | } 233 | 234 | // Copy all but undefined properties from one or more 235 | // objects to the `target` object. 236 | $.extend = function(target){ 237 | var deep, args = slice.call(arguments, 1) 238 | if (typeof target == 'boolean') { 239 | deep = target 240 | target = args.shift() 241 | } 242 | args.forEach(function(arg){ extend(target, arg, deep) }) 243 | return target 244 | } 245 | 246 | // `$.zepto.qsa` is Zepto's CSS selector implementation which 247 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. 248 | // This method can be overriden in plugins. 249 | zepto.qsa = function(element, selector){ 250 | var found, 251 | maybeID = selector[0] == '#', 252 | maybeClass = !maybeID && selector[0] == '.', 253 | nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked 254 | isSimple = simpleSelectorRE.test(nameOnly) 255 | return (isDocument(element) && isSimple && maybeID) ? 256 | ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : 257 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : 258 | slice.call( 259 | isSimple && !maybeID ? 260 | maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class 261 | element.getElementsByTagName(selector) : // Or a tag 262 | element.querySelectorAll(selector) // Or it's not simple, and we need to query all 263 | ) 264 | } 265 | 266 | function filtered(nodes, selector) { 267 | return selector == null ? $(nodes) : $(nodes).filter(selector) 268 | } 269 | 270 | $.contains = function(parent, node) { 271 | return parent !== node && parent.contains(node) 272 | } 273 | 274 | function funcArg(context, arg, idx, payload) { 275 | return isFunction(arg) ? arg.call(context, idx, payload) : arg 276 | } 277 | 278 | function setAttribute(node, name, value) { 279 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) 280 | } 281 | 282 | // access className property while respecting SVGAnimatedString 283 | function className(node, value){ 284 | var klass = node.className, 285 | svg = klass && klass.baseVal !== undefined 286 | 287 | if (value === undefined) return svg ? klass.baseVal : klass 288 | svg ? (klass.baseVal = value) : (node.className = value) 289 | } 290 | 291 | // "true" => true 292 | // "false" => false 293 | // "null" => null 294 | // "42" => 42 295 | // "42.5" => 42.5 296 | // "08" => "08" 297 | // JSON => parse if valid 298 | // String => self 299 | function deserializeValue(value) { 300 | var num 301 | try { 302 | return value ? 303 | value == "true" || 304 | ( value == "false" ? false : 305 | value == "null" ? null : 306 | !/^0/.test(value) && !isNaN(num = Number(value)) ? num : 307 | /^[\[\{]/.test(value) ? $.parseJSON(value) : 308 | value ) 309 | : value 310 | } catch(e) { 311 | return value 312 | } 313 | } 314 | 315 | $.type = type 316 | $.isFunction = isFunction 317 | $.isWindow = isWindow 318 | $.isArray = isArray 319 | $.isPlainObject = isPlainObject 320 | 321 | $.isEmptyObject = function(obj) { 322 | var name 323 | for (name in obj) return false 324 | return true 325 | } 326 | 327 | $.inArray = function(elem, array, i){ 328 | return emptyArray.indexOf.call(array, elem, i) 329 | } 330 | 331 | $.camelCase = camelize 332 | $.trim = function(str) { 333 | return str == null ? "" : String.prototype.trim.call(str) 334 | } 335 | 336 | // plugin compatibility 337 | $.uuid = 0 338 | $.support = { } 339 | $.expr = { } 340 | 341 | $.map = function(elements, callback){ 342 | var value, values = [], i, key 343 | if (likeArray(elements)) 344 | for (i = 0; i < elements.length; i++) { 345 | value = callback(elements[i], i) 346 | if (value != null) values.push(value) 347 | } 348 | else 349 | for (key in elements) { 350 | value = callback(elements[key], key) 351 | if (value != null) values.push(value) 352 | } 353 | return flatten(values) 354 | } 355 | 356 | $.each = function(elements, callback){ 357 | var i, key 358 | if (likeArray(elements)) { 359 | for (i = 0; i < elements.length; i++) 360 | if (callback.call(elements[i], i, elements[i]) === false) return elements 361 | } else { 362 | for (key in elements) 363 | if (callback.call(elements[key], key, elements[key]) === false) return elements 364 | } 365 | 366 | return elements 367 | } 368 | 369 | $.grep = function(elements, callback){ 370 | return filter.call(elements, callback) 371 | } 372 | 373 | if (window.JSON) $.parseJSON = JSON.parse 374 | 375 | // Populate the class2type map 376 | $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { 377 | class2type[ "[object " + name + "]" ] = name.toLowerCase() 378 | }) 379 | 380 | // Define methods that will be available on all 381 | // Zepto collections 382 | $.fn = { 383 | // Because a collection acts like an array 384 | // copy over these useful array functions. 385 | forEach: emptyArray.forEach, 386 | reduce: emptyArray.reduce, 387 | push: emptyArray.push, 388 | sort: emptyArray.sort, 389 | indexOf: emptyArray.indexOf, 390 | concat: emptyArray.concat, 391 | 392 | // `map` and `slice` in the jQuery API work differently 393 | // from their array counterparts 394 | map: function(fn){ 395 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) 396 | }, 397 | slice: function(){ 398 | return $(slice.apply(this, arguments)) 399 | }, 400 | 401 | ready: function(callback){ 402 | // need to check if document.body exists for IE as that browser reports 403 | // document ready when it hasn't yet created the body element 404 | if (readyRE.test(document.readyState) && document.body) callback($) 405 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) 406 | return this 407 | }, 408 | get: function(idx){ 409 | return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] 410 | }, 411 | toArray: function(){ return this.get() }, 412 | size: function(){ 413 | return this.length 414 | }, 415 | remove: function(){ 416 | return this.each(function(){ 417 | if (this.parentNode != null) 418 | this.parentNode.removeChild(this) 419 | }) 420 | }, 421 | each: function(callback){ 422 | emptyArray.every.call(this, function(el, idx){ 423 | return callback.call(el, idx, el) !== false 424 | }) 425 | return this 426 | }, 427 | filter: function(selector){ 428 | if (isFunction(selector)) return this.not(this.not(selector)) 429 | return $(filter.call(this, function(element){ 430 | return zepto.matches(element, selector) 431 | })) 432 | }, 433 | add: function(selector,context){ 434 | return $(uniq(this.concat($(selector,context)))) 435 | }, 436 | is: function(selector){ 437 | return this.length > 0 && zepto.matches(this[0], selector) 438 | }, 439 | not: function(selector){ 440 | var nodes=[] 441 | if (isFunction(selector) && selector.call !== undefined) 442 | this.each(function(idx){ 443 | if (!selector.call(this,idx)) nodes.push(this) 444 | }) 445 | else { 446 | var excludes = typeof selector == 'string' ? this.filter(selector) : 447 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) 448 | this.forEach(function(el){ 449 | if (excludes.indexOf(el) < 0) nodes.push(el) 450 | }) 451 | } 452 | return $(nodes) 453 | }, 454 | has: function(selector){ 455 | return this.filter(function(){ 456 | return isObject(selector) ? 457 | $.contains(this, selector) : 458 | $(this).find(selector).size() 459 | }) 460 | }, 461 | eq: function(idx){ 462 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) 463 | }, 464 | first: function(){ 465 | var el = this[0] 466 | return el && !isObject(el) ? el : $(el) 467 | }, 468 | last: function(){ 469 | var el = this[this.length - 1] 470 | return el && !isObject(el) ? el : $(el) 471 | }, 472 | find: function(selector){ 473 | var result, $this = this 474 | if (typeof selector == 'object') 475 | result = $(selector).filter(function(){ 476 | var node = this 477 | return emptyArray.some.call($this, function(parent){ 478 | return $.contains(parent, node) 479 | }) 480 | }) 481 | else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) 482 | else result = this.map(function(){ return zepto.qsa(this, selector) }) 483 | return result 484 | }, 485 | closest: function(selector, context){ 486 | var node = this[0], collection = false 487 | if (typeof selector == 'object') collection = $(selector) 488 | while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) 489 | node = node !== context && !isDocument(node) && node.parentNode 490 | return $(node) 491 | }, 492 | parents: function(selector){ 493 | var ancestors = [], nodes = this 494 | while (nodes.length > 0) 495 | nodes = $.map(nodes, function(node){ 496 | if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { 497 | ancestors.push(node) 498 | return node 499 | } 500 | }) 501 | return filtered(ancestors, selector) 502 | }, 503 | parent: function(selector){ 504 | return filtered(uniq(this.pluck('parentNode')), selector) 505 | }, 506 | children: function(selector){ 507 | return filtered(this.map(function(){ return children(this) }), selector) 508 | }, 509 | contents: function() { 510 | return this.map(function() { return slice.call(this.childNodes) }) 511 | }, 512 | siblings: function(selector){ 513 | return filtered(this.map(function(i, el){ 514 | return filter.call(children(el.parentNode), function(child){ return child!==el }) 515 | }), selector) 516 | }, 517 | empty: function(){ 518 | return this.each(function(){ this.innerHTML = '' }) 519 | }, 520 | // `pluck` is borrowed from Prototype.js 521 | pluck: function(property){ 522 | return $.map(this, function(el){ return el[property] }) 523 | }, 524 | show: function(){ 525 | return this.each(function(){ 526 | this.style.display == "none" && (this.style.display = '') 527 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") 528 | this.style.display = defaultDisplay(this.nodeName) 529 | }) 530 | }, 531 | replaceWith: function(newContent){ 532 | return this.before(newContent).remove() 533 | }, 534 | wrap: function(structure){ 535 | var func = isFunction(structure) 536 | if (this[0] && !func) 537 | var dom = $(structure).get(0), 538 | clone = dom.parentNode || this.length > 1 539 | 540 | return this.each(function(index){ 541 | $(this).wrapAll( 542 | func ? structure.call(this, index) : 543 | clone ? dom.cloneNode(true) : dom 544 | ) 545 | }) 546 | }, 547 | wrapAll: function(structure){ 548 | if (this[0]) { 549 | $(this[0]).before(structure = $(structure)) 550 | var children 551 | // drill down to the inmost element 552 | while ((children = structure.children()).length) structure = children.first() 553 | $(structure).append(this) 554 | } 555 | return this 556 | }, 557 | wrapInner: function(structure){ 558 | var func = isFunction(structure) 559 | return this.each(function(index){ 560 | var self = $(this), contents = self.contents(), 561 | dom = func ? structure.call(this, index) : structure 562 | contents.length ? contents.wrapAll(dom) : self.append(dom) 563 | }) 564 | }, 565 | unwrap: function(){ 566 | this.parent().each(function(){ 567 | $(this).replaceWith($(this).children()) 568 | }) 569 | return this 570 | }, 571 | clone: function(){ 572 | return this.map(function(){ return this.cloneNode(true) }) 573 | }, 574 | hide: function(){ 575 | return this.css("display", "none") 576 | }, 577 | toggle: function(setting){ 578 | return this.each(function(){ 579 | var el = $(this) 580 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() 581 | }) 582 | }, 583 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, 584 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, 585 | html: function(html){ 586 | return arguments.length === 0 ? 587 | (this.length > 0 ? this[0].innerHTML : null) : 588 | this.each(function(idx){ 589 | var originHtml = this.innerHTML 590 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) 591 | }) 592 | }, 593 | text: function(text){ 594 | return arguments.length === 0 ? 595 | (this.length > 0 ? this[0].textContent : null) : 596 | this.each(function(){ this.textContent = (text === undefined) ? '' : ''+text }) 597 | }, 598 | attr: function(name, value){ 599 | var result 600 | return (typeof name == 'string' && value === undefined) ? 601 | (this.length == 0 || this[0].nodeType !== 1 ? undefined : 602 | (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() : 603 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result 604 | ) : 605 | this.each(function(idx){ 606 | if (this.nodeType !== 1) return 607 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) 608 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) 609 | }) 610 | }, 611 | removeAttr: function(name){ 612 | return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) }) 613 | }, 614 | prop: function(name, value){ 615 | name = propMap[name] || name 616 | return (value === undefined) ? 617 | (this[0] && this[0][name]) : 618 | this.each(function(idx){ 619 | this[name] = funcArg(this, value, idx, this[name]) 620 | }) 621 | }, 622 | data: function(name, value){ 623 | var data = this.attr('data-' + name.replace(capitalRE, '-$1').toLowerCase(), value) 624 | return data !== null ? deserializeValue(data) : undefined 625 | }, 626 | val: function(value){ 627 | return arguments.length === 0 ? 628 | (this[0] && (this[0].multiple ? 629 | $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : 630 | this[0].value) 631 | ) : 632 | this.each(function(idx){ 633 | this.value = funcArg(this, value, idx, this.value) 634 | }) 635 | }, 636 | offset: function(coordinates){ 637 | if (coordinates) return this.each(function(index){ 638 | var $this = $(this), 639 | coords = funcArg(this, coordinates, index, $this.offset()), 640 | parentOffset = $this.offsetParent().offset(), 641 | props = { 642 | top: coords.top - parentOffset.top, 643 | left: coords.left - parentOffset.left 644 | } 645 | 646 | if ($this.css('position') == 'static') props['position'] = 'relative' 647 | $this.css(props) 648 | }) 649 | if (this.length==0) return null 650 | var obj = this[0].getBoundingClientRect() 651 | return { 652 | left: obj.left + window.pageXOffset, 653 | top: obj.top + window.pageYOffset, 654 | width: Math.round(obj.width), 655 | height: Math.round(obj.height) 656 | } 657 | }, 658 | css: function(property, value){ 659 | if (arguments.length < 2) { 660 | var element = this[0], computedStyle = getComputedStyle(element, '') 661 | if(!element) return 662 | if (typeof property == 'string') 663 | return element.style[camelize(property)] || computedStyle.getPropertyValue(property) 664 | else if (isArray(property)) { 665 | var props = {} 666 | $.each(isArray(property) ? property: [property], function(_, prop){ 667 | props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) 668 | }) 669 | return props 670 | } 671 | } 672 | 673 | var css = '' 674 | if (type(property) == 'string') { 675 | if (!value && value !== 0) 676 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) 677 | else 678 | css = dasherize(property) + ":" + maybeAddPx(property, value) 679 | } else { 680 | for (key in property) 681 | if (!property[key] && property[key] !== 0) 682 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) 683 | else 684 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' 685 | } 686 | 687 | return this.each(function(){ this.style.cssText += ';' + css }) 688 | }, 689 | index: function(element){ 690 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) 691 | }, 692 | hasClass: function(name){ 693 | if (!name) return false 694 | return emptyArray.some.call(this, function(el){ 695 | return this.test(className(el)) 696 | }, classRE(name)) 697 | }, 698 | addClass: function(name){ 699 | if (!name) return this 700 | return this.each(function(idx){ 701 | classList = [] 702 | var cls = className(this), newName = funcArg(this, name, idx, cls) 703 | newName.split(/\s+/g).forEach(function(klass){ 704 | if (!$(this).hasClass(klass)) classList.push(klass) 705 | }, this) 706 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) 707 | }) 708 | }, 709 | removeClass: function(name){ 710 | return this.each(function(idx){ 711 | if (name === undefined) return className(this, '') 712 | classList = className(this) 713 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ 714 | classList = classList.replace(classRE(klass), " ") 715 | }) 716 | className(this, classList.trim()) 717 | }) 718 | }, 719 | toggleClass: function(name, when){ 720 | if (!name) return this 721 | return this.each(function(idx){ 722 | var $this = $(this), names = funcArg(this, name, idx, className(this)) 723 | names.split(/\s+/g).forEach(function(klass){ 724 | (when === undefined ? !$this.hasClass(klass) : when) ? 725 | $this.addClass(klass) : $this.removeClass(klass) 726 | }) 727 | }) 728 | }, 729 | scrollTop: function(value){ 730 | if (!this.length) return 731 | var hasScrollTop = 'scrollTop' in this[0] 732 | if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset 733 | return this.each(hasScrollTop ? 734 | function(){ this.scrollTop = value } : 735 | function(){ this.scrollTo(this.scrollX, value) }) 736 | }, 737 | scrollLeft: function(value){ 738 | if (!this.length) return 739 | var hasScrollLeft = 'scrollLeft' in this[0] 740 | if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset 741 | return this.each(hasScrollLeft ? 742 | function(){ this.scrollLeft = value } : 743 | function(){ this.scrollTo(value, this.scrollY) }) 744 | }, 745 | position: function() { 746 | if (!this.length) return 747 | 748 | var elem = this[0], 749 | // Get *real* offsetParent 750 | offsetParent = this.offsetParent(), 751 | // Get correct offsets 752 | offset = this.offset(), 753 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() 754 | 755 | // Subtract element margins 756 | // note: when an element has margin: auto the offsetLeft and marginLeft 757 | // are the same in Safari causing offset.left to incorrectly be 0 758 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 759 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 760 | 761 | // Add offsetParent borders 762 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 763 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 764 | 765 | // Subtract the two offsets 766 | return { 767 | top: offset.top - parentOffset.top, 768 | left: offset.left - parentOffset.left 769 | } 770 | }, 771 | offsetParent: function() { 772 | return this.map(function(){ 773 | var parent = this.offsetParent || document.body 774 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") 775 | parent = parent.offsetParent 776 | return parent 777 | }) 778 | } 779 | } 780 | 781 | // for now 782 | $.fn.detach = $.fn.remove 783 | 784 | // Generate the `width` and `height` functions 785 | ;['width', 'height'].forEach(function(dimension){ 786 | var dimensionProperty = 787 | dimension.replace(/./, function(m){ return m[0].toUpperCase() }) 788 | 789 | $.fn[dimension] = function(value){ 790 | var offset, el = this[0] 791 | if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : 792 | isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : 793 | (offset = this.offset()) && offset[dimension] 794 | else return this.each(function(idx){ 795 | el = $(this) 796 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) 797 | }) 798 | } 799 | }) 800 | 801 | function traverseNode(node, fun) { 802 | fun(node) 803 | for (var key in node.childNodes) traverseNode(node.childNodes[key], fun) 804 | } 805 | 806 | // Generate the `after`, `prepend`, `before`, `append`, 807 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. 808 | adjacencyOperators.forEach(function(operator, operatorIndex) { 809 | var inside = operatorIndex % 2 //=> prepend, append 810 | 811 | $.fn[operator] = function(){ 812 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings 813 | var argType, nodes = $.map(arguments, function(arg) { 814 | argType = type(arg) 815 | return argType == "object" || argType == "array" || arg == null ? 816 | arg : zepto.fragment(arg) 817 | }), 818 | parent, copyByClone = this.length > 1 819 | if (nodes.length < 1) return this 820 | 821 | return this.each(function(_, target){ 822 | parent = inside ? target : target.parentNode 823 | 824 | // convert all methods to a "before" operation 825 | target = operatorIndex == 0 ? target.nextSibling : 826 | operatorIndex == 1 ? target.firstChild : 827 | operatorIndex == 2 ? target : 828 | null 829 | 830 | nodes.forEach(function(node){ 831 | if (copyByClone) node = node.cloneNode(true) 832 | else if (!parent) return $(node).remove() 833 | 834 | traverseNode(parent.insertBefore(node, target), function(el){ 835 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && 836 | (!el.type || el.type === 'text/javascript') && !el.src) 837 | window['eval'].call(window, el.innerHTML) 838 | }) 839 | }) 840 | }) 841 | } 842 | 843 | // after => insertAfter 844 | // prepend => prependTo 845 | // before => insertBefore 846 | // append => appendTo 847 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ 848 | $(html)[operator](this) 849 | return this 850 | } 851 | }) 852 | 853 | zepto.Z.prototype = $.fn 854 | 855 | // Export internal API functions in the `$.zepto` namespace 856 | zepto.uniq = uniq 857 | zepto.deserializeValue = deserializeValue 858 | $.zepto = zepto 859 | 860 | return $ 861 | })() 862 | 863 | window.Zepto = Zepto 864 | window.$ === undefined && (window.$ = Zepto) 865 | 866 | ;(function($){ 867 | var _zid = 1, undefined, 868 | slice = Array.prototype.slice, 869 | isFunction = $.isFunction, 870 | isString = function(obj){ return typeof obj == 'string' }, 871 | handlers = {}, 872 | specialEvents={}, 873 | focusinSupported = 'onfocusin' in window, 874 | focus = { focus: 'focusin', blur: 'focusout' }, 875 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } 876 | 877 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' 878 | 879 | function zid(element) { 880 | return element._zid || (element._zid = _zid++) 881 | } 882 | function findHandlers(element, event, fn, selector) { 883 | event = parse(event) 884 | if (event.ns) var matcher = matcherFor(event.ns) 885 | return (handlers[zid(element)] || []).filter(function(handler) { 886 | return handler 887 | && (!event.e || handler.e == event.e) 888 | && (!event.ns || matcher.test(handler.ns)) 889 | && (!fn || zid(handler.fn) === zid(fn)) 890 | && (!selector || handler.sel == selector) 891 | }) 892 | } 893 | function parse(event) { 894 | var parts = ('' + event).split('.') 895 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} 896 | } 897 | function matcherFor(ns) { 898 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') 899 | } 900 | 901 | function eventCapture(handler, captureSetting) { 902 | return handler.del && 903 | (!focusinSupported && (handler.e in focus)) || 904 | !!captureSetting 905 | } 906 | 907 | function realEvent(type) { 908 | return hover[type] || (focusinSupported && focus[type]) || type 909 | } 910 | 911 | function add(element, events, fn, data, selector, delegator, capture){ 912 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) 913 | events.split(/\s/).forEach(function(event){ 914 | if (event == 'ready') return $(document).ready(fn) 915 | var handler = parse(event) 916 | handler.fn = fn 917 | handler.sel = selector 918 | // emulate mouseenter, mouseleave 919 | if (handler.e in hover) fn = function(e){ 920 | var related = e.relatedTarget 921 | if (!related || (related !== this && !$.contains(this, related))) 922 | return handler.fn.apply(this, arguments) 923 | } 924 | handler.del = delegator 925 | var callback = delegator || fn 926 | handler.proxy = function(e){ 927 | e = compatible(e) 928 | if (e.isImmediatePropagationStopped()) return 929 | e.data = data 930 | var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) 931 | if (result === false) e.preventDefault(), e.stopPropagation() 932 | return result 933 | } 934 | handler.i = set.length 935 | set.push(handler) 936 | if ('addEventListener' in element) 937 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 938 | }) 939 | } 940 | function remove(element, events, fn, selector, capture){ 941 | var id = zid(element) 942 | ;(events || '').split(/\s/).forEach(function(event){ 943 | findHandlers(element, event, fn, selector).forEach(function(handler){ 944 | delete handlers[id][handler.i] 945 | if ('removeEventListener' in element) 946 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 947 | }) 948 | }) 949 | } 950 | 951 | $.event = { add: add, remove: remove } 952 | 953 | $.proxy = function(fn, context) { 954 | if (isFunction(fn)) { 955 | var proxyFn = function(){ return fn.apply(context, arguments) } 956 | proxyFn._zid = zid(fn) 957 | return proxyFn 958 | } else if (isString(context)) { 959 | return $.proxy(fn[context], fn) 960 | } else { 961 | throw new TypeError("expected function") 962 | } 963 | } 964 | 965 | $.fn.bind = function(event, data, callback){ 966 | return this.on(event, data, callback) 967 | } 968 | $.fn.unbind = function(event, callback){ 969 | return this.off(event, callback) 970 | } 971 | $.fn.one = function(event, selector, data, callback){ 972 | return this.on(event, selector, data, callback, 1) 973 | } 974 | 975 | var returnTrue = function(){return true}, 976 | returnFalse = function(){return false}, 977 | ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/, 978 | eventMethods = { 979 | preventDefault: 'isDefaultPrevented', 980 | stopImmediatePropagation: 'isImmediatePropagationStopped', 981 | stopPropagation: 'isPropagationStopped' 982 | } 983 | 984 | function compatible(event, source) { 985 | if (source || !event.isDefaultPrevented) { 986 | source || (source = event) 987 | 988 | $.each(eventMethods, function(name, predicate) { 989 | var sourceMethod = source[name] 990 | event[name] = function(){ 991 | this[predicate] = returnTrue 992 | return sourceMethod && sourceMethod.apply(source, arguments) 993 | } 994 | event[predicate] = returnFalse 995 | }) 996 | 997 | if (source.defaultPrevented !== undefined ? source.defaultPrevented : 998 | 'returnValue' in source ? source.returnValue === false : 999 | source.getPreventDefault && source.getPreventDefault()) 1000 | event.isDefaultPrevented = returnTrue 1001 | } 1002 | return event 1003 | } 1004 | 1005 | function createProxy(event) { 1006 | var key, proxy = { originalEvent: event } 1007 | for (key in event) 1008 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] 1009 | 1010 | return compatible(proxy, event) 1011 | } 1012 | 1013 | $.fn.delegate = function(selector, event, callback){ 1014 | return this.on(event, selector, callback) 1015 | } 1016 | $.fn.undelegate = function(selector, event, callback){ 1017 | return this.off(event, selector, callback) 1018 | } 1019 | 1020 | $.fn.live = function(event, callback){ 1021 | $(document.body).delegate(this.selector, event, callback) 1022 | return this 1023 | } 1024 | $.fn.die = function(event, callback){ 1025 | $(document.body).undelegate(this.selector, event, callback) 1026 | return this 1027 | } 1028 | 1029 | $.fn.on = function(event, selector, data, callback, one){ 1030 | var autoRemove, delegator, $this = this 1031 | if (event && !isString(event)) { 1032 | $.each(event, function(type, fn){ 1033 | $this.on(type, selector, data, fn, one) 1034 | }) 1035 | return $this 1036 | } 1037 | 1038 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1039 | callback = data, data = selector, selector = undefined 1040 | if (isFunction(data) || data === false) 1041 | callback = data, data = undefined 1042 | 1043 | if (callback === false) callback = returnFalse 1044 | 1045 | return $this.each(function(_, element){ 1046 | if (one) autoRemove = function(e){ 1047 | remove(element, e.type, callback) 1048 | return callback.apply(this, arguments) 1049 | } 1050 | 1051 | if (selector) delegator = function(e){ 1052 | var evt, match = $(e.target).closest(selector, element).get(0) 1053 | if (match && match !== element) { 1054 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) 1055 | return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) 1056 | } 1057 | } 1058 | 1059 | add(element, event, callback, data, selector, delegator || autoRemove) 1060 | }) 1061 | } 1062 | $.fn.off = function(event, selector, callback){ 1063 | var $this = this 1064 | if (event && !isString(event)) { 1065 | $.each(event, function(type, fn){ 1066 | $this.off(type, selector, fn) 1067 | }) 1068 | return $this 1069 | } 1070 | 1071 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1072 | callback = selector, selector = undefined 1073 | 1074 | if (callback === false) callback = returnFalse 1075 | 1076 | return $this.each(function(){ 1077 | remove(this, event, callback, selector) 1078 | }) 1079 | } 1080 | 1081 | $.fn.trigger = function(event, args){ 1082 | event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) 1083 | event._args = args 1084 | return this.each(function(){ 1085 | // items in the collection might not be DOM elements 1086 | if('dispatchEvent' in this) this.dispatchEvent(event) 1087 | else $(this).triggerHandler(event, args) 1088 | }) 1089 | } 1090 | 1091 | // triggers event handlers on current element just as if an event occurred, 1092 | // doesn't trigger an actual event, doesn't bubble 1093 | $.fn.triggerHandler = function(event, args){ 1094 | var e, result 1095 | this.each(function(i, element){ 1096 | e = createProxy(isString(event) ? $.Event(event) : event) 1097 | e._args = args 1098 | e.target = element 1099 | $.each(findHandlers(element, event.type || event), function(i, handler){ 1100 | result = handler.proxy(e) 1101 | if (e.isImmediatePropagationStopped()) return false 1102 | }) 1103 | }) 1104 | return result 1105 | } 1106 | 1107 | // shortcut methods for `.bind(event, fn)` for each event type 1108 | ;('focusin focusout load resize scroll unload click dblclick '+ 1109 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ 1110 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { 1111 | $.fn[event] = function(callback) { 1112 | return callback ? 1113 | this.bind(event, callback) : 1114 | this.trigger(event) 1115 | } 1116 | }) 1117 | 1118 | ;['focus', 'blur'].forEach(function(name) { 1119 | $.fn[name] = function(callback) { 1120 | if (callback) this.bind(name, callback) 1121 | else this.each(function(){ 1122 | try { this[name]() } 1123 | catch(e) {} 1124 | }) 1125 | return this 1126 | } 1127 | }) 1128 | 1129 | $.Event = function(type, props) { 1130 | if (!isString(type)) props = type, type = props.type 1131 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true 1132 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) 1133 | event.initEvent(type, bubbles, true) 1134 | return compatible(event) 1135 | } 1136 | 1137 | })(Zepto) 1138 | 1139 | ;(function($){ 1140 | var jsonpID = 0, 1141 | document = window.document, 1142 | key, 1143 | name, 1144 | rscript = /)<[^<]*)*<\/script>/gi, 1145 | scriptTypeRE = /^(?:text|application)\/javascript/i, 1146 | xmlTypeRE = /^(?:text|application)\/xml/i, 1147 | jsonType = 'application/json', 1148 | htmlType = 'text/html', 1149 | blankRE = /^\s*$/ 1150 | 1151 | // trigger a custom event and return false if it was cancelled 1152 | function triggerAndReturn(context, eventName, data) { 1153 | var event = $.Event(eventName) 1154 | $(context).trigger(event, data) 1155 | return !event.isDefaultPrevented() 1156 | } 1157 | 1158 | // trigger an Ajax "global" event 1159 | function triggerGlobal(settings, context, eventName, data) { 1160 | if (settings.global) return triggerAndReturn(context || document, eventName, data) 1161 | } 1162 | 1163 | // Number of active Ajax requests 1164 | $.active = 0 1165 | 1166 | function ajaxStart(settings) { 1167 | if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart') 1168 | } 1169 | function ajaxStop(settings) { 1170 | if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop') 1171 | } 1172 | 1173 | // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable 1174 | function ajaxBeforeSend(xhr, settings) { 1175 | var context = settings.context 1176 | if (settings.beforeSend.call(context, xhr, settings) === false || 1177 | triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) 1178 | return false 1179 | 1180 | triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]) 1181 | } 1182 | function ajaxSuccess(data, xhr, settings, deferred) { 1183 | var context = settings.context, status = 'success' 1184 | settings.success.call(context, data, status, xhr) 1185 | if (deferred) deferred.resolveWith(context, [data, status, xhr]) 1186 | triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]) 1187 | ajaxComplete(status, xhr, settings) 1188 | } 1189 | // type: "timeout", "error", "abort", "parsererror" 1190 | function ajaxError(error, type, xhr, settings, deferred) { 1191 | var context = settings.context 1192 | settings.error.call(context, xhr, type, error) 1193 | if (deferred) deferred.rejectWith(context, [xhr, type, error]) 1194 | triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type]) 1195 | ajaxComplete(type, xhr, settings) 1196 | } 1197 | // status: "success", "notmodified", "error", "timeout", "abort", "parsererror" 1198 | function ajaxComplete(status, xhr, settings) { 1199 | var context = settings.context 1200 | settings.complete.call(context, xhr, status) 1201 | triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]) 1202 | ajaxStop(settings) 1203 | } 1204 | 1205 | // Empty function, used as default callback 1206 | function empty() {} 1207 | 1208 | $.ajaxJSONP = function(options, deferred){ 1209 | if (!('type' in options)) return $.ajax(options) 1210 | 1211 | var _callbackName = options.jsonpCallback, 1212 | callbackName = ($.isFunction(_callbackName) ? 1213 | _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)), 1214 | script = document.createElement('script'), 1215 | originalCallback = window[callbackName], 1216 | responseData, 1217 | abort = function(errorType) { 1218 | $(script).triggerHandler('error', errorType || 'abort') 1219 | }, 1220 | xhr = { abort: abort }, abortTimeout 1221 | 1222 | if (deferred) deferred.promise(xhr) 1223 | 1224 | $(script).on('load error', function(e, errorType){ 1225 | clearTimeout(abortTimeout) 1226 | $(script).off().remove() 1227 | 1228 | if (e.type == 'error' || !responseData) { 1229 | ajaxError(null, errorType || 'error', xhr, options, deferred) 1230 | } else { 1231 | ajaxSuccess(responseData[0], xhr, options, deferred) 1232 | } 1233 | 1234 | window[callbackName] = originalCallback 1235 | if (responseData && $.isFunction(originalCallback)) 1236 | originalCallback(responseData[0]) 1237 | 1238 | originalCallback = responseData = undefined 1239 | }) 1240 | 1241 | if (ajaxBeforeSend(xhr, options) === false) { 1242 | abort('abort') 1243 | return xhr 1244 | } 1245 | 1246 | window[callbackName] = function(){ 1247 | responseData = arguments 1248 | } 1249 | 1250 | script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName) 1251 | document.head.appendChild(script) 1252 | 1253 | if (options.timeout > 0) abortTimeout = setTimeout(function(){ 1254 | abort('timeout') 1255 | }, options.timeout) 1256 | 1257 | return xhr 1258 | } 1259 | 1260 | $.ajaxSettings = { 1261 | // Default type of request 1262 | type: 'GET', 1263 | // Callback that is executed before request 1264 | beforeSend: empty, 1265 | // Callback that is executed if the request succeeds 1266 | success: empty, 1267 | // Callback that is executed the the server drops error 1268 | error: empty, 1269 | // Callback that is executed on request complete (both: error and success) 1270 | complete: empty, 1271 | // The context for the callbacks 1272 | context: null, 1273 | // Whether to trigger "global" Ajax events 1274 | global: true, 1275 | // Transport 1276 | xhr: function () { 1277 | return new window.XMLHttpRequest() 1278 | }, 1279 | // MIME types mapping 1280 | // IIS returns Javascript as "application/x-javascript" 1281 | accepts: { 1282 | script: 'text/javascript, application/javascript, application/x-javascript', 1283 | json: jsonType, 1284 | xml: 'application/xml, text/xml', 1285 | html: htmlType, 1286 | text: 'text/plain' 1287 | }, 1288 | // Whether the request is to another domain 1289 | crossDomain: false, 1290 | // Default timeout 1291 | timeout: 0, 1292 | // Whether data should be serialized to string 1293 | processData: true, 1294 | // Whether the browser should be allowed to cache GET responses 1295 | cache: true 1296 | } 1297 | 1298 | function mimeToDataType(mime) { 1299 | if (mime) mime = mime.split(';', 2)[0] 1300 | return mime && ( mime == htmlType ? 'html' : 1301 | mime == jsonType ? 'json' : 1302 | scriptTypeRE.test(mime) ? 'script' : 1303 | xmlTypeRE.test(mime) && 'xml' ) || 'text' 1304 | } 1305 | 1306 | function appendQuery(url, query) { 1307 | if (query == '') return url 1308 | return (url + '&' + query).replace(/[&?]{1,2}/, '?') 1309 | } 1310 | 1311 | // serialize payload and append it to the URL for GET requests 1312 | function serializeData(options) { 1313 | if (options.processData && options.data && $.type(options.data) != "string") 1314 | options.data = $.param(options.data, options.traditional) 1315 | if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) 1316 | options.url = appendQuery(options.url, options.data), options.data = undefined 1317 | } 1318 | 1319 | $.ajax = function(options){ 1320 | var settings = $.extend({}, options || {}), 1321 | deferred = $.Deferred && $.Deferred() 1322 | for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] 1323 | 1324 | ajaxStart(settings) 1325 | 1326 | if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && 1327 | RegExp.$2 != window.location.host 1328 | 1329 | if (!settings.url) settings.url = window.location.toString() 1330 | serializeData(settings) 1331 | if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now()) 1332 | 1333 | var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url) 1334 | if (dataType == 'jsonp' || hasPlaceholder) { 1335 | if (!hasPlaceholder) 1336 | settings.url = appendQuery(settings.url, 1337 | settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?') 1338 | return $.ajaxJSONP(settings, deferred) 1339 | } 1340 | 1341 | var mime = settings.accepts[dataType], 1342 | headers = { }, 1343 | setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] }, 1344 | protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol, 1345 | xhr = settings.xhr(), 1346 | nativeSetHeader = xhr.setRequestHeader, 1347 | abortTimeout 1348 | 1349 | if (deferred) deferred.promise(xhr) 1350 | 1351 | if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest') 1352 | setHeader('Accept', mime || '*/*') 1353 | if (mime = settings.mimeType || mime) { 1354 | if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0] 1355 | xhr.overrideMimeType && xhr.overrideMimeType(mime) 1356 | } 1357 | if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET')) 1358 | setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded') 1359 | 1360 | if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name]) 1361 | xhr.setRequestHeader = setHeader 1362 | 1363 | xhr.onreadystatechange = function(){ 1364 | if (xhr.readyState == 4) { 1365 | xhr.onreadystatechange = empty 1366 | clearTimeout(abortTimeout) 1367 | var result, error = false 1368 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { 1369 | dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type')) 1370 | result = xhr.responseText 1371 | 1372 | try { 1373 | // http://perfectionkills.com/global-eval-what-are-the-options/ 1374 | if (dataType == 'script') (1,eval)(result) 1375 | else if (dataType == 'xml') result = xhr.responseXML 1376 | else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result) 1377 | } catch (e) { error = e } 1378 | 1379 | if (error) ajaxError(error, 'parsererror', xhr, settings, deferred) 1380 | else ajaxSuccess(result, xhr, settings, deferred) 1381 | } else { 1382 | ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred) 1383 | } 1384 | } 1385 | } 1386 | 1387 | if (ajaxBeforeSend(xhr, settings) === false) { 1388 | xhr.abort() 1389 | ajaxError(null, 'abort', xhr, settings, deferred) 1390 | return xhr 1391 | } 1392 | 1393 | if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name] 1394 | 1395 | var async = 'async' in settings ? settings.async : true 1396 | xhr.open(settings.type, settings.url, async, settings.username, settings.password) 1397 | 1398 | for (name in headers) nativeSetHeader.apply(xhr, headers[name]) 1399 | 1400 | if (settings.timeout > 0) abortTimeout = setTimeout(function(){ 1401 | xhr.onreadystatechange = empty 1402 | xhr.abort() 1403 | ajaxError(null, 'timeout', xhr, settings, deferred) 1404 | }, settings.timeout) 1405 | 1406 | // avoid sending empty string (#319) 1407 | xhr.send(settings.data ? settings.data : null) 1408 | return xhr 1409 | } 1410 | 1411 | // handle optional data/success arguments 1412 | function parseArguments(url, data, success, dataType) { 1413 | if ($.isFunction(data)) dataType = success, success = data, data = undefined 1414 | if (!$.isFunction(success)) dataType = success, success = undefined 1415 | return { 1416 | url: url 1417 | , data: data 1418 | , success: success 1419 | , dataType: dataType 1420 | } 1421 | } 1422 | 1423 | $.get = function(/* url, data, success, dataType */){ 1424 | return $.ajax(parseArguments.apply(null, arguments)) 1425 | } 1426 | 1427 | $.post = function(/* url, data, success, dataType */){ 1428 | var options = parseArguments.apply(null, arguments) 1429 | options.type = 'POST' 1430 | return $.ajax(options) 1431 | } 1432 | 1433 | $.getJSON = function(/* url, data, success */){ 1434 | var options = parseArguments.apply(null, arguments) 1435 | options.dataType = 'json' 1436 | return $.ajax(options) 1437 | } 1438 | 1439 | $.fn.load = function(url, data, success){ 1440 | if (!this.length) return this 1441 | var self = this, parts = url.split(/\s/), selector, 1442 | options = parseArguments(url, data, success), 1443 | callback = options.success 1444 | if (parts.length > 1) options.url = parts[0], selector = parts[1] 1445 | options.success = function(response){ 1446 | self.html(selector ? 1447 | $('
').html(response.replace(rscript, "")).find(selector) 1448 | : response) 1449 | callback && callback.apply(self, arguments) 1450 | } 1451 | $.ajax(options) 1452 | return this 1453 | } 1454 | 1455 | var escape = encodeURIComponent 1456 | 1457 | function serialize(params, obj, traditional, scope){ 1458 | var type, array = $.isArray(obj), hash = $.isPlainObject(obj) 1459 | $.each(obj, function(key, value) { 1460 | type = $.type(value) 1461 | if (scope) key = traditional ? scope : 1462 | scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']' 1463 | // handle data in serializeArray() format 1464 | if (!scope && array) params.add(value.name, value.value) 1465 | // recurse into nested objects 1466 | else if (type == "array" || (!traditional && type == "object")) 1467 | serialize(params, value, traditional, key) 1468 | else params.add(key, value) 1469 | }) 1470 | } 1471 | 1472 | $.param = function(obj, traditional){ 1473 | var params = [] 1474 | params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) } 1475 | serialize(params, obj, traditional) 1476 | return params.join('&').replace(/%20/g, '+') 1477 | } 1478 | })(Zepto) 1479 | 1480 | ;(function($){ 1481 | $.fn.serializeArray = function() { 1482 | var result = [], el 1483 | $([].slice.call(this.get(0).elements)).each(function(){ 1484 | el = $(this) 1485 | var type = el.attr('type') 1486 | if (this.nodeName.toLowerCase() != 'fieldset' && 1487 | !this.disabled && type != 'submit' && type != 'reset' && type != 'button' && 1488 | ((type != 'radio' && type != 'checkbox') || this.checked)) 1489 | result.push({ 1490 | name: el.attr('name'), 1491 | value: el.val() 1492 | }) 1493 | }) 1494 | return result 1495 | } 1496 | 1497 | $.fn.serialize = function(){ 1498 | var result = [] 1499 | this.serializeArray().forEach(function(elm){ 1500 | result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value)) 1501 | }) 1502 | return result.join('&') 1503 | } 1504 | 1505 | $.fn.submit = function(callback) { 1506 | if (callback) this.bind('submit', callback) 1507 | else if (this.length) { 1508 | var event = $.Event('submit') 1509 | this.eq(0).trigger(event) 1510 | if (!event.isDefaultPrevented()) this.get(0).submit() 1511 | } 1512 | return this 1513 | } 1514 | 1515 | })(Zepto) 1516 | 1517 | ;(function($){ 1518 | // __proto__ doesn't exist on IE<11, so redefine 1519 | // the Z function to use object extension instead 1520 | if (!('__proto__' in {})) { 1521 | $.extend($.zepto, { 1522 | Z: function(dom, selector){ 1523 | dom = dom || [] 1524 | $.extend(dom, $.fn) 1525 | dom.selector = selector || '' 1526 | dom.__Z = true 1527 | return dom 1528 | }, 1529 | // this is a kludge but works 1530 | isZ: function(object){ 1531 | return $.type(object) === 'array' && '__Z' in object 1532 | } 1533 | }) 1534 | } 1535 | 1536 | // getComputedStyle shouldn't freak out when called 1537 | // without a valid element as argument 1538 | try { 1539 | getComputedStyle(undefined) 1540 | } catch(e) { 1541 | var nativeGetComputedStyle = getComputedStyle; 1542 | window.getComputedStyle = function(element){ 1543 | try { 1544 | return nativeGetComputedStyle(element) 1545 | } catch(e) { 1546 | return null 1547 | } 1548 | } 1549 | } 1550 | })(Zepto) 1551 | -------------------------------------------------------------------------------- /demo/zepto.onepagescroll.js: -------------------------------------------------------------------------------- 1 | /* =========================================================== 2 | * zepto.onepagescroll.js v1.2.2 3 | * =========================================================== 4 | * Copyright 2014 Pete Rojwongsuriya. 5 | * http://www.thepetedesign.com 6 | * 7 | * Create an Apple-like website that let user scroll 8 | * one page at a time 9 | * 10 | * Credit: Eike Send for the awesome swipe event 11 | * https://github.com/peachananr/zepto-onepage-scroll 12 | * 13 | * 14 | * Zepto Modules Required: 15 | * - touch.js 16 | * - fx.js 17 | * 18 | * 19 | * License: GPL v3 20 | * 21 | * ========================================================== */ 22 | 23 | ;(function($){ 24 | $.extend($.fn, { 25 | onePageScroll: function(options){ 26 | 27 | var defaults = { 28 | sectionContainer: "section", 29 | easing: "ease", 30 | animationTime: 1000, 31 | pagination: true, 32 | updateURL: false, 33 | keyboard: true, 34 | beforeMove: null, 35 | afterMove: null, 36 | loop: false, 37 | responsiveFallback: false 38 | }; 39 | 40 | var settings = $.extend({}, defaults, options), 41 | el = $(this), 42 | sections = $(settings.sectionContainer), 43 | total = sections.length, 44 | status = "off", 45 | topPos = 0, 46 | lastAnimation = 0, 47 | lastAnimation = 0, 48 | quietPeriod = 300, 49 | paginationList = "", 50 | body = $("body"); 51 | 52 | 53 | /*------------------------------------------------*/ 54 | /* Credit: Eike Send for the awesome swipe event */ 55 | /*------------------------------------------------*/ 56 | 57 | $.fn.swipeEvents = function() { 58 | return this.each(function() { 59 | 60 | var startX, 61 | startY, 62 | $this = $(this); 63 | 64 | $this.on('touchstart', touchstart); 65 | 66 | function touchstart(event) { 67 | var touches = event.touches; 68 | if (touches && touches.length) { 69 | startX = touches[0].pageX; 70 | startY = touches[0].pageY; 71 | $this.on('touchmove', touchmove); 72 | } 73 | } 74 | 75 | function touchmove(event) { 76 | var touches = event.touches; 77 | if (touches && touches.length) { 78 | event.preventDefault(); 79 | var deltaX = startX - touches[0].pageX; 80 | var deltaY = startY - touches[0].pageY; 81 | 82 | if (deltaX >= 50) { 83 | $this.trigger("swipeLeft"); 84 | } 85 | if (deltaX <= -50) { 86 | $this.trigger("swipeRight"); 87 | } 88 | if (deltaY >= 50) { 89 | $this.trigger("swipeUp"); 90 | } 91 | if (deltaY <= -50) { 92 | $this.trigger("swipeDown"); 93 | } 94 | if (Math.abs(deltaX) >= 50 || Math.abs(deltaY) >= 50) { 95 | $this.off('touchmove', touchmove); 96 | } 97 | } 98 | } 99 | 100 | }); 101 | }; 102 | 103 | /*---------------------------------*/ 104 | /* Function to transform the page */ 105 | /*---------------------------------*/ 106 | 107 | $.fn.transformPage = function(settings, pos, index, next_el) { 108 | var el2 = $(this); 109 | 110 | if (typeof settings.beforeMove == 'function') settings.beforeMove(index, next_el); 111 | 112 | el2.animate({ 113 | translate3d: "0, " + pos + "%, 0" 114 | }, settings.animationTime, settings.easing, function() { 115 | if (typeof settings.afterMove == 'function') settings.afterMove(index); 116 | }); 117 | } 118 | 119 | /*---------------------------------*/ 120 | /* Function to move down section */ 121 | /*---------------------------------*/ 122 | 123 | $.fn.moveDown = function() { 124 | var timeNow = new Date().getTime(); 125 | 126 | // Cancel scroll if currently animating or within quiet period 127 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 128 | event.preventDefault(); 129 | return; 130 | } 131 | 132 | var index = $(settings.sectionContainer +".active").data("index"), 133 | current = $(settings.sectionContainer + "[data-index='" + index + "']"), 134 | next = $(settings.sectionContainer + "[data-index='" + (parseInt(index) + 1) + "']"), 135 | el3 = $(this); 136 | 137 | 138 | if(next.length < 1) { 139 | if (settings.loop == true) { 140 | pos = 0; 141 | next = $(settings.sectionContainer + "[data-index='1']"); 142 | } else { 143 | return 144 | } 145 | 146 | }else { 147 | pos = (index * 100) * -1; 148 | } 149 | var next_index = next.data("index"); 150 | current.removeClass("active"); 151 | next.addClass("active"); 152 | 153 | if(settings.pagination == true) { 154 | $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 155 | $(".onepage-pagination li a" + "[data-index='" + next_index + "']").addClass("active"); 156 | } 157 | 158 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 159 | body.addClass("viewing-page-"+ next_index); 160 | 161 | if (history.replaceState && settings.updateURL == true) { 162 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(index) + 1); 163 | history.pushState( {}, document.title, href ); 164 | } 165 | el3.transformPage(settings, pos, next_index, next); 166 | lastAnimation = timeNow; 167 | } 168 | 169 | /*---------------------------------*/ 170 | /* Function to move up section */ 171 | /*---------------------------------*/ 172 | 173 | $.fn.moveUp = function() { 174 | var timeNow = new Date().getTime(); 175 | 176 | // Cancel scroll if currently animating or within quiet period 177 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 178 | event.preventDefault(); 179 | return; 180 | } 181 | 182 | var index = $(settings.sectionContainer +".active").data("index"), 183 | current = $(settings.sectionContainer + "[data-index='" + index + "']"), 184 | next = $(settings.sectionContainer + "[data-index='" + (parseInt(index) - 1) + "']"), 185 | el4 = $(this); 186 | 187 | if(next.length < 1) { 188 | if (settings.loop == true) { 189 | pos = ((total - 1) * 100) * -1; 190 | next = $(settings.sectionContainer + "[data-index='" + total + "']"); 191 | } else { 192 | return 193 | } 194 | }else { 195 | pos = ((next.data("index") - 1) * 100) * -1; 196 | } 197 | var next_index = next.data("index"); 198 | current.removeClass("active") 199 | next.addClass("active") 200 | 201 | if(settings.pagination == true) { 202 | $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 203 | $(".onepage-pagination li a" + "[data-index='" + next_index + "']").addClass("active"); 204 | } 205 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 206 | body.addClass("viewing-page-"+ next_index); 207 | 208 | if (history.replaceState && settings.updateURL == true) { 209 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(index) - 1); 210 | history.pushState( {}, document.title, href ); 211 | } 212 | el4.transformPage(settings, pos, next_index, next); 213 | lastAnimation = timeNow; 214 | } 215 | 216 | /*-------------------------------------------*/ 217 | /* Function to move to specified section */ 218 | /*-------------------------------------------*/ 219 | 220 | $.fn.moveTo = function(page_index) { 221 | var timeNow = new Date().getTime(); 222 | 223 | // Cancel scroll if currently animating or within quiet period 224 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 225 | event.preventDefault(); 226 | return; 227 | } 228 | var current = $(settings.sectionContainer + ".active"), 229 | next = $(settings.sectionContainer + "[data-index='" + (page_index) + "']"), 230 | el5 = $(this); 231 | 232 | if(next.length > 0) { 233 | var next_index = next.data("index"); 234 | current.removeClass("active"); 235 | next.addClass("active"); 236 | $(".onepage-pagination li a" + ".active").removeClass("active"); 237 | $(".onepage-pagination li a" + "[data-index='" + (page_index) + "']").addClass("active"); 238 | 239 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 240 | body.addClass("viewing-page-"+ next_index); 241 | 242 | pos = ((page_index - 1) * 100) * -1; 243 | 244 | if (history.replaceState && settings.updateURL == true) { 245 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(page_index) - 1); 246 | history.pushState( {}, document.title, href ); 247 | } 248 | el5.transformPage(settings, pos, page_index, next); 249 | lastAnimation = timeNow; 250 | } 251 | } 252 | 253 | /*-------------------------------------------*/ 254 | /* Responsive Fallback trigger */ 255 | /*-------------------------------------------*/ 256 | 257 | var responsive = function() { 258 | 259 | if ($(document).width() < settings.responsiveFallback) { 260 | 261 | body.addClass("disabled-onepage-scroll"); 262 | $(document).off('mousewheel DOMMouseScroll', mouseWheelHandler); 263 | $(document).off("swipeDown swipeUp"); 264 | 265 | } else { 266 | 267 | if (body.hasClass("disabled-onepage-scroll")) { 268 | bodyremoveClass("disabled-onepage-scroll"); 269 | $("html, body, .wrapper").animate({ scrollTop: 0 }, "fast"); 270 | } 271 | 272 | $(document).swipeEvents().on("swipeDown", function(event){ 273 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 274 | el.moveUp(); 275 | }).on("swipeUp", function(event){ 276 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 277 | el.moveDown(); 278 | }); 279 | 280 | 281 | $(document).on('mousewheel DOMMouseScroll', mouseWheelHandler); 282 | 283 | } 284 | } 285 | 286 | /*-------------------------------------------*/ 287 | /* Initialize scroll detection */ 288 | /*-------------------------------------------*/ 289 | 290 | function init_scroll(event, delta) { 291 | var deltaOfInterest = delta; 292 | 293 | if (deltaOfInterest < 0) { 294 | el.moveDown() 295 | } else { 296 | el.moveUp() 297 | } 298 | } 299 | 300 | 301 | /*-------------------------------------------*/ 302 | /* Prepare Everything */ 303 | /*-------------------------------------------*/ 304 | 305 | el.addClass("onepage-wrapper") 306 | el.css("position","relative"); 307 | $.each(sections, function(i, item){ 308 | $(this).addClass("ops-section").data("index", i + 1); 309 | topPos = topPos + 100; 310 | 311 | if(settings.pagination == true) { 312 | paginationList += "
  • "; 313 | } 314 | }); 315 | 316 | $(document).swipeEvents().on("swipeDown", function(event){ 317 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 318 | el.moveUp(); 319 | }).on("swipeUp", function(event){ 320 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 321 | el.moveDown(); 322 | }); 323 | 324 | // Create Pagination and Display Them 325 | if(settings.pagination == true) { 326 | $("
      " + paginationList + "
    ").prependTo("body"); 327 | posTop = (el.find(".onepage-pagination").height() / 2) * -1; 328 | el.find(".onepage-pagination").css("margin-top", posTop); 329 | } 330 | 331 | if(window.location.hash != "" && window.location.hash != "#1") { 332 | var init_index = window.location.hash.replace("#", ""), 333 | next = $(settings.sectionContainer + "[data-index='" + (init_index) + "']"), 334 | next_index = next.data("index"); 335 | 336 | $(settings.sectionContainer + "[data-index='" + init_index + "']").addClass("active") 337 | body.addClass("viewing-page-"+ init_index) 338 | if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + init_index + "']").addClass("active"); 339 | 340 | if(next) { 341 | next.addClass("active") 342 | if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + init_index + "']").addClass("active"); 343 | 344 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 345 | 346 | body.addClass("viewing-page-" + next_index) 347 | if (history.replaceState && settings.updateURL == true) { 348 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (init_index); 349 | history.pushState( {}, document.title, href ); 350 | } 351 | } 352 | var pos = ((init_index - 1) * 100) * -1; 353 | el.transformPage(settings, pos, init_index); 354 | 355 | }else{ 356 | $(settings.sectionContainer + "[data-index='1']").addClass("active"); 357 | body.addClass("viewing-page-1"); 358 | if(settings.pagination == true) $(".onepage-pagination li a[data-index='1']").addClass("active"); 359 | } 360 | 361 | function paginationHandler() { 362 | var page_index = this.dataset.index; 363 | el.moveTo(page_index); 364 | } 365 | 366 | 367 | if(settings.pagination == true) { 368 | $(".onepage-pagination li a").click(function (){ 369 | var page_index = $(this).data("index"); 370 | el.moveTo(page_index); 371 | }); 372 | } 373 | 374 | function mouseWheelHandler(event) { 375 | event.preventDefault(); 376 | var delta = event.wheelDelta || -event.detail; 377 | if(!body.hasClass("disabled-onepage-scroll")) init_scroll(event, delta); 378 | } 379 | 380 | $(document).on('mousewheel DOMMouseScroll', mouseWheelHandler); 381 | 382 | if(settings.responsiveFallback != false) { 383 | window.onresize = function(){ 384 | responsive(); 385 | } 386 | 387 | responsive(); 388 | } 389 | 390 | function keydownHandler(e) { 391 | var tag = e.target.tagName.toLowerCase(); 392 | 393 | if (!body.hasClass("disabled-onepage-scroll")) { 394 | switch(e.which) { 395 | case 38: 396 | if (tag != 'input' && tag != 'textarea') el.moveUp() 397 | break; 398 | case 40: 399 | if (tag != 'input' && tag != 'textarea') el.moveDown() 400 | break; 401 | default: return; 402 | } 403 | } 404 | return false; 405 | } 406 | 407 | if(settings.keyboard == true) { 408 | document.onkeydown = keydownHandler; 409 | } 410 | return false; 411 | } 412 | 413 | 414 | }) 415 | })(Zepto) -------------------------------------------------------------------------------- /demo/zepto_onepage_scroll_demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Zepto One Page Scroll by Pete R. | The Pete Design 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 685 | 686 | 687 | 688 | 689 |
    690 | 691 |
    692 | 693 |
    694 | 695 |
    696 | 697 |
    698 |
    699 |

    Zepto One Page Scroll v1.2

    700 |

    Create an Apple-like one page scroller website (iPhone 5S website) with One Page Scroll plugin. (Zepto Library & Modules Required)

    701 |

    Created by Pete R., Founder of Travelistly & BucketListly

    702 | 703 | 704 |
    705 | 706 | Download on Github 707 |

    Looking for a jQuery | Pure JS version?

    708 |
    709 |
    710 | phones 711 |
    712 | 713 |
    714 |
    715 |

    Ready-to-use plugin

    716 |

    All you need is an HTML markup, call the script and BAM!

    717 | 718 | <div class="main">
    719 | <section>...</section>
    720 | <section>...</section>
    721 | ...
    722 | </div> 723 |
    724 | 725 | $(".main").onePageScroll(); 726 | 727 |
    728 |
    729 | 730 |
    731 |
    732 |

    Pretty Neat Eh?

    733 |

    You can customize the animation timing, the selector or even the animation easing using CSS3. I can't wait to see what you guys will come up with. Don't forget to grab them for free on Github'

    734 |
    735 | Download on Github 736 |
    737 |
    738 |
    739 | 740 |
    741 | Back to The Pete Design 742 | Fork me on GitHub 743 |
    744 | 751 | 752 | 753 | 760 | 761 | 762 | 763 | -------------------------------------------------------------------------------- /onepage-scroll.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin: 0; 3 | overflow: hidden; 4 | -webkit-transition: opacity 400ms; 5 | -moz-transition: opacity 400ms; 6 | transition: opacity 400ms; 7 | } 8 | 9 | body, .onepage-wrapper, html { 10 | display: block; 11 | position: static; 12 | padding: 0; 13 | width: 100%; 14 | height: 100%; 15 | } 16 | 17 | .onepage-wrapper { 18 | width: 100%; 19 | height: 100%; 20 | display: block; 21 | position: relative; 22 | padding: 0; 23 | -webkit-transform-style: preserve-3d; 24 | } 25 | 26 | .onepage-wrapper .ops-section { 27 | width: 100%; 28 | height: 100%; 29 | position: relative; 30 | } 31 | 32 | .onepage-pagination { 33 | position: absolute; 34 | right: 10px; 35 | top: 50%; 36 | z-index: 5; 37 | list-style: none; 38 | margin: 0; 39 | padding: 0; 40 | } 41 | .onepage-pagination li { 42 | padding: 0; 43 | text-align: center; 44 | } 45 | .onepage-pagination li a{ 46 | padding: 10px; 47 | width: 4px; 48 | height: 4px; 49 | display: block; 50 | 51 | } 52 | .onepage-pagination li a:before{ 53 | content: ''; 54 | position: absolute; 55 | width: 4px; 56 | height: 4px; 57 | background: rgba(0,0,0,0.85); 58 | border-radius: 10px; 59 | -webkit-border-radius: 10px; 60 | -moz-border-radius: 10px; 61 | } 62 | 63 | .onepage-pagination li a.active:before{ 64 | width: 10px; 65 | height: 10px; 66 | background: none; 67 | border: 1px solid black; 68 | margin-top: -4px; 69 | left: 8px; 70 | } 71 | 72 | .disabled-onepage-scroll, .disabled-onepage-scroll .wrapper { 73 | overflow: auto; 74 | } 75 | 76 | .disabled-onepage-scroll .onepage-wrapper .ops-section { 77 | position: relative !important; 78 | top: auto !important; 79 | } 80 | .disabled-onepage-scroll .onepage-wrapper { 81 | -webkit-transform: none !important; 82 | -moz-transform: none !important; 83 | transform: none !important; 84 | -ms-transform: none !important; 85 | min-height: 100%; 86 | } 87 | 88 | 89 | .disabled-onepage-scroll .onepage-pagination { 90 | display: none; 91 | } 92 | 93 | body.disabled-onepage-scroll, .disabled-onepage-scroll .onepage-wrapper, html { 94 | position: inherit; 95 | } -------------------------------------------------------------------------------- /zepto.onepagescroll.js: -------------------------------------------------------------------------------- 1 | /* =========================================================== 2 | * zepto.onepagescroll.js v1.2.2 3 | * =========================================================== 4 | * Copyright 2014 Pete Rojwongsuriya. 5 | * http://www.thepetedesign.com 6 | * 7 | * Create an Apple-like website that let user scroll 8 | * one page at a time 9 | * 10 | * Credit: Eike Send for the awesome swipe event 11 | * https://github.com/peachananr/zepto-onepage-scroll 12 | * 13 | * 14 | * Zepto Modules Required: 15 | * - touch.js 16 | * - fx.js 17 | * 18 | * 19 | * License: GPL v3 20 | * 21 | * ========================================================== */ 22 | 23 | ;(function($){ 24 | $.extend($.fn, { 25 | onePageScroll: function(options){ 26 | 27 | var defaults = { 28 | sectionContainer: "section", 29 | easing: "ease", 30 | animationTime: 1000, 31 | pagination: true, 32 | updateURL: false, 33 | keyboard: true, 34 | beforeMove: null, 35 | afterMove: null, 36 | loop: false, 37 | responsiveFallback: false 38 | }; 39 | 40 | var settings = $.extend({}, defaults, options), 41 | el = $(this), 42 | sections = $(settings.sectionContainer), 43 | total = sections.length, 44 | status = "off", 45 | topPos = 0, 46 | lastAnimation = 0, 47 | lastAnimation = 0, 48 | quietPeriod = 300, 49 | paginationList = "", 50 | body = $("body"); 51 | 52 | 53 | /*------------------------------------------------*/ 54 | /* Credit: Eike Send for the awesome swipe event */ 55 | /*------------------------------------------------*/ 56 | 57 | $.fn.swipeEvents = function() { 58 | return this.each(function() { 59 | 60 | var startX, 61 | startY, 62 | $this = $(this); 63 | 64 | $this.on('touchstart', touchstart); 65 | 66 | function touchstart(event) { 67 | var touches = event.touches; 68 | if (touches && touches.length) { 69 | startX = touches[0].pageX; 70 | startY = touches[0].pageY; 71 | $this.on('touchmove', touchmove); 72 | } 73 | } 74 | 75 | function touchmove(event) { 76 | var touches = event.touches; 77 | if (touches && touches.length) { 78 | event.preventDefault(); 79 | var deltaX = startX - touches[0].pageX; 80 | var deltaY = startY - touches[0].pageY; 81 | 82 | if (deltaX >= 50) { 83 | $this.trigger("swipeLeft"); 84 | } 85 | if (deltaX <= -50) { 86 | $this.trigger("swipeRight"); 87 | } 88 | if (deltaY >= 50) { 89 | $this.trigger("swipeUp"); 90 | } 91 | if (deltaY <= -50) { 92 | $this.trigger("swipeDown"); 93 | } 94 | if (Math.abs(deltaX) >= 50 || Math.abs(deltaY) >= 50) { 95 | $this.off('touchmove', touchmove); 96 | } 97 | } 98 | } 99 | 100 | }); 101 | }; 102 | 103 | /*---------------------------------*/ 104 | /* Function to transform the page */ 105 | /*---------------------------------*/ 106 | 107 | $.fn.transformPage = function(settings, pos, index, next_el) { 108 | var el2 = $(this); 109 | 110 | if (typeof settings.beforeMove == 'function') settings.beforeMove(index, next_el); 111 | 112 | el2.animate({ 113 | translate3d: "0, " + pos + "%, 0" 114 | }, settings.animationTime, settings.easing, function() { 115 | if (typeof settings.afterMove == 'function') settings.afterMove(index); 116 | }); 117 | } 118 | 119 | /*---------------------------------*/ 120 | /* Function to move down section */ 121 | /*---------------------------------*/ 122 | 123 | $.fn.moveDown = function() { 124 | var timeNow = new Date().getTime(); 125 | 126 | // Cancel scroll if currently animating or within quiet period 127 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 128 | event.preventDefault(); 129 | return; 130 | } 131 | 132 | var index = $(settings.sectionContainer +".active").data("index"), 133 | current = $(settings.sectionContainer + "[data-index='" + index + "']"), 134 | next = $(settings.sectionContainer + "[data-index='" + (parseInt(index) + 1) + "']"), 135 | el3 = $(this); 136 | 137 | 138 | if(next.length < 1) { 139 | if (settings.loop == true) { 140 | pos = 0; 141 | next = $(settings.sectionContainer + "[data-index='1']"); 142 | } else { 143 | return 144 | } 145 | 146 | }else { 147 | pos = (index * 100) * -1; 148 | } 149 | var next_index = next.data("index"); 150 | current.removeClass("active"); 151 | next.addClass("active"); 152 | 153 | if(settings.pagination == true) { 154 | $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 155 | $(".onepage-pagination li a" + "[data-index='" + next_index + "']").addClass("active"); 156 | } 157 | 158 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 159 | body.addClass("viewing-page-"+ next_index); 160 | 161 | if (history.replaceState && settings.updateURL == true) { 162 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(index) + 1); 163 | history.pushState( {}, document.title, href ); 164 | } 165 | el3.transformPage(settings, pos, next_index, next); 166 | lastAnimation = timeNow; 167 | } 168 | 169 | /*---------------------------------*/ 170 | /* Function to move up section */ 171 | /*---------------------------------*/ 172 | 173 | $.fn.moveUp = function() { 174 | var timeNow = new Date().getTime(); 175 | 176 | // Cancel scroll if currently animating or within quiet period 177 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 178 | event.preventDefault(); 179 | return; 180 | } 181 | 182 | var index = $(settings.sectionContainer +".active").data("index"), 183 | current = $(settings.sectionContainer + "[data-index='" + index + "']"), 184 | next = $(settings.sectionContainer + "[data-index='" + (parseInt(index) - 1) + "']"), 185 | el4 = $(this); 186 | 187 | if(next.length < 1) { 188 | if (settings.loop == true) { 189 | pos = ((total - 1) * 100) * -1; 190 | next = $(settings.sectionContainer + "[data-index='" + total + "']"); 191 | } else { 192 | return 193 | } 194 | }else { 195 | pos = ((next.data("index") - 1) * 100) * -1; 196 | } 197 | var next_index = next.data("index"); 198 | current.removeClass("active") 199 | next.addClass("active") 200 | 201 | if(settings.pagination == true) { 202 | $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 203 | $(".onepage-pagination li a" + "[data-index='" + next_index + "']").addClass("active"); 204 | } 205 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 206 | body.addClass("viewing-page-"+ next_index); 207 | 208 | if (history.replaceState && settings.updateURL == true) { 209 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(index) - 1); 210 | history.pushState( {}, document.title, href ); 211 | } 212 | el4.transformPage(settings, pos, next_index, next); 213 | lastAnimation = timeNow; 214 | } 215 | 216 | /*-------------------------------------------*/ 217 | /* Function to move to specified section */ 218 | /*-------------------------------------------*/ 219 | 220 | $.fn.moveTo = function(page_index) { 221 | var timeNow = new Date().getTime(); 222 | 223 | // Cancel scroll if currently animating or within quiet period 224 | if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 225 | event.preventDefault(); 226 | return; 227 | } 228 | var current = $(settings.sectionContainer + ".active"), 229 | next = $(settings.sectionContainer + "[data-index='" + (page_index) + "']"), 230 | el5 = $(this); 231 | 232 | if(next.length > 0) { 233 | var next_index = next.data("index"); 234 | current.removeClass("active"); 235 | next.addClass("active"); 236 | $(".onepage-pagination li a" + ".active").removeClass("active"); 237 | $(".onepage-pagination li a" + "[data-index='" + (page_index) + "']").addClass("active"); 238 | 239 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 240 | body.addClass("viewing-page-"+ next_index); 241 | 242 | pos = ((page_index - 1) * 100) * -1; 243 | 244 | if (history.replaceState && settings.updateURL == true) { 245 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (parseInt(page_index) - 1); 246 | history.pushState( {}, document.title, href ); 247 | } 248 | el5.transformPage(settings, pos, page_index, next); 249 | lastAnimation = timeNow; 250 | } 251 | } 252 | 253 | /*-------------------------------------------*/ 254 | /* Responsive Fallback trigger */ 255 | /*-------------------------------------------*/ 256 | 257 | var responsive = function() { 258 | 259 | if ($(document).width() < settings.responsiveFallback) { 260 | 261 | body.addClass("disabled-onepage-scroll"); 262 | $(document).off('mousewheel DOMMouseScroll', mouseWheelHandler); 263 | $(document).off("swipeDown swipeUp"); 264 | 265 | } else { 266 | 267 | if (body.hasClass("disabled-onepage-scroll")) { 268 | bodyremoveClass("disabled-onepage-scroll"); 269 | $("html, body, .wrapper").animate({ scrollTop: 0 }, "fast"); 270 | } 271 | 272 | $(document).swipeEvents().on("swipeDown", function(event){ 273 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 274 | el.moveUp(); 275 | }).on("swipeUp", function(event){ 276 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 277 | el.moveDown(); 278 | }); 279 | 280 | 281 | $(document).on('mousewheel DOMMouseScroll', mouseWheelHandler); 282 | 283 | } 284 | } 285 | 286 | /*-------------------------------------------*/ 287 | /* Initialize scroll detection */ 288 | /*-------------------------------------------*/ 289 | 290 | function init_scroll(event, delta) { 291 | var deltaOfInterest = delta; 292 | 293 | if (deltaOfInterest < 0) { 294 | el.moveDown() 295 | } else { 296 | el.moveUp() 297 | } 298 | } 299 | 300 | 301 | /*-------------------------------------------*/ 302 | /* Prepare Everything */ 303 | /*-------------------------------------------*/ 304 | 305 | el.addClass("onepage-wrapper") 306 | el.css("position","relative"); 307 | $.each(sections, function(i, item){ 308 | $(this).addClass("ops-section").data("index", i + 1); 309 | topPos = topPos + 100; 310 | 311 | if(settings.pagination == true) { 312 | paginationList += "
  • "; 313 | } 314 | }); 315 | 316 | $(document).swipeEvents().on("swipeDown", function(event){ 317 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 318 | el.moveUp(); 319 | }).on("swipeUp", function(event){ 320 | if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 321 | el.moveDown(); 322 | }); 323 | 324 | // Create Pagination and Display Them 325 | if(settings.pagination == true) { 326 | $("
      " + paginationList + "
    ").prependTo("body"); 327 | posTop = (el.find(".onepage-pagination").height() / 2) * -1; 328 | el.find(".onepage-pagination").css("margin-top", posTop); 329 | } 330 | 331 | if(window.location.hash != "" && window.location.hash != "#1") { 332 | var init_index = window.location.hash.replace("#", ""), 333 | next = $(settings.sectionContainer + "[data-index='" + (init_index) + "']"), 334 | next_index = next.data("index"); 335 | 336 | $(settings.sectionContainer + "[data-index='" + init_index + "']").addClass("active") 337 | body.addClass("viewing-page-"+ init_index) 338 | if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + init_index + "']").addClass("active"); 339 | 340 | if(next) { 341 | next.addClass("active") 342 | if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + init_index + "']").addClass("active"); 343 | 344 | document.body.className = document.body.className.replace(/\bviewing-page-\d.*?\b/g, ''); 345 | 346 | body.addClass("viewing-page-" + next_index) 347 | if (history.replaceState && settings.updateURL == true) { 348 | var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (init_index); 349 | history.pushState( {}, document.title, href ); 350 | } 351 | } 352 | var pos = ((init_index - 1) * 100) * -1; 353 | el.transformPage(settings, pos, init_index); 354 | 355 | }else{ 356 | $(settings.sectionContainer + "[data-index='1']").addClass("active"); 357 | body.addClass("viewing-page-1"); 358 | if(settings.pagination == true) $(".onepage-pagination li a[data-index='1']").addClass("active"); 359 | } 360 | 361 | function paginationHandler() { 362 | var page_index = this.dataset.index; 363 | el.moveTo(page_index); 364 | } 365 | 366 | 367 | if(settings.pagination == true) { 368 | $(".onepage-pagination li a").click(function (){ 369 | var page_index = $(this).data("index"); 370 | el.moveTo(page_index); 371 | }); 372 | } 373 | 374 | function mouseWheelHandler(event) { 375 | event.preventDefault(); 376 | var delta = event.wheelDelta || -event.detail; 377 | if(!body.hasClass("disabled-onepage-scroll")) init_scroll(event, delta); 378 | } 379 | 380 | $(document).on('mousewheel DOMMouseScroll', mouseWheelHandler); 381 | 382 | if(settings.responsiveFallback != false) { 383 | window.onresize = function(){ 384 | responsive(); 385 | } 386 | 387 | responsive(); 388 | } 389 | 390 | function keydownHandler(e) { 391 | var tag = e.target.tagName.toLowerCase(); 392 | 393 | if (!body.hasClass("disabled-onepage-scroll")) { 394 | switch(e.which) { 395 | case 38: 396 | if (tag != 'input' && tag != 'textarea') el.moveUp() 397 | break; 398 | case 40: 399 | if (tag != 'input' && tag != 'textarea') el.moveDown() 400 | break; 401 | default: return; 402 | } 403 | } 404 | return false; 405 | } 406 | 407 | if(settings.keyboard == true) { 408 | document.onkeydown = keydownHandler; 409 | } 410 | return false; 411 | } 412 | 413 | 414 | }) 415 | })(Zepto) -------------------------------------------------------------------------------- /zepto.onepagescroll.min.js: -------------------------------------------------------------------------------- 1 | (function(e){e.extend(e.fn,{onePageScroll:function(t){function d(e,t){var n=t;if(n<0){i.moveDown()}else{i.moveUp()}}function w(){var e=this.dataset.index;i.moveTo(e)}function E(e){e.preventDefault();var t=e.wheelDelta||-e.detail;if(!h.hasClass("disabled-onepage-scroll"))d(e,t)}function S(e){var t=e.target.tagName.toLowerCase();if(!h.hasClass("disabled-onepage-scroll")){switch(e.which){case 38:if(t!="input"&&t!="textarea")i.moveUp();break;case 40:if(t!="input"&&t!="textarea")i.moveDown();break;default:return}}return false}var n={sectionContainer:"section",easing:"ease",animationTime:1e3,pagination:true,updateURL:false,keyboard:true,beforeMove:null,afterMove:null,loop:false,responsiveFallback:false};var r=e.extend({},n,t),i=e(this),s=e(r.sectionContainer),o=s.length,u="off",a=0,f=0,f=0,l=300,c="",h=e("body");e.fn.swipeEvents=function(){return this.each(function(){function i(e){var i=e.touches;if(i&&i.length){t=i[0].pageX;n=i[0].pageY;r.on("touchmove",s)}}function s(e){var i=e.touches;if(i&&i.length){e.preventDefault();var o=t-i[0].pageX;var u=n-i[0].pageY;if(o>=50){r.trigger("swipeLeft")}if(o<=-50){r.trigger("swipeRight")}if(u>=50){r.trigger("swipeUp")}if(u<=-50){r.trigger("swipeDown")}if(Math.abs(o)>=50||Math.abs(u)>=50){r.off("touchmove",s)}}}var t,n,r=e(this);r.on("touchstart",i)})};e.fn.transformPage=function(t,n,r,i){var s=e(this);if(typeof t.beforeMove=="function")t.beforeMove(r,i);s.animate({translate3d:"0, "+n+"%, 0"},t.animationTime,t.easing,function(){if(typeof t.afterMove=="function")t.afterMove(r)})};e.fn.moveDown=function(){var t=(new Date).getTime();if(t-f0){var u=s.data("index");i.removeClass("active");s.addClass("active");e(".onepage-pagination li a"+".active").removeClass("active");e(".onepage-pagination li a"+"[data-index='"+t+"']").addClass("active");document.body.className=document.body.className.replace(/\bviewing-page-\d.*?\b/g,"");h.addClass("viewing-page-"+u);b=(t-1)*100*-1;if(history.replaceState&&r.updateURL==true){var a=window.location.href.substr(0,window.location.href.indexOf("#"))+"#"+(parseInt(t)-1);history.pushState({},document.title,a)}o.transformPage(r,b,t,s);f=n}};var p=function(){if(e(document).width()"}});e(document).swipeEvents().on("swipeDown",function(t){if(!e("body").hasClass("disabled-onepage-scroll"))t.preventDefault();i.moveUp()}).on("swipeUp",function(t){if(!e("body").hasClass("disabled-onepage-scroll"))t.preventDefault();i.moveDown()});if(r.pagination==true){e("
      "+c+"
    ").prependTo("body");posTop=i.find(".onepage-pagination").height()/2*-1;i.find(".onepage-pagination").css("margin-top",posTop)}if(window.location.hash!=""&&window.location.hash!="#1"){var v=window.location.hash.replace("#",""),m=e(r.sectionContainer+"[data-index='"+v+"']"),g=m.data("index");e(r.sectionContainer+"[data-index='"+v+"']").addClass("active");h.addClass("viewing-page-"+v);if(r.pagination==true)e(".onepage-pagination li a"+"[data-index='"+v+"']").addClass("active");if(m){m.addClass("active");if(r.pagination==true)e(".onepage-pagination li a"+"[data-index='"+v+"']").addClass("active");document.body.className=document.body.className.replace(/\bviewing-page-\d.*?\b/g,"");h.addClass("viewing-page-"+g);if(history.replaceState&&r.updateURL==true){var y=window.location.href.substr(0,window.location.href.indexOf("#"))+"#"+v;history.pushState({},document.title,y)}}var b=(v-1)*100*-1;i.transformPage(r,b,v)}else{e(r.sectionContainer+"[data-index='1']").addClass("active");h.addClass("viewing-page-1");if(r.pagination==true)e(".onepage-pagination li a[data-index='1']").addClass("active")}if(r.pagination==true){e(".onepage-pagination li a").click(function(){var t=e(this).data("index");i.moveTo(t)})}e(document).on("mousewheel DOMMouseScroll",E);if(r.responsiveFallback!=false){window.onresize=function(){p()};p()}if(r.keyboard==true){document.onkeydown=S}return false}})})(Zepto) --------------------------------------------------------------------------------