├── .gitignore ├── AUTHORS.rst ├── CHANGELOG.rst ├── LICENSE.rst ├── README.rst ├── bower.json ├── docs ├── Makefile ├── _build │ ├── doctrees │ │ ├── environment.pickle │ │ ├── index.doctree │ │ └── src │ │ │ ├── class_api │ │ │ ├── methods.doctree │ │ │ └── properties.doctree │ │ │ ├── contributing │ │ │ ├── guide.doctree │ │ │ ├── plugins.doctree │ │ │ └── plugins_list.doctree │ │ │ └── introduction │ │ │ ├── how_to_implement.doctree │ │ │ ├── how_to_update.doctree │ │ │ └── why_classjs.doctree │ └── html │ │ ├── .buildinfo │ │ ├── _sources │ │ ├── index.txt │ │ └── src │ │ │ ├── class_api │ │ │ ├── methods.txt │ │ │ └── properties.txt │ │ │ ├── contributing │ │ │ ├── guide.txt │ │ │ ├── plugins.txt │ │ │ └── plugins_list.txt │ │ │ └── introduction │ │ │ ├── how_to_implement.txt │ │ │ ├── how_to_update.txt │ │ │ └── why_classjs.txt │ │ ├── _static │ │ ├── ajax-loader.gif │ │ ├── basic.css │ │ ├── comment-bright.png │ │ ├── comment-close.png │ │ ├── comment.png │ │ ├── default.css │ │ ├── doctools.js │ │ ├── down-pressed.png │ │ ├── down.png │ │ ├── file.png │ │ ├── jquery.js │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── sidebar.js │ │ ├── underscore.js │ │ ├── up-pressed.png │ │ ├── up.png │ │ └── websupport.js │ │ ├── genindex.html │ │ ├── index.html │ │ ├── objects.inv │ │ ├── search.html │ │ ├── searchindex.js │ │ └── src │ │ ├── class_api │ │ ├── methods.html │ │ └── properties.html │ │ ├── contributing │ │ ├── guide.html │ │ ├── plugins.html │ │ └── plugins_list.html │ │ └── introduction │ │ ├── how_to_implement.html │ │ ├── how_to_update.html │ │ └── why_classjs.html ├── conf.py ├── index.html ├── index.rst └── src │ ├── class_api │ ├── methods.rst │ └── properties.rst │ ├── contributing │ ├── guide.rst │ └── plugins.rst │ └── introduction │ ├── how_to_implement.rst │ ├── how_to_update.rst │ └── why_classjs.rst ├── index.html ├── src ├── class.js └── class.min.js └── tests ├── index.html ├── libs ├── jquery.min.js ├── mootools.min.js └── prototype.min.js ├── qunit ├── qunit.css ├── qunit.js └── same.js ├── testDemo.html ├── testLibs.html └── tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | bower_components/ -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | the class.js library is written and maintained by: 2 | 3 | - Angelo Dini 4 | 5 | class.js is heavily inspired by the following libraries: 6 | 7 | - MooTools Class 8 | - JS.Class 9 | - Classy -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | class.js 3 | ======== 4 | 5 | v1.0.0 6 | ------ 7 | - version dump, codebase did not encounter any bigger issues. 8 | 9 | v1.0.beta1 10 | ---------- 11 | - added initial release with support for extend, implement, getOptions, setOptions, 12 | noConflict, parent and version. -------------------------------------------------------------------------------- /LICENSE.rst: -------------------------------------------------------------------------------- 1 | # class.js - simple class based inheritance 2 | # copyright (c) 2012 Angelo Dini and contributors 3 | # https://github.com/finalangel 4 | 5 | Some rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | * Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following 16 | disclaimer in the documentation and/or other materials provided 17 | with the distribution. 18 | 19 | * The names of the contributors may not be used to endorse or 20 | promote products derived from this software without specific 21 | prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Class.js - Class Based Inheritance 2 | ================================== 3 | 4 | .. image:: https://travis-ci.org/divio/classjs-plugins.png?branch=master 5 | :target: https://travis-ci.org/divio/classjs-plugins 6 | 7 | https://github.com/divio/classjs 8 | 9 | Class.js is a JavaScript library for building class based object-oriented programms using JavaScript's prototypal 10 | inheritance. It strives to mimic classical class inheritance provided by other languages such as Python, Java or PHP. 11 | Its syntax is heavily inspired by MooTools's class implementation. 12 | 13 | https://github.com/divio/classjs-plugins 14 | 15 | Class.js plugins are aimed for professionals with extensive JavaScript knowledge. Each plugin follows a simplistic and 16 | a modular approach. All plugins have demos, tests and documentation regarding their options, methods, events and 17 | callbacks. 18 | 19 | 20 | Documentation 21 | ------------- 22 | 23 | | Visit `classjs.rtfd.org `_ for a full documentation or go to the `demo page `_ to view the examples. 24 | | Please use github to report bugs or feature requests. Include a `jsfiddle `_ or equivalent example whenever possible. 25 | 26 | 27 | License 28 | ------- 29 | 30 | Distributed under the BSD `LICENSE `_. 31 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "class.js", 3 | "main": "src/class.js", 4 | "version": "1.0.0", 5 | "ignore": [ 6 | "docs", 7 | "tests", 8 | ".gitignore", 9 | "*.rst", 10 | "*.html" 11 | ], 12 | "dependencies": {}, 13 | "devDependencies": {}, 14 | "keywords": [ 15 | "class", 16 | "classjs", 17 | "javascript", 18 | "library" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | 15 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest 16 | 17 | help: 18 | @echo "Please use \`make ' where is one of" 19 | @echo " html to make standalone HTML files" 20 | @echo " dirhtml to make HTML files named index.html in directories" 21 | @echo " singlehtml to make a single large HTML file" 22 | @echo " pickle to make pickle files" 23 | @echo " json to make JSON files" 24 | @echo " htmlhelp to make HTML files and a HTML help project" 25 | @echo " qthelp to make HTML files and a qthelp project" 26 | @echo " devhelp to make HTML files and a Devhelp project" 27 | @echo " epub to make an epub" 28 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 29 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 30 | @echo " text to make text files" 31 | @echo " man to make manual pages" 32 | @echo " changes to make an overview of all changed/added/deprecated items" 33 | @echo " linkcheck to check all external links for integrity" 34 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 35 | 36 | clean: 37 | -rm -rf $(BUILDDIR)/* 38 | 39 | html: 40 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 41 | @echo 42 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 43 | 44 | dirhtml: 45 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 48 | 49 | singlehtml: 50 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 51 | @echo 52 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 53 | 54 | pickle: 55 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 56 | @echo 57 | @echo "Build finished; now you can process the pickle files." 58 | 59 | json: 60 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 61 | @echo 62 | @echo "Build finished; now you can process the JSON files." 63 | 64 | htmlhelp: 65 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 66 | @echo 67 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 68 | ".hhp project file in $(BUILDDIR)/htmlhelp." 69 | 70 | qthelp: 71 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 72 | @echo 73 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 74 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 75 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ClassyJS.qhcp" 76 | @echo "To view the help file:" 77 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ClassyJS.qhc" 78 | 79 | devhelp: 80 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 81 | @echo 82 | @echo "Build finished." 83 | @echo "To view the help file:" 84 | @echo "# mkdir -p $$HOME/.local/share/devhelp/ClassyJS" 85 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ClassyJS" 86 | @echo "# devhelp" 87 | 88 | epub: 89 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 90 | @echo 91 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 92 | 93 | latex: 94 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 95 | @echo 96 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 97 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 98 | "(use \`make latexpdf' here to do that automatically)." 99 | 100 | latexpdf: 101 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 102 | @echo "Running LaTeX files through pdflatex..." 103 | make -C $(BUILDDIR)/latex all-pdf 104 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 105 | 106 | text: 107 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 108 | @echo 109 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 110 | 111 | man: 112 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 113 | @echo 114 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 115 | 116 | changes: 117 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 118 | @echo 119 | @echo "The overview file is in $(BUILDDIR)/changes." 120 | 121 | linkcheck: 122 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 123 | @echo 124 | @echo "Link check complete; look for any errors in the above output " \ 125 | "or in $(BUILDDIR)/linkcheck/output.txt." 126 | 127 | doctest: 128 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 129 | @echo "Testing of doctests in the sources finished, look at the " \ 130 | "results in $(BUILDDIR)/doctest/output.txt." 131 | -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/class_api/methods.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/class_api/methods.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/class_api/properties.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/class_api/properties.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/contributing/guide.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/contributing/guide.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/contributing/plugins.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/contributing/plugins.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/contributing/plugins_list.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/contributing/plugins_list.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/introduction/how_to_implement.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/introduction/how_to_implement.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/introduction/how_to_update.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/introduction/how_to_update.doctree -------------------------------------------------------------------------------- /docs/_build/doctrees/src/introduction/why_classjs.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/doctrees/src/introduction/why_classjs.doctree -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: cd386de848af5b1e44d828feaaf6b8a6 4 | tags: fbb0d17656682115ca4d033fb2f83ba1 5 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.txt: -------------------------------------------------------------------------------- 1 | .. classjs documentation master file, created by 2 | sphinx-quickstart on Tue Apr 3 09:48:09 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | 7 | ####### 8 | Welcome 9 | ####### 10 | 11 | class.js is a JavaScript library for building class based object-oriented programs using 12 | JavaScript's prototypal inheritance. class.js strives to mimic classical class inheritance 13 | provided by other languages such as Python, Java or C. Its syntax is heavily inspired 14 | by MooTools class implementation. 15 | 16 | The latest stable version is |release| - https://github.com/finalangel/classjs 17 | 18 | 19 | ############ 20 | Introduction 21 | ############ 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | 26 | src/introduction/why_classjs.rst 27 | src/introduction/how_to_implement.rst 28 | src/introduction/how_to_update.rst 29 | 30 | 31 | ######### 32 | Class API 33 | ######### 34 | 35 | .. toctree:: 36 | :maxdepth: 2 37 | 38 | src/class_api/methods.rst 39 | src/class_api/properties.rst 40 | 41 | 42 | ############ 43 | Contributing 44 | ############ 45 | 46 | .. toctree:: 47 | :maxdepth: 2 48 | 49 | src/contributing/guide.rst 50 | src/contributing/plugins.rst 51 | src/contributing/plugins_list.rst -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/class_api/methods.txt: -------------------------------------------------------------------------------- 1 | ******* 2 | methods 3 | ******* 4 | 5 | The following methods can be attached to a new class. 6 | 7 | 8 | new Class(object); 9 | ================== 10 | 11 | ``(returns object)`` - This is the class constructor and passes the provided object to the instances prototype. 12 | 13 | Create a new Class:: 14 | 15 | var Animal = new Class({ 16 | initialize: function (name, age) { 17 | this.name = name; 18 | this.age = age; 19 | }, 20 | eat: function () { 21 | alert(this.name + ' is eating now.'); 22 | } 23 | }); 24 | 25 | For a better explanation to ``initialize`` consult the class.js properties section. 26 | 27 | 28 | Class.extend(object) 29 | ==================== 30 | 31 | ``(returns object)`` - The object or class passed through extend will be **merged** with the assigned class following 32 | the previous example. 33 | 34 | Extend the class:: 35 | 36 | Animal.extend({ 37 | die: function () { 38 | alert(this.name + ' died at age ' + this.age); 39 | } 40 | }); 41 | 42 | var cat = new Animal('Sora', 4); 43 | cat.die(); // alerts "Sora died at age 4" 44 | 45 | You can create a new instance and extend it, without modififying the parent class:: 46 | 47 | var MyAnimal = new Class(Animal); 48 | MyAnimal.extend({ 49 | clone: function () { 50 | alert(this.name + ' can clone itself now.'); 51 | } 52 | }); 53 | 54 | // can't clone 55 | var sora = new Animal('Sora', 4); 56 | var pitschy = new MyAnimal('Pitschy', 4); 57 | // sora.clone(); fails 58 | pitschy.clone(); // can clone 59 | 60 | 61 | Class.implement(array) 62 | ====================== 63 | 64 | ``(returns object)`` - Each object or class within the array will be **added** to the assigned class following 65 | the previous example. 66 | 67 | Implementing new methods:: 68 | 69 | // preparing a class 70 | var Mammal = new Class({ 71 | swim: function () { 72 | alert(this.name + ' can swim now.'); 73 | }, 74 | dive: function () { 75 | alert(this.name + ' can dive now.'); 76 | } 77 | }); 78 | 79 | // preparing a normal object 80 | var Bird = { 81 | fly: function () { 82 | alert(this.name + ' can fly now.'); 83 | } 84 | }; 85 | 86 | Animal.implement([Mammal, Bird]); 87 | 88 | var cat = new Animal('Sora', 4); 89 | cat.swim(); // alerts "Sora can swim now." 90 | cat.dive(); // alerts "Sora can dive now." 91 | cat.fly(); // alerts "Sora can fly now." 92 | 93 | .. note:: 94 | implement simply **copies** object methods over into the new class and breaks the prototypal chain. 95 | It does not create a parent link nor does it copy ``initialize`` into the new class. 96 | Implemented methods cannot be overwritten to prevent accidental conflicts. Use extend to modify 97 | available class methods. 98 | 99 | 100 | Class.getOptions() 101 | ================== 102 | 103 | ``(returns object)`` - Gathers assigned options and returns them. 104 | 105 | Getting options from a class:: 106 | 107 | var Animal = new Class({ 108 | options: { 109 | 'name': '', 110 | 'age': null 111 | }, 112 | initialize: function (name, age) { 113 | this.name = this.options.name || name; 114 | this.age = this.options.age || age; 115 | } 116 | }); 117 | 118 | Animal.getOptions(); // returns { 'name': '', 'age': null } 119 | 120 | It is not possible to get the options once an instance has been created. 121 | You can access the instance objects through their options name ``cat.options.name``. 122 | 123 | 124 | Class.setOptions(object) 125 | ======================== 126 | 127 | ``(returns object)`` - Sets and merges a given options object to the classes internal options object. 128 | 129 | Setting options for a class:: 130 | 131 | var Animal = new Class({ 132 | options: { 133 | 'name': '', 134 | 'age': null 135 | }, 136 | initialize: function (name, age) { 137 | this.name = this.options.name || name; 138 | this.age = this.options.age || age; 139 | } 140 | }); 141 | 142 | Animal.setOptions({ 143 | 'name': undefined, 144 | 'dead': false 145 | }); 146 | 147 | Animal.getOptions(); // returns { 'name': undefined, 'age': null, 'dead': false } 148 | 149 | It is not possible to change the options once an instance has been created. 150 | You can access the instance objects through their options name ``cat.options.name``. 151 | 152 | 153 | Class.noConflict() 154 | ================== 155 | 156 | ``(returns Class)`` - Removes the class object from the window object and restores what was there before 157 | class.js was loaded. 158 | 159 | Using class.js with multiple libraries:: 160 | 161 | // loading MooTools 162 | var Classy = Class.noConflict(); 163 | 164 | var Animal = new Classy({ 165 | initialize: function (name, age) { 166 | this.name = name; 167 | this.age = age; 168 | }, 169 | eat: function () { 170 | alert(this.name + ' is eating now.'); 171 | } 172 | }); 173 | 174 | var cat = new Animal('Sora', 4); 175 | cat.eat(); // alerts "Sora is eating now." 176 | 177 | 178 | Class.version 179 | =============== 180 | 181 | ``(returns string)`` - Returns the current running class.js version as a string. 182 | 183 | alert(Class.version); // alerts current class.js version -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/class_api/properties.txt: -------------------------------------------------------------------------------- 1 | ********** 2 | properties 3 | ********** 4 | 5 | The following properties can be used within the Classes passing object. 6 | 7 | 8 | initialize: function 9 | ==================== 10 | 11 | ``(returns constructor)`` - The initialize function serves as constructor on instance creation. 12 | 13 | Create a new Class:: 14 | 15 | var Animal = new Class({ 16 | initialize: function(name, age) { 17 | this.name = name; 18 | this.age = age; 19 | } 20 | }); 21 | 22 | // the passing options will be passed through the constructor initialize 23 | new Animal('Satan', 21); 24 | 25 | 26 | implement: array 27 | ================ 28 | 29 | ``(returns object)`` - Each object or class within the array will be **added** to the assigned class. 30 | 31 | Implementing new methods:: 32 | 33 | // preparing a class 34 | var Mammal = new Class({ 35 | swim: function () { 36 | alert(this.name + ' can swim now.'); 37 | }, 38 | dive: function () { 39 | alert(this.name + ' can dive now.'); 40 | } 41 | }); 42 | 43 | // preparing a normal object 44 | var Bird = { 45 | fly: function () { 46 | alert(this.name + ' can fly now.'); 47 | } 48 | }; 49 | 50 | var Animal = new Class({ 51 | implement: [Mammal, Bird], 52 | initialize: function (name, age) { 53 | this.name = name; 54 | this.age = age; 55 | }, 56 | eat: function () { 57 | alert(this.name + ' is eating now.'); 58 | } 59 | }); 60 | 61 | var cat = new Animal('Sora', 4); 62 | cat.swim(); // alerts "Sora can swim now." 63 | cat.dive(); // alerts "Sora can dive now." 64 | cat.fly(); // alerts "Sora can fly now." 65 | 66 | This property works identical to the Class.implement method. 67 | 68 | 69 | options: object 70 | =============== 71 | 72 | ``(returns object)`` - The options object represents a JSON structure. 73 | 74 | Attach options to a Class:: 75 | 76 | var Animal = new Class({ 77 | options: { 78 | 'name': '', 79 | 'age': null, 80 | 'dead': false 81 | }, 82 | initialize: function (options) { 83 | // merging objects using jQuery 84 | this.options = options; 85 | 86 | // you might want to merge the two ojects using jQuery 87 | // this.options = jQuery.extend(true, {}, this.options, options) 88 | } 89 | }); 90 | 91 | var cat = new Animal({ 92 | 'name': 'Sora', 93 | 'age': 4 94 | }); 95 | 96 | // call options direct 97 | alert(cat.options.name); // alerts 'Sora' 98 | 99 | 100 | this.parent() 101 | ============= 102 | 103 | ``(returns function)`` - When called from within a class.js function this invokes the parent function of the same name. 104 | This is useful when extending an existing class.js plugin. 105 | 106 | Example usage of parent:: 107 | 108 | var Animal = new Class({ 109 | initialize: function (name, age) { 110 | this.name = name; 111 | this.age = age; 112 | }, 113 | getName: function () { 114 | alert(this.name + ' is eating now.'); 115 | } 116 | }); 117 | 118 | Animal.extend({ 119 | getName: function () { 120 | // calls previous getName first 121 | this.parent(); 122 | alert(this.name + ' is ' + this.age + ' years old.'); 123 | } 124 | }); 125 | 126 | var cat = new Animal('Sora', 4); 127 | cat.getName(); // alerts both calls, name and age -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/contributing/guide.txt: -------------------------------------------------------------------------------- 1 | ****************** 2 | Contribution guide 3 | ****************** 4 | 5 | All open-source projects live through their community, so does class.js. You are very welcome to contribute 6 | bug fixes and feature proposals. Please note the following guidelines: 7 | 8 | * class.js is hosted on github: http://github.com/FinalAngel/classjs 9 | 10 | * Use github's issues tracker to submit bug fixes or feature proposals 11 | 12 | * Whenever possible include a `jsfiddle `_ to an issue. 13 | 14 | * It is good practice to fork a project and make your changes through your own fork. 15 | 16 | * Always send a pull request with a reference to the github ticket. 17 | 18 | * Include enough information within your commit messages and pull request to make life easier for us. 19 | 20 | 21 | Don't feel offended if a pull or feature request has been rejected. We always provide reasonable comments 22 | or information's about how your code could be improved. 23 | 24 | Start by fixing or extending the documentation ;) -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/contributing/plugins.txt: -------------------------------------------------------------------------------- 1 | ******* 2 | Plugins 3 | ******* 4 | 5 | Creating and extending plugins is the entire purpose of class.js. 6 | To encourage users to write and extend plugins, we need to establish some common guidelines. 7 | 8 | 9 | Creating a plugin 10 | ================= 11 | 12 | First of all, create a JavaScript file and include the following information within the top of your script: 13 | 14 | * the authors name 15 | * the plugins version 16 | * the plugins license 17 | * the plugins dependencies 18 | 19 | For example:: 20 | 21 | /** 22 | * @author Angelo Dini 23 | * @version 1.0 24 | * @copyright Distributed under the BSD License. 25 | * @requires class.js, jQuery 26 | */ 27 | 28 | You can include the information at any style of your choice whatsoever. 29 | Just insure that you include the required information within the development and minified versions alike. 30 | 31 | 32 | ==== 33 | 34 | 35 | Creating a namespace is important to keep the amount of global variables as low as possible. 36 | 37 | I prefere to use Cl as the shorthand for **Cl** ass:: 38 | 39 | var Cl = window.Cl || {}; 40 | 41 | You are welcome to use this namespace as well. You might want to crossreference the core plugins 42 | for already reservated names like Cl.Lightbox or Cl.Carousel. 43 | 44 | 45 | ==== 46 | 47 | 48 | Creating a closure allows you to create an environment where you don't have to worry about other 49 | plugins namespaces. class.js uses this system by itself:: 50 | 51 | (function(){ 52 | // your code here 53 | })(); 54 | 55 | // you might want to pass some custom variables 56 | (function($){ 57 | // your code here 58 | })(jQuery); 59 | 60 | 61 | ==== 62 | 63 | 64 | When choosing names be descriptive and use CamelCase for naming conventions:: 65 | 66 | Cl.MyPlugin = new Class({ 67 | initialize: function () { 68 | return 'My first plugin'; 69 | } 70 | }); 71 | 72 | 73 | ==== 74 | 75 | 76 | If we combine those techniques your plugin would look like this:: 77 | 78 | /** 79 | * @author Angelo Dini, Distributed under the BSD License. 80 | * @version 1.0 81 | * @requires class.js, jQuery 82 | */ 83 | (function(){ 84 | Cl.MyPlugin = new Class({ 85 | initialize: function () { 86 | return 'My first plugin'; 87 | } 88 | }); 89 | })(); 90 | 91 | 92 | Submitting a plugin 93 | =================== 94 | 95 | If you successfully created a plugin worth spreading let us know https://twitter.com/finalangel and we will 96 | include it within the plugins list. We just require the a website or download link. 97 | 98 | 99 | Core plugins 100 | ============ 101 | 102 | Besides the above described plugins we maintain several core plugins like ``Cl.Lightbox`` or 103 | ``Cl.Carousel``. Those core plugins differ in various ways: 104 | 105 | **A core plugin requires tests and documentation** preferable within the repository itself, 106 | with the option of external documentation. This allows for an easy development process and 107 | insures a high level of quality. Those plugins receive a **reserved namespace** like 108 | ``Cl.AutoComplete`` and will be listed separately. 109 | 110 | It is also a **must** to provide an example page in which the functionality of the plugin can 111 | be demonstrated. Either through using github or a dedicated microsite. 112 | 113 | You are encouraged to use classjs as a name prefix when using a subversion system. For 114 | example ``classjs-lightbox`` or ``classjs-autocomplete``. 115 | 116 | Your plugin also needs to be easily extendable while providing meaningful options. -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/contributing/plugins_list.txt: -------------------------------------------------------------------------------- 1 | *************** 2 | List of plugins 3 | *************** 4 | 5 | Thanks for the following authors for their amazing plugins and effort: 6 | 7 | 8 | Core plugins 9 | ============ 10 | 11 | * `Cl.Carousel `_ [Angelo Dini] 12 | * `Cl.Lightbox `_ [Angelo Dini] 13 | 14 | 15 | User plugins 16 | ============ 17 | * 18 | 19 | Please refer to the :doc:`how_to` page for creating your own plugin. -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/introduction/how_to_implement.txt: -------------------------------------------------------------------------------- 1 | **************** 2 | How to implement 3 | **************** 4 | 5 | Download the production version of class.js (minified) and implement it in your html code. 6 | 7 | For **HTML5** use:: 8 | 9 | 10 | 11 | For **HTML** and **XHTML** versions use:: 12 | 13 | 14 | 15 | You will be able to call ``Class.version`` within your preferred browsers console 16 | if class.js is implemented or initialized correctly. Feel free to explore the source. -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/introduction/how_to_update.txt: -------------------------------------------------------------------------------- 1 | ************* 2 | How to update 3 | ************* 4 | 5 | Update from Beta to 1.0 6 | ======================= 7 | 8 | There are no special adjustments required for this version. 9 | Beta releases will not be covered by any adaptation. 10 | Therefore consult the Changelog for more details. 11 | 12 | 13 | Update from classy.js to class.js 14 | ================================= 15 | 16 | There is not **yet** an official adapter from classy.js (Divio internal version) to class.js. 17 | You need to change your code to be compatible with class.js. Please follow this guide for a smooth transition: 18 | 19 | Comparison from old to new:: 20 | 21 | var Animal = Class.$extend(obj); // old 22 | var Animal = new Class(obj); // new 23 | 24 | var Tiger = Animal.$extend(obj); // old 25 | var Tiger = Animal.extend(obj); // new 26 | 27 | Class.$classyVersion; // old 28 | Class.version; // new 29 | 30 | Class.$withData(obj); // old 31 | Class.setOptions(obj); // new 32 | 33 | Class.$noConflict(); // old 34 | Class.noConflict(); // new 35 | 36 | this.$super(); // old 37 | this.parent(); // new 38 | 39 | initialize: function () {} // identical in both versions 40 | 41 | implement: [array] // identical in both version 42 | 43 | Additionally class.js provides the following features:: 44 | 45 | Class.getOptions(); 46 | Class.implement([array]); -------------------------------------------------------------------------------- /docs/_build/html/_sources/src/introduction/why_classjs.txt: -------------------------------------------------------------------------------- 1 | ************ 2 | Why class.js 3 | ************ 4 | 5 | I started learning JavaScript roughly in 2002 without the use of any framework. 6 | Back than Prototype was the big player and I did not understand its concept. 7 | I also had issues with Prototype’s none-modular approach splitting animation 8 | (script-aculo-us) from the core library. 9 | 10 | After I finishing my study I came across MooTools and quickly adapted my code to 11 | a more modular and re-usable style. At a certain point of my career the requirements 12 | for use of jQuery grew. jQuery’s popularity grow and we had to adapt. 13 | 14 | I am not a big fan of jQuery, especially jQuery’s UI approach. It is missing any 15 | modular structure and is almost impossible to extend. The fame of jQuery makes it 16 | hard to find a plugin for your case. If you end up finding one you end up changing 17 | the code to work for your specific case. This is wrong. I should be able to take 18 | the plugin and extend it, leaving the code untouched. This enables me to easily 19 | update and maintain the plugin without re-implementing your own changes. 20 | 21 | There is also a second reason. A lot of developers do not understand the principles 22 | of prototypal inheritance. All in all JavaScript is one of the few popular languages 23 | which adapts this concept. This is confusing and leads to misinterpretation. 24 | 25 | This is why I created class.js. 26 | 27 | -------------------------------------------------------------------------------- /docs/_build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /docs/_build/html/_static/basic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * basic.css 3 | * ~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- basic theme. 6 | * 7 | * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /* -- main layout ----------------------------------------------------------- */ 13 | 14 | div.clearer { 15 | clear: both; 16 | } 17 | 18 | /* -- relbar ---------------------------------------------------------------- */ 19 | 20 | div.related { 21 | width: 100%; 22 | font-size: 90%; 23 | } 24 | 25 | div.related h3 { 26 | display: none; 27 | } 28 | 29 | div.related ul { 30 | margin: 0; 31 | padding: 0 0 0 10px; 32 | list-style: none; 33 | } 34 | 35 | div.related li { 36 | display: inline; 37 | } 38 | 39 | div.related li.right { 40 | float: right; 41 | margin-right: 5px; 42 | } 43 | 44 | /* -- sidebar --------------------------------------------------------------- */ 45 | 46 | div.sphinxsidebarwrapper { 47 | padding: 10px 5px 0 10px; 48 | } 49 | 50 | div.sphinxsidebar { 51 | float: left; 52 | width: 230px; 53 | margin-left: -100%; 54 | font-size: 90%; 55 | } 56 | 57 | div.sphinxsidebar ul { 58 | list-style: none; 59 | } 60 | 61 | div.sphinxsidebar ul ul, 62 | div.sphinxsidebar ul.want-points { 63 | margin-left: 20px; 64 | list-style: square; 65 | } 66 | 67 | div.sphinxsidebar ul ul { 68 | margin-top: 0; 69 | margin-bottom: 0; 70 | } 71 | 72 | div.sphinxsidebar form { 73 | margin-top: 10px; 74 | } 75 | 76 | div.sphinxsidebar input { 77 | border: 1px solid #98dbcc; 78 | font-family: sans-serif; 79 | font-size: 1em; 80 | } 81 | 82 | div.sphinxsidebar #searchbox input[type="text"] { 83 | width: 170px; 84 | } 85 | 86 | div.sphinxsidebar #searchbox input[type="submit"] { 87 | width: 30px; 88 | } 89 | 90 | img { 91 | border: 0; 92 | } 93 | 94 | /* -- search page ----------------------------------------------------------- */ 95 | 96 | ul.search { 97 | margin: 10px 0 0 20px; 98 | padding: 0; 99 | } 100 | 101 | ul.search li { 102 | padding: 5px 0 5px 20px; 103 | background-image: url(file.png); 104 | background-repeat: no-repeat; 105 | background-position: 0 7px; 106 | } 107 | 108 | ul.search li a { 109 | font-weight: bold; 110 | } 111 | 112 | ul.search li div.context { 113 | color: #888; 114 | margin: 2px 0 0 30px; 115 | text-align: left; 116 | } 117 | 118 | ul.keywordmatches li.goodmatch a { 119 | font-weight: bold; 120 | } 121 | 122 | /* -- index page ------------------------------------------------------------ */ 123 | 124 | table.contentstable { 125 | width: 90%; 126 | } 127 | 128 | table.contentstable p.biglink { 129 | line-height: 150%; 130 | } 131 | 132 | a.biglink { 133 | font-size: 1.3em; 134 | } 135 | 136 | span.linkdescr { 137 | font-style: italic; 138 | padding-top: 5px; 139 | font-size: 90%; 140 | } 141 | 142 | /* -- general index --------------------------------------------------------- */ 143 | 144 | table.indextable { 145 | width: 100%; 146 | } 147 | 148 | table.indextable td { 149 | text-align: left; 150 | vertical-align: top; 151 | } 152 | 153 | table.indextable dl, table.indextable dd { 154 | margin-top: 0; 155 | margin-bottom: 0; 156 | } 157 | 158 | table.indextable tr.pcap { 159 | height: 10px; 160 | } 161 | 162 | table.indextable tr.cap { 163 | margin-top: 10px; 164 | background-color: #f2f2f2; 165 | } 166 | 167 | img.toggler { 168 | margin-right: 3px; 169 | margin-top: 3px; 170 | cursor: pointer; 171 | } 172 | 173 | div.modindex-jumpbox { 174 | border-top: 1px solid #ddd; 175 | border-bottom: 1px solid #ddd; 176 | margin: 1em 0 1em 0; 177 | padding: 0.4em; 178 | } 179 | 180 | div.genindex-jumpbox { 181 | border-top: 1px solid #ddd; 182 | border-bottom: 1px solid #ddd; 183 | margin: 1em 0 1em 0; 184 | padding: 0.4em; 185 | } 186 | 187 | /* -- general body styles --------------------------------------------------- */ 188 | 189 | a.headerlink { 190 | visibility: hidden; 191 | } 192 | 193 | h1:hover > a.headerlink, 194 | h2:hover > a.headerlink, 195 | h3:hover > a.headerlink, 196 | h4:hover > a.headerlink, 197 | h5:hover > a.headerlink, 198 | h6:hover > a.headerlink, 199 | dt:hover > a.headerlink { 200 | visibility: visible; 201 | } 202 | 203 | div.body p.caption { 204 | text-align: inherit; 205 | } 206 | 207 | div.body td { 208 | text-align: left; 209 | } 210 | 211 | .field-list ul { 212 | padding-left: 1em; 213 | } 214 | 215 | .first { 216 | margin-top: 0 !important; 217 | } 218 | 219 | p.rubric { 220 | margin-top: 30px; 221 | font-weight: bold; 222 | } 223 | 224 | img.align-left, .figure.align-left, object.align-left { 225 | clear: left; 226 | float: left; 227 | margin-right: 1em; 228 | } 229 | 230 | img.align-right, .figure.align-right, object.align-right { 231 | clear: right; 232 | float: right; 233 | margin-left: 1em; 234 | } 235 | 236 | img.align-center, .figure.align-center, object.align-center { 237 | display: block; 238 | margin-left: auto; 239 | margin-right: auto; 240 | } 241 | 242 | .align-left { 243 | text-align: left; 244 | } 245 | 246 | .align-center { 247 | text-align: center; 248 | } 249 | 250 | .align-right { 251 | text-align: right; 252 | } 253 | 254 | /* -- sidebars -------------------------------------------------------------- */ 255 | 256 | div.sidebar { 257 | margin: 0 0 0.5em 1em; 258 | border: 1px solid #ddb; 259 | padding: 7px 7px 0 7px; 260 | background-color: #ffe; 261 | width: 40%; 262 | float: right; 263 | } 264 | 265 | p.sidebar-title { 266 | font-weight: bold; 267 | } 268 | 269 | /* -- topics ---------------------------------------------------------------- */ 270 | 271 | div.topic { 272 | border: 1px solid #ccc; 273 | padding: 7px 7px 0 7px; 274 | margin: 10px 0 10px 0; 275 | } 276 | 277 | p.topic-title { 278 | font-size: 1.1em; 279 | font-weight: bold; 280 | margin-top: 10px; 281 | } 282 | 283 | /* -- admonitions ----------------------------------------------------------- */ 284 | 285 | div.admonition { 286 | margin-top: 10px; 287 | margin-bottom: 10px; 288 | padding: 7px; 289 | } 290 | 291 | div.admonition dt { 292 | font-weight: bold; 293 | } 294 | 295 | div.admonition dl { 296 | margin-bottom: 0; 297 | } 298 | 299 | p.admonition-title { 300 | margin: 0px 10px 5px 0px; 301 | font-weight: bold; 302 | } 303 | 304 | div.body p.centered { 305 | text-align: center; 306 | margin-top: 25px; 307 | } 308 | 309 | /* -- tables ---------------------------------------------------------------- */ 310 | 311 | table.docutils { 312 | border: 0; 313 | border-collapse: collapse; 314 | } 315 | 316 | table.docutils td, table.docutils th { 317 | padding: 1px 8px 1px 5px; 318 | border-top: 0; 319 | border-left: 0; 320 | border-right: 0; 321 | border-bottom: 1px solid #aaa; 322 | } 323 | 324 | table.field-list td, table.field-list th { 325 | border: 0 !important; 326 | } 327 | 328 | table.footnote td, table.footnote th { 329 | border: 0 !important; 330 | } 331 | 332 | th { 333 | text-align: left; 334 | padding-right: 5px; 335 | } 336 | 337 | table.citation { 338 | border-left: solid 1px gray; 339 | margin-left: 1px; 340 | } 341 | 342 | table.citation td { 343 | border-bottom: none; 344 | } 345 | 346 | /* -- other body styles ----------------------------------------------------- */ 347 | 348 | ol.arabic { 349 | list-style: decimal; 350 | } 351 | 352 | ol.loweralpha { 353 | list-style: lower-alpha; 354 | } 355 | 356 | ol.upperalpha { 357 | list-style: upper-alpha; 358 | } 359 | 360 | ol.lowerroman { 361 | list-style: lower-roman; 362 | } 363 | 364 | ol.upperroman { 365 | list-style: upper-roman; 366 | } 367 | 368 | dl { 369 | margin-bottom: 15px; 370 | } 371 | 372 | dd p { 373 | margin-top: 0px; 374 | } 375 | 376 | dd ul, dd table { 377 | margin-bottom: 10px; 378 | } 379 | 380 | dd { 381 | margin-top: 3px; 382 | margin-bottom: 10px; 383 | margin-left: 30px; 384 | } 385 | 386 | dt:target, .highlighted { 387 | background-color: #fbe54e; 388 | } 389 | 390 | dl.glossary dt { 391 | font-weight: bold; 392 | font-size: 1.1em; 393 | } 394 | 395 | .field-list ul { 396 | margin: 0; 397 | padding-left: 1em; 398 | } 399 | 400 | .field-list p { 401 | margin: 0; 402 | } 403 | 404 | .refcount { 405 | color: #060; 406 | } 407 | 408 | .optional { 409 | font-size: 1.3em; 410 | } 411 | 412 | .versionmodified { 413 | font-style: italic; 414 | } 415 | 416 | .system-message { 417 | background-color: #fda; 418 | padding: 5px; 419 | border: 3px solid red; 420 | } 421 | 422 | .footnote:target { 423 | background-color: #ffa; 424 | } 425 | 426 | .line-block { 427 | display: block; 428 | margin-top: 1em; 429 | margin-bottom: 1em; 430 | } 431 | 432 | .line-block .line-block { 433 | margin-top: 0; 434 | margin-bottom: 0; 435 | margin-left: 1.5em; 436 | } 437 | 438 | .guilabel, .menuselection { 439 | font-family: sans-serif; 440 | } 441 | 442 | .accelerator { 443 | text-decoration: underline; 444 | } 445 | 446 | .classifier { 447 | font-style: oblique; 448 | } 449 | 450 | abbr, acronym { 451 | border-bottom: dotted 1px; 452 | cursor: help; 453 | } 454 | 455 | /* -- code displays --------------------------------------------------------- */ 456 | 457 | pre { 458 | overflow: auto; 459 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 460 | } 461 | 462 | td.linenos pre { 463 | padding: 5px 0px; 464 | border: 0; 465 | background-color: transparent; 466 | color: #aaa; 467 | } 468 | 469 | table.highlighttable { 470 | margin-left: 0.5em; 471 | } 472 | 473 | table.highlighttable td { 474 | padding: 0 0.5em 0 0.5em; 475 | } 476 | 477 | tt.descname { 478 | background-color: transparent; 479 | font-weight: bold; 480 | font-size: 1.2em; 481 | } 482 | 483 | tt.descclassname { 484 | background-color: transparent; 485 | } 486 | 487 | tt.xref, a tt { 488 | background-color: transparent; 489 | font-weight: bold; 490 | } 491 | 492 | h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt { 493 | background-color: transparent; 494 | } 495 | 496 | .viewcode-link { 497 | float: right; 498 | } 499 | 500 | .viewcode-back { 501 | float: right; 502 | font-family: sans-serif; 503 | } 504 | 505 | div.viewcode-block:target { 506 | margin: -1px -10px; 507 | padding: 0 10px; 508 | } 509 | 510 | /* -- math display ---------------------------------------------------------- */ 511 | 512 | img.math { 513 | vertical-align: middle; 514 | } 515 | 516 | div.body div.math p { 517 | text-align: center; 518 | } 519 | 520 | span.eqno { 521 | float: right; 522 | } 523 | 524 | /* -- printout stylesheet --------------------------------------------------- */ 525 | 526 | @media print { 527 | div.document, 528 | div.documentwrapper, 529 | div.bodywrapper { 530 | margin: 0 !important; 531 | width: 100%; 532 | } 533 | 534 | div.sphinxsidebar, 535 | div.related, 536 | div.footer, 537 | #top-link { 538 | display: none; 539 | } 540 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/comment.png -------------------------------------------------------------------------------- /docs/_build/html/_static/default.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: sans-serif; 18 | font-size: 100%; 19 | background-color: #11303d; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: #1c4e63; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: #ffffff; 40 | color: #000000; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | div.footer { 45 | color: #ffffff; 46 | width: 100%; 47 | padding: 9px 0 9px 0; 48 | text-align: center; 49 | font-size: 75%; 50 | } 51 | 52 | div.footer a { 53 | color: #ffffff; 54 | text-decoration: underline; 55 | } 56 | 57 | div.related { 58 | background-color: #133f52; 59 | line-height: 30px; 60 | color: #ffffff; 61 | } 62 | 63 | div.related a { 64 | color: #ffffff; 65 | } 66 | 67 | div.sphinxsidebar { 68 | } 69 | 70 | div.sphinxsidebar h3 { 71 | font-family: 'Trebuchet MS', sans-serif; 72 | color: #ffffff; 73 | font-size: 1.4em; 74 | font-weight: normal; 75 | margin: 0; 76 | padding: 0; 77 | } 78 | 79 | div.sphinxsidebar h3 a { 80 | color: #ffffff; 81 | } 82 | 83 | div.sphinxsidebar h4 { 84 | font-family: 'Trebuchet MS', sans-serif; 85 | color: #ffffff; 86 | font-size: 1.3em; 87 | font-weight: normal; 88 | margin: 5px 0 0 0; 89 | padding: 0; 90 | } 91 | 92 | div.sphinxsidebar p { 93 | color: #ffffff; 94 | } 95 | 96 | div.sphinxsidebar p.topless { 97 | margin: 5px 10px 10px 10px; 98 | } 99 | 100 | div.sphinxsidebar ul { 101 | margin: 10px; 102 | padding: 0; 103 | color: #ffffff; 104 | } 105 | 106 | div.sphinxsidebar a { 107 | color: #98dbcc; 108 | } 109 | 110 | div.sphinxsidebar input { 111 | border: 1px solid #98dbcc; 112 | font-family: sans-serif; 113 | font-size: 1em; 114 | } 115 | 116 | 117 | 118 | /* -- hyperlink styles ------------------------------------------------------ */ 119 | 120 | a { 121 | color: #355f7c; 122 | text-decoration: none; 123 | } 124 | 125 | a:visited { 126 | color: #355f7c; 127 | text-decoration: none; 128 | } 129 | 130 | a:hover { 131 | text-decoration: underline; 132 | } 133 | 134 | 135 | 136 | /* -- body styles ----------------------------------------------------------- */ 137 | 138 | div.body h1, 139 | div.body h2, 140 | div.body h3, 141 | div.body h4, 142 | div.body h5, 143 | div.body h6 { 144 | font-family: 'Trebuchet MS', sans-serif; 145 | background-color: #f2f2f2; 146 | font-weight: normal; 147 | color: #20435c; 148 | border-bottom: 1px solid #ccc; 149 | margin: 20px -20px 10px -20px; 150 | padding: 3px 0 3px 10px; 151 | } 152 | 153 | div.body h1 { margin-top: 0; font-size: 200%; } 154 | div.body h2 { font-size: 160%; } 155 | div.body h3 { font-size: 140%; } 156 | div.body h4 { font-size: 120%; } 157 | div.body h5 { font-size: 110%; } 158 | div.body h6 { font-size: 100%; } 159 | 160 | a.headerlink { 161 | color: #c60f0f; 162 | font-size: 0.8em; 163 | padding: 0 4px 0 4px; 164 | text-decoration: none; 165 | } 166 | 167 | a.headerlink:hover { 168 | background-color: #c60f0f; 169 | color: white; 170 | } 171 | 172 | div.body p, div.body dd, div.body li { 173 | text-align: justify; 174 | line-height: 130%; 175 | } 176 | 177 | div.admonition p.admonition-title + p { 178 | display: inline; 179 | } 180 | 181 | div.admonition p { 182 | margin-bottom: 5px; 183 | } 184 | 185 | div.admonition pre { 186 | margin-bottom: 5px; 187 | } 188 | 189 | div.admonition ul, div.admonition ol { 190 | margin-bottom: 5px; 191 | } 192 | 193 | div.note { 194 | background-color: #eee; 195 | border: 1px solid #ccc; 196 | } 197 | 198 | div.seealso { 199 | background-color: #ffc; 200 | border: 1px solid #ff6; 201 | } 202 | 203 | div.topic { 204 | background-color: #eee; 205 | } 206 | 207 | div.warning { 208 | background-color: #ffe4e4; 209 | border: 1px solid #f66; 210 | } 211 | 212 | p.admonition-title { 213 | display: inline; 214 | } 215 | 216 | p.admonition-title:after { 217 | content: ":"; 218 | } 219 | 220 | pre { 221 | padding: 5px; 222 | background-color: #eeffcc; 223 | color: #333333; 224 | line-height: 120%; 225 | border: 1px solid #ac9; 226 | border-left: none; 227 | border-right: none; 228 | } 229 | 230 | tt { 231 | background-color: #ecf0f3; 232 | padding: 0 1px 0 1px; 233 | font-size: 0.95em; 234 | } 235 | 236 | th { 237 | background-color: #ede; 238 | } 239 | 240 | .warning tt { 241 | background: #efc2c2; 242 | } 243 | 244 | .note tt { 245 | background: #d6d6d6; 246 | } 247 | 248 | .viewcode-back { 249 | font-family: sans-serif; 250 | } 251 | 252 | div.viewcode-block:target { 253 | background-color: #f4debf; 254 | border-top: 1px solid #ac9; 255 | border-bottom: 1px solid #ac9; 256 | } -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | } 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * small function to check if an array contains 66 | * a given item. 67 | */ 68 | jQuery.contains = function(arr, item) { 69 | for (var i = 0; i < arr.length; i++) { 70 | if (arr[i] == item) 71 | return true; 72 | } 73 | return false; 74 | }; 75 | 76 | /** 77 | * highlight a given string on a jquery object by wrapping it in 78 | * span elements with the given class name. 79 | */ 80 | jQuery.fn.highlightText = function(text, className) { 81 | function highlight(node) { 82 | if (node.nodeType == 3) { 83 | var val = node.nodeValue; 84 | var pos = val.toLowerCase().indexOf(text); 85 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 86 | var span = document.createElement("span"); 87 | span.className = className; 88 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 89 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 90 | document.createTextNode(val.substr(pos + text.length)), 91 | node.nextSibling)); 92 | node.nodeValue = val.substr(0, pos); 93 | } 94 | } 95 | else if (!jQuery(node).is("button, select, textarea")) { 96 | jQuery.each(node.childNodes, function() { 97 | highlight(this); 98 | }); 99 | } 100 | } 101 | return this.each(function() { 102 | highlight(this); 103 | }); 104 | }; 105 | 106 | /** 107 | * Small JavaScript module for the documentation. 108 | */ 109 | var Documentation = { 110 | 111 | init : function() { 112 | this.fixFirefoxAnchorBug(); 113 | this.highlightSearchWords(); 114 | this.initIndexTable(); 115 | }, 116 | 117 | /** 118 | * i18n support 119 | */ 120 | TRANSLATIONS : {}, 121 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 122 | LOCALE : 'unknown', 123 | 124 | // gettext and ngettext don't access this so that the functions 125 | // can safely bound to a different name (_ = Documentation.gettext) 126 | gettext : function(string) { 127 | var translated = Documentation.TRANSLATIONS[string]; 128 | if (typeof translated == 'undefined') 129 | return string; 130 | return (typeof translated == 'string') ? translated : translated[0]; 131 | }, 132 | 133 | ngettext : function(singular, plural, n) { 134 | var translated = Documentation.TRANSLATIONS[singular]; 135 | if (typeof translated == 'undefined') 136 | return (n == 1) ? singular : plural; 137 | return translated[Documentation.PLURALEXPR(n)]; 138 | }, 139 | 140 | addTranslations : function(catalog) { 141 | for (var key in catalog.messages) 142 | this.TRANSLATIONS[key] = catalog.messages[key]; 143 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 144 | this.LOCALE = catalog.locale; 145 | }, 146 | 147 | /** 148 | * add context elements like header anchor links 149 | */ 150 | addContextElements : function() { 151 | $('div[id] > :header:first').each(function() { 152 | $('\u00B6'). 153 | attr('href', '#' + this.id). 154 | attr('title', _('Permalink to this headline')). 155 | appendTo(this); 156 | }); 157 | $('dt[id]').each(function() { 158 | $('\u00B6'). 159 | attr('href', '#' + this.id). 160 | attr('title', _('Permalink to this definition')). 161 | appendTo(this); 162 | }); 163 | }, 164 | 165 | /** 166 | * workaround a firefox stupidity 167 | */ 168 | fixFirefoxAnchorBug : function() { 169 | if (document.location.hash && $.browser.mozilla) 170 | window.setTimeout(function() { 171 | document.location.href += ''; 172 | }, 10); 173 | }, 174 | 175 | /** 176 | * highlight the search words provided in the url in the text 177 | */ 178 | highlightSearchWords : function() { 179 | var params = $.getQueryParameters(); 180 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 181 | if (terms.length) { 182 | var body = $('div.body'); 183 | window.setTimeout(function() { 184 | $.each(terms, function() { 185 | body.highlightText(this.toLowerCase(), 'highlighted'); 186 | }); 187 | }, 10); 188 | $('') 190 | .appendTo($('#searchbox')); 191 | } 192 | }, 193 | 194 | /** 195 | * init the domain index toggle buttons 196 | */ 197 | initIndexTable : function() { 198 | var togglers = $('img.toggler').click(function() { 199 | var src = $(this).attr('src'); 200 | var idnum = $(this).attr('id').substr(7); 201 | $('tr.cg-' + idnum).toggle(); 202 | if (src.substr(-9) == 'minus.png') 203 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 204 | else 205 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 206 | }).css('display', ''); 207 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 208 | togglers.click(); 209 | } 210 | }, 211 | 212 | /** 213 | * helper function to hide the search marks again 214 | */ 215 | hideSearchWords : function() { 216 | $('#searchbox .highlight-link').fadeOut(300); 217 | $('span.highlighted').removeClass('highlighted'); 218 | }, 219 | 220 | /** 221 | * make the url absolute 222 | */ 223 | makeURL : function(relativeURL) { 224 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 225 | }, 226 | 227 | /** 228 | * get the current relative url 229 | */ 230 | getCurrentURL : function() { 231 | var path = document.location.pathname; 232 | var parts = path.split(/\//); 233 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 234 | if (this == '..') 235 | parts.pop(); 236 | }); 237 | var url = parts.join('/'); 238 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 239 | } 240 | }; 241 | 242 | // quick alias for translations 243 | _ = Documentation.gettext; 244 | 245 | $(document).ready(function() { 246 | Documentation.init(); 247 | }); 248 | -------------------------------------------------------------------------------- /docs/_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/down.png -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 8 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 9 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 10 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 11 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 12 | .highlight .ge { font-style: italic } /* Generic.Emph */ 13 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 14 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 15 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 16 | .highlight .go { color: #333333 } /* Generic.Output */ 17 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 18 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 19 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 20 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 21 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 22 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 23 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 24 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 25 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 26 | .highlight .kt { color: #902000 } /* Keyword.Type */ 27 | .highlight .m { color: #208050 } /* Literal.Number */ 28 | .highlight .s { color: #4070a0 } /* Literal.String */ 29 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 30 | .highlight .nb { color: #007020 } /* Name.Builtin */ 31 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 32 | .highlight .no { color: #60add5 } /* Name.Constant */ 33 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 34 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 35 | .highlight .ne { color: #007020 } /* Name.Exception */ 36 | .highlight .nf { color: #06287e } /* Name.Function */ 37 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 38 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 39 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 40 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 41 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 42 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 43 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 44 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 45 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 46 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 47 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 48 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 49 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 50 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 51 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 52 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 53 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 54 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 55 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 56 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 57 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 58 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 59 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 60 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 61 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 62 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/_build/html/_static/sidebar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * sidebar.js 3 | * ~~~~~~~~~~ 4 | * 5 | * This script makes the Sphinx sidebar collapsible. 6 | * 7 | * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds 8 | * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton 9 | * used to collapse and expand the sidebar. 10 | * 11 | * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden 12 | * and the width of the sidebar and the margin-left of the document 13 | * are decreased. When the sidebar is expanded the opposite happens. 14 | * This script saves a per-browser/per-session cookie used to 15 | * remember the position of the sidebar among the pages. 16 | * Once the browser is closed the cookie is deleted and the position 17 | * reset to the default (expanded). 18 | * 19 | * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 20 | * :license: BSD, see LICENSE for details. 21 | * 22 | */ 23 | 24 | $(function() { 25 | // global elements used by the functions. 26 | // the 'sidebarbutton' element is defined as global after its 27 | // creation, in the add_sidebar_button function 28 | var bodywrapper = $('.bodywrapper'); 29 | var sidebar = $('.sphinxsidebar'); 30 | var sidebarwrapper = $('.sphinxsidebarwrapper'); 31 | 32 | // for some reason, the document has no sidebar; do not run into errors 33 | if (!sidebar.length) return; 34 | 35 | // original margin-left of the bodywrapper and width of the sidebar 36 | // with the sidebar expanded 37 | var bw_margin_expanded = bodywrapper.css('margin-left'); 38 | var ssb_width_expanded = sidebar.width(); 39 | 40 | // margin-left of the bodywrapper and width of the sidebar 41 | // with the sidebar collapsed 42 | var bw_margin_collapsed = '.8em'; 43 | var ssb_width_collapsed = '.8em'; 44 | 45 | // colors used by the current theme 46 | var dark_color = $('.related').css('background-color'); 47 | var light_color = $('.document').css('background-color'); 48 | 49 | function sidebar_is_collapsed() { 50 | return sidebarwrapper.is(':not(:visible)'); 51 | } 52 | 53 | function toggle_sidebar() { 54 | if (sidebar_is_collapsed()) 55 | expand_sidebar(); 56 | else 57 | collapse_sidebar(); 58 | } 59 | 60 | function collapse_sidebar() { 61 | sidebarwrapper.hide(); 62 | sidebar.css('width', ssb_width_collapsed); 63 | bodywrapper.css('margin-left', bw_margin_collapsed); 64 | sidebarbutton.css({ 65 | 'margin-left': '0', 66 | 'height': bodywrapper.height() 67 | }); 68 | sidebarbutton.find('span').text('»'); 69 | sidebarbutton.attr('title', _('Expand sidebar')); 70 | document.cookie = 'sidebar=collapsed'; 71 | } 72 | 73 | function expand_sidebar() { 74 | bodywrapper.css('margin-left', bw_margin_expanded); 75 | sidebar.css('width', ssb_width_expanded); 76 | sidebarwrapper.show(); 77 | sidebarbutton.css({ 78 | 'margin-left': ssb_width_expanded-12, 79 | 'height': bodywrapper.height() 80 | }); 81 | sidebarbutton.find('span').text('«'); 82 | sidebarbutton.attr('title', _('Collapse sidebar')); 83 | document.cookie = 'sidebar=expanded'; 84 | } 85 | 86 | function add_sidebar_button() { 87 | sidebarwrapper.css({ 88 | 'float': 'left', 89 | 'margin-right': '0', 90 | 'width': ssb_width_expanded - 28 91 | }); 92 | // create the button 93 | sidebar.append( 94 | '
«
' 95 | ); 96 | var sidebarbutton = $('#sidebarbutton'); 97 | light_color = sidebarbutton.css('background-color'); 98 | // find the height of the viewport to center the '<<' in the page 99 | var viewport_height; 100 | if (window.innerHeight) 101 | viewport_height = window.innerHeight; 102 | else 103 | viewport_height = $(window).height(); 104 | sidebarbutton.find('span').css({ 105 | 'display': 'block', 106 | 'margin-top': (viewport_height - sidebar.position().top - 20) / 2 107 | }); 108 | 109 | sidebarbutton.click(toggle_sidebar); 110 | sidebarbutton.attr('title', _('Collapse sidebar')); 111 | sidebarbutton.css({ 112 | 'color': '#FFFFFF', 113 | 'border-left': '1px solid ' + dark_color, 114 | 'font-size': '1.2em', 115 | 'cursor': 'pointer', 116 | 'height': bodywrapper.height(), 117 | 'padding-top': '1px', 118 | 'margin-left': ssb_width_expanded - 12 119 | }); 120 | 121 | sidebarbutton.hover( 122 | function () { 123 | $(this).css('background-color', dark_color); 124 | }, 125 | function () { 126 | $(this).css('background-color', light_color); 127 | } 128 | ); 129 | } 130 | 131 | function set_position_from_cookie() { 132 | if (!document.cookie) 133 | return; 134 | var items = document.cookie.split(';'); 135 | for(var k=0; k=e.computed&&(e={value:f,computed:g})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);var e={computed:Infinity};b.each(a,function(f,g,h){g=c?c.call(d,f,g,h):f;gf?1:0}),"value")};b.sortedIndex=function(a,c,d){d=d||b.identity;for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.zip=function(){for(var a=b.toArray(arguments),c=b.max(b.pluck(a,"length")),d=new Array(c),e=0;e0?f-c:c-f)>=0)return e;e[g++]=f}};b.bind=function(a,c){var d=b.rest(arguments,2);return function(){return a.apply(c||j,d.concat(b.toArray(arguments)))}};b.bindAll=function(a){var c=b.rest(arguments);if(c.length==0)c=b.functions(a);b.each(c,function(d){a[d]=b.bind(a[d],a)}); 17 | return a};b.delay=function(a,c){var d=b.rest(arguments,2);return setTimeout(function(){return a.apply(a,d)},c)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(b.rest(arguments)))};b.wrap=function(a,c){return function(){var d=[a].concat(b.toArray(arguments));return c.apply(c,d)}};b.compose=function(){var a=b.toArray(arguments);return function(){for(var c=b.toArray(arguments),d=a.length-1;d>=0;d--)c=[a[d].apply(this,c)];return c[0]}};b.keys=function(a){if(b.isArray(a))return b.range(0,a.length); 18 | var c=[];for(var d in a)q.call(a,d)&&c.push(d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=function(a){return b.select(b.keys(a),function(c){return b.isFunction(a[c])}).sort()};b.extend=function(a,c){for(var d in c)a[d]=c[d];return a};b.clone=function(a){if(b.isArray(a))return a.slice(0);return b.extend({},a)};b.tap=function(a,c){c(a);return a};b.isEqual=function(a,c){if(a===c)return true;var d=typeof a;if(d!=typeof c)return false;if(a==c)return true;if(!a&&c||a&&!c)return false; 19 | if(a.isEqual)return a.isEqual(c);if(b.isDate(a)&&b.isDate(c))return a.getTime()===c.getTime();if(b.isNaN(a)&&b.isNaN(c))return true;if(b.isRegExp(a)&&b.isRegExp(c))return a.source===c.source&&a.global===c.global&&a.ignoreCase===c.ignoreCase&&a.multiline===c.multiline;if(d!=="object")return false;if(a.length&&a.length!==c.length)return false;d=b.keys(a);var e=b.keys(c);if(d.length!=e.length)return false;for(var f in a)if(!b.isEqual(a[f],c[f]))return false;return true};b.isEmpty=function(a){return b.keys(a).length== 20 | 0};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=function(a){return!!(a&&a.concat&&a.unshift)};b.isArguments=function(a){return a&&b.isNumber(a.length)&&!b.isArray(a)&&!r.call(a,"length")};b.isFunction=function(a){return!!(a&&a.constructor&&a.call&&a.apply)};b.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)};b.isNumber=function(a){return p.call(a)==="[object Number]"};b.isDate=function(a){return!!(a&&a.getTimezoneOffset&&a.setUTCFullYear)};b.isRegExp=function(a){return!!(a&& 21 | a.test&&a.exec&&(a.ignoreCase||a.ignoreCase===false))};b.isNaN=function(a){return b.isNumber(a)&&isNaN(a)};b.isNull=function(a){return a===null};b.isUndefined=function(a){return typeof a=="undefined"};b.noConflict=function(){j._=n;return this};b.identity=function(a){return a};b.breakLoop=function(){throw m;};var s=0;b.uniqueId=function(a){var c=s++;return a?a+c:c};b.template=function(a,c){a=new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+a.replace(/[\r\t\n]/g, 22 | " ").replace(/'(?=[^%]*%>)/g,"\t").split("'").join("\\'").split("\t").join("'").replace(/<%=(.+?)%>/g,"',$1,'").split("<%").join("');").split("%>").join("p.push('")+"');}return p.join('');");return c?a(c):a};b.forEach=b.each;b.foldl=b.inject=b.reduce;b.foldr=b.reduceRight;b.filter=b.select;b.every=b.all;b.some=b.any;b.head=b.first;b.tail=b.rest;b.methods=b.functions;var l=function(a,c){return c?b(a).chain():a};b.each(b.functions(b),function(a){var c=b[a];i.prototype[a]=function(){var d=b.toArray(arguments); 23 | o.call(d,this._wrapped);return l(c.apply(b,d),this._chain)}});b.each(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){c.apply(this._wrapped,arguments);return l(this._wrapped,this._chain)}});b.each(["concat","join","slice"],function(a){var c=Array.prototype[a];i.prototype[a]=function(){return l(c.apply(this._wrapped,arguments),this._chain)}});i.prototype.chain=function(){this._chain=true;return this};i.prototype.value=function(){return this._wrapped}})(); 24 | -------------------------------------------------------------------------------- /docs/_build/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/_static/up.png -------------------------------------------------------------------------------- /docs/_build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Index — classjs 1.0 documentation 14 | 15 | 16 | 17 | 18 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 42 | 43 |
44 |
45 |
46 |
47 | 48 | 49 |

Index

50 | 51 |
52 | 53 |
54 | 55 | 56 |
57 |
58 |
59 |
60 |
61 | 62 | 63 | 64 | 76 | 77 |
78 |
79 |
80 |
81 | 90 | 94 | 95 | -------------------------------------------------------------------------------- /docs/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Welcome — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 44 | 45 |
46 |
47 |
48 |
49 | 50 |
51 |

Welcome

52 |

class.js is a JavaScript library for building class based object-oriented programs using 53 | JavaScript’s prototypal inheritance. class.js strives to mimic classical class inheritance 54 | provided by other languages such as Python, Java or C. Its syntax is heavily inspired 55 | by MooTools class implementation.

56 |

The latest stable version is 1.0 - https://github.com/finalangel/classjs

57 |
58 |
59 |

Introduction

60 |
61 | 66 |
67 |
68 | 92 |
93 |

Contributing

94 |
95 | 109 |
110 |
111 | 112 | 113 |
114 |
115 |
116 |
117 |
118 |

Table Of Contents

119 | 131 | 132 |

Next topic

133 |

Why class.js

135 |

This Page

136 | 140 | 152 | 153 |
154 |
155 |
156 |
157 | 169 | 173 | 174 | -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FinalAngel/classjs/f7eaa511284d2f343f0d614024ae8b071960efbb/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Search — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 46 | 47 |
48 |
49 |
50 |
51 | 52 |

Search

53 |
54 | 55 |

56 | Please activate JavaScript to enable the search 57 | functionality. 58 |

59 |
60 |

61 | From here you can search these documents. Enter your search 62 | words into the box below and click "search". Note that the search 63 | function will automatically search for all of the words. Pages 64 | containing fewer words won't appear in the result list. 65 |

66 |
67 | 68 | 69 | 70 |
71 | 72 |
73 | 74 |
75 | 76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | 94 | 98 | 99 | -------------------------------------------------------------------------------- /docs/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({objects:{},terms:{all:[0,6,2],concept:2,chain:4,global:0,prefix:0,code:[0,7,6,2,8],follow:[0,3,4,5,6,7],depend:0,send:6,program:1,under:0,withdata:7,worth:0,sourc:[8,6],string:4,fals:[4,5],fan:2,veri:6,untouch:2,ticket:6,level:0,did:2,die:4,list:[0,1,3],adjust:7,mammal:[4,5],pleas:[7,6,3],prevent:4,direct:5,second:2,pass:[0,4,5],download:[0,8],compat:7,what:4,section:4,abl:[8,2],invok:5,current:4,version:[0,1,7,4,8],"new":[0,1,5,7,4],method:[4,1,5],here:0,closur:0,modular:2,let:0,path:8,modifi:4,misinterpret:2,amount:0,implement:[1,2,4,5,7,8],shorthand:0,transit:7,prefer:[0,8],api:1,establish:0,angelo:[0,3],from:[7,4,5,2],describ:0,would:0,commun:6,two:5,subvers:0,websit:0,few:2,live:6,call:[5,8],type:8,more:[7,2],comparison:7,sora:[4,5],effort:3,must:0,fly:[4,5],none:2,alik:0,restor:4,prepar:[4,5],work:[5,2],cat:[4,5],can:[0,4,5],learn:2,purpos:0,want:[0,5],process:0,high:0,explor:8,alwai:6,multipl:4,divio:7,write:0,how:[7,1,8,6],reject:6,xhtml:8,updat:[7,1,2],product:8,clone:4,after:2,usabl:2,befor:4,wrong:2,end:2,grow:2,demonstr:0,github:[0,1,6],classj:[0,1,6],practic:6,classi:[7,4],assign:[4,5],issu:[6,2],inform:[0,6],maintain:[0,2],environ:0,allow:0,offend:6,over:4,top:0,through:[0,4,5,6],myanim:4,style:[0,2],thank:3,fix:6,better:4,window:[0,4],therefor:7,might:[0,5],easier:6,them:4,good:6,"return":[0,4,5],python:1,initi:[0,1,4,5,7,8],"break":4,framework:2,jsfiddl:6,modififi:4,now:[4,5],nor:4,strive:1,choic:0,name:[0,4,5],changelog:7,separ:0,easili:[0,2],each:[4,5],hard:2,year:5,orient:1,special:7,variabl:0,open:6,aculo:2,adapt:[7,2],dive:[4,5],ass:0,given:4,free:8,reason:[6,2],base:1,releas:7,could:6,keep:0,principl:2,confus:2,imposs:2,first:[0,5],feel:[8,6],onc:4,arrai:[7,1,5,4],qualiti:0,dini:[0,3],microsit:0,alreadi:0,stabl:1,miss:2,differ:0,convent:0,script:[0,8,2],licens:0,system:0,messag:6,myplugin:0,attach:[4,5],carousel:[0,3],includ:[0,6],consol:8,option:[0,1,5,4],especi:2,namespac:0,copi:4,consult:[7,4],than:2,serv:5,grew:2,whenev:6,provid:[0,1,7,4,6],remov:4,structur:[5,2],project:6,browser:8,fork:6,ani:[0,7,2],have:0,need:[0,7],dedic:0,"null":[4,5],techniqu:0,note:[4,6],also:[0,2],exampl:[0,4,5],take:2,which:[0,2],combin:0,insur:0,distribut:0,normal:[4,5],oject:5,object:[4,1,5],beta:7,bsd:0,"class":[0,1,2,4,5,6,7,8],amaz:3,how_to:3,bug:6,gather:4,cover:7,doe:[4,6],latest:1,came:2,text:8,syntax:1,find:2,access:4,copyright:0,should:2,satan:5,offici:7,overwritten:4,contribut:[1,6],variou:0,get:4,cannot:4,requir:[0,7,2],enabl:2,bird:[4,5],common:0,where:0,set:4,fail:4,reserv:0,whatsoev:0,jqueri:[0,5,2],parent:[7,1,5,4],correctli:8,enough:6,"import":0,approach:2,across:2,extend:[0,1,2,4,5,6,7],javascript:[0,1,8,2],entir:0,html5:8,both:[7,5],accident:4,plugin:[0,1,5,3,2],career:2,instanc:[4,5],improv:6,com:[0,1,6],comment:6,finalangel:[0,1,6],simpli:4,point:2,guidelin:[0,6],inspir:1,guid:[7,1,6],java:1,addition:7,been:[4,6],json:5,besid:0,quickli:2,life:6,setopt:[7,1,4],tiger:7,minifi:[0,8],those:0,"case":2,ident:[7,5],look:0,properti:[4,1,5],"while":0,abov:0,almost:2,worri:0,player:2,itself:[0,4],crossrefer:0,fame:2,sever:0,develop:[0,2],welcom:[0,1,6],author:[0,3],receiv:0,make:[6,2],same:5,html:8,split:2,document:[0,6],conflict:4,finish:2,http:[0,1,6],alert:[4,5],user:[0,1,3],extern:0,studi:2,well:0,inherit:[1,2],anim:[7,4,5,2],without:[4,2],thi:[0,1,2,4,5,7],choos:0,undefin:4,roughli:2,propos:6,explan:4,load:4,just:0,heavili:1,yet:7,languag:[1,2],easi:0,had:2,spread:0,mootool:[4,1,2],introduct:1,build:1,swim:[4,5],big:2,camelcas:0,know:0,like:0,specif:2,either:0,popular:2,page:[0,3],old:[7,5],twitter:0,creation:5,some:0,back:2,dead:[4,5],intern:[7,4],successfulli:0,librari:[4,1,2],lead:2,tracker:6,leav:2,getnam:5,refer:[6,3],core:[0,1,3,2],encourag:0,previou:[4,5],run:4,usag:5,host:6,repositori:0,"super":7,src:8,about:[0,6],obj:7,noconflict:[7,1,4],lightbox:[0,3],constructor:[4,5],commit:6,own:[6,3,2],within:[0,4,5,8,6],chang:[7,4,6,2],your:[0,2,3,6,7,8],merg:[4,5],wai:0,submit:[0,1,6],custom:0,avail:4,start:[6,2],low:0,lot:2,"var":[0,7,5,4],"function":[0,1,5,7,4],link:[0,4],pitschi:4,don:[0,6],"true":5,eat:[4,5],pull:6,possibl:[0,4,6],smooth:7,autocomplet:0,featur:[7,6],creat:[0,1,2,3,5,4],classic:1,certain:2,repres:5,exist:5,file:0,request:6,when:[0,5],detail:7,other:[0,1],test:0,getopt:[7,1,4],you:[0,2,4,5,6,7,8],classyvers:7,why:[1,2],meaning:0,descript:0,mimic:1,understand:2,prototyp:[4,1,2]},objtypes:{},titles:["Plugins","Welcome","Why class.js","List of plugins","methods","properties","Contribution guide","How to update","How to implement"],objnames:{},filenames:["src/contributing/plugins","index","src/introduction/why_classjs","src/contributing/plugins_list","src/class_api/methods","src/class_api/properties","src/contributing/guide","src/introduction/how_to_update","src/introduction/how_to_implement"]}) -------------------------------------------------------------------------------- /docs/_build/html/src/class_api/properties.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | properties — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

properties

56 |

The following properties can be used within the Classes passing object.

57 |
58 |

initialize: function

59 |

(returns constructor) - The initialize function serves as constructor on instance creation.

60 |

Create a new Class:

61 |
var Animal = new Class({
 62 |     initialize: function(name, age) {
 63 |         this.name = name;
 64 |         this.age = age;
 65 |     }
 66 | });
 67 | 
 68 |     // the passing options will be passed through the constructor initialize
 69 | new Animal('Satan', 21);
 70 | 
71 |
72 |
73 |
74 |

implement: array

75 |

(returns object) - Each object or class within the array will be added to the assigned class.

76 |

Implementing new methods:

77 |
// preparing a class
 78 | var Mammal = new Class({
 79 |     swim: function () {
 80 |         alert(this.name + ' can swim now.');
 81 |     },
 82 |     dive: function () {
 83 |         alert(this.name + ' can dive now.');
 84 |     }
 85 | });
 86 | 
 87 | // preparing a normal object
 88 | var Bird = {
 89 |     fly: function () {
 90 |         alert(this.name + ' can fly now.');
 91 |     }
 92 | };
 93 | 
 94 | var Animal = new Class({
 95 |     implement: [Mammal, Bird],
 96 |     initialize: function (name, age) {
 97 |         this.name = name;
 98 |         this.age = age;
 99 |     },
100 |     eat: function () {
101 |         alert(this.name + ' is eating now.');
102 |     }
103 | });
104 | 
105 | var cat = new Animal('Sora', 4);
106 |     cat.swim(); // alerts "Sora can swim now."
107 |     cat.dive(); // alerts "Sora can dive now."
108 |     cat.fly(); // alerts "Sora can fly now."
109 | 
110 |
111 |

This property works identical to the Class.implement method.

112 |
113 |
114 |

options: object

115 |

(returns object) - The options object represents a JSON structure.

116 |

Attach options to a Class:

117 |
var Animal = new Class({
118 |     options: {
119 |         'name': '',
120 |         'age': null,
121 |         'dead': false
122 |     },
123 |     initialize: function (options) {
124 |         // merging objects using jQuery
125 |         this.options = options;
126 | 
127 |         // you might want to merge the two ojects using jQuery
128 |         // this.options = jQuery.extend(true, {}, this.options, options)
129 |     }
130 | });
131 | 
132 | var cat = new Animal({
133 |     'name': 'Sora',
134 |     'age': 4
135 | });
136 | 
137 |     // call options direct
138 |     alert(cat.options.name); // alerts 'Sora'
139 | 
140 |
141 |
142 |
143 |

this.parent()

144 |

(returns function) - When called from within a class.js function this invokes the parent function of the same name. 145 | This is useful when extending an existing class.js plugin.

146 |

Example usage of parent:

147 |
var Animal = new Class({
148 |     initialize: function (name, age) {
149 |             this.name = name;
150 |             this.age = age;
151 |     },
152 |     getName: function () {
153 |             alert(this.name + ' is eating now.');
154 |     }
155 | });
156 | 
157 | Animal.extend({
158 |     getName: function () {
159 |             // calls previous getName first
160 |             this.parent();
161 |             alert(this.name + ' is ' +  this.age + ' years old.');
162 |     }
163 | });
164 | 
165 | var cat = new Animal('Sora', 4);
166 |     cat.getName(); // alerts both calls, name and age
167 | 
168 |
169 |
170 |
171 | 172 | 173 |
174 |
175 |
176 |
177 |
178 |

Table Of Contents

179 | 188 | 189 |

Previous topic

190 |

methods

192 |

Next topic

193 |

Contribution guide

195 |

This Page

196 | 200 | 212 | 213 |
214 |
215 |
216 |
217 | 232 | 236 | 237 | -------------------------------------------------------------------------------- /docs/_build/html/src/contributing/guide.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Contribution guide — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

Contribution guide

56 |

All open-source projects live through their community, so does class.js. You are very welcome to contribute 57 | bug fixes and feature proposals. Please note the following guidelines:

58 |
    59 |
  • class.js is hosted on github: http://github.com/FinalAngel/classjs
  • 60 |
  • Use github’s issues tracker to submit bug fixes or feature proposals
  • 61 |
  • Whenever possible include a jsfiddle to an issue.
  • 62 |
  • It is good practice to fork a project and make your changes through your own fork.
  • 63 |
  • Always send a pull request with a reference to the github ticket.
  • 64 |
  • Include enough information within your commit messages and pull request to make life easier for us.
  • 65 |
66 |

Don’t feel offended if a pull or feature request has been rejected. We always provide reasonable comments 67 | or information’s about how your code could be improved.

68 |

Start by fixing or extending the documentation ;)

69 |
70 | 71 | 72 |
73 |
74 |
75 |
76 |
77 |

Previous topic

78 |

properties

80 |

Next topic

81 |

Plugins

83 |

This Page

84 | 88 | 100 | 101 |
102 |
103 |
104 |
105 | 120 | 124 | 125 | -------------------------------------------------------------------------------- /docs/_build/html/src/contributing/plugins.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Plugins — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

Plugins

56 |

Creating and extending plugins is the entire purpose of class.js. 57 | To encourage users to write and extend plugins, we need to establish some common guidelines.

58 |
59 |

Creating a plugin

60 |

First of all, create a JavaScript file and include the following information within the top of your script:

61 |
    62 |
  • the authors name
  • 63 |
  • the plugins version
  • 64 |
  • the plugins license
  • 65 |
  • the plugins dependencies
  • 66 |
67 |

For example:

68 |
/**
 69 |  * @author      Angelo Dini
 70 |  * @version     1.0
 71 |  * @copyright   Distributed under the BSD License.
 72 |  * @requires    class.js, jQuery
 73 |  */
 74 | 
75 |
76 |

You can include the information at any style of your choice whatsoever. 77 | Just insure that you include the required information within the development and minified versions alike.

78 |
79 |

Creating a namespace is important to keep the amount of global variables as low as possible.

80 |

I prefere to use Cl as the shorthand for Cl ass:

81 |
var Cl = window.Cl || {};
 82 | 
83 |
84 |

You are welcome to use this namespace as well. You might want to crossreference the core plugins 85 | for already reservated names like Cl.Lightbox or Cl.Carousel.

86 |
87 |

Creating a closure allows you to create an environment where you don’t have to worry about other 88 | plugins namespaces. class.js uses this system by itself:

89 |
(function(){
 90 |     // your code here
 91 | })();
 92 | 
 93 | // you might want to pass some custom variables
 94 | (function($){
 95 |     // your code here
 96 | })(jQuery);
 97 | 
98 |
99 |
100 |

When choosing names be descriptive and use CamelCase for naming conventions:

101 |
Cl.MyPlugin = new Class({
102 |     initialize: function () {
103 |         return 'My first plugin';
104 |     }
105 | });
106 | 
107 |
108 |
109 |

If we combine those techniques your plugin would look like this:

110 |
/**
111 |  * @author      Angelo Dini, Distributed under the BSD License.
112 |  * @version     1.0
113 |  * @requires    class.js, jQuery
114 |  */
115 | (function(){
116 |     Cl.MyPlugin = new Class({
117 |         initialize: function () {
118 |             return 'My first plugin';
119 |         }
120 |     });
121 | })();
122 | 
123 |
124 |
125 |
126 |

Submitting a plugin

127 |

If you successfully created a plugin worth spreading let us know https://twitter.com/finalangel and we will 128 | include it within the plugins list. We just require the a website or download link.

129 |
130 |
131 |

Core plugins

132 |

Besides the above described plugins we maintain several core plugins like Cl.Lightbox or 133 | Cl.Carousel. Those core plugins differ in various ways:

134 |

A core plugin requires tests and documentation preferable within the repository itself, 135 | with the option of external documentation. This allows for an easy development process and 136 | insures a high level of quality. Those plugins receive a reserved namespace like 137 | Cl.AutoComplete and will be listed separately.

138 |

It is also a must to provide an example page in which the functionality of the plugin can 139 | be demonstrated. Either through using github or a dedicated microsite.

140 |

You are encouraged to use classjs as a name prefix when using a subversion system. For 141 | example classjs-lightbox or classjs-autocomplete.

142 |

Your plugin also needs to be easily extendable while providing meaningful options.

143 |
144 |
145 | 146 | 147 |
148 |
149 |
150 |
151 |
152 |

Table Of Contents

153 | 161 | 162 |

Previous topic

163 |

Contribution guide

165 |

Next topic

166 |

List of plugins

168 |

This Page

169 | 173 | 185 | 186 |
187 |
188 |
189 |
190 | 205 | 209 | 210 | -------------------------------------------------------------------------------- /docs/_build/html/src/contributing/plugins_list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | List of plugins — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 44 | 45 |
46 |
47 |
48 |
49 | 50 |
51 |

List of plugins

52 |

Thanks for the following authors for their amazing plugins and effort:

53 |
54 |

Core plugins

55 | 59 |
60 |
61 |

User plugins

62 |
    63 |
  • 64 |
65 |

Please refer to the how_to page for creating your own plugin.

66 |
67 |
68 | 69 | 70 |
71 |
72 |
73 |
74 |
75 |

Table Of Contents

76 | 83 | 84 |

Previous topic

85 |

Plugins

87 |

This Page

88 | 92 | 104 | 105 |
106 |
107 |
108 |
109 | 121 | 125 | 126 | -------------------------------------------------------------------------------- /docs/_build/html/src/introduction/how_to_implement.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | How to implement — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

How to implement

56 |

Download the production version of class.js (minified) and implement it in your html code.

57 |

For HTML5 use:

58 |
<script src="/path/class.js"></script>
59 |
60 |

For HTML and XHTML versions use:

61 |
<script type="text/javascript" src="/path/class.js"></script>
62 |
63 |

You will be able to call Class.version within your preferred browsers console 64 | if class.js is implemented or initialized correctly. Feel free to explore the source.

65 |
66 | 67 | 68 |
69 |
70 |
71 |
72 |
73 |

Previous topic

74 |

Why class.js

76 |

Next topic

77 |

How to update

79 |

This Page

80 | 84 | 96 | 97 |
98 |
99 |
100 |
101 | 116 | 120 | 121 | -------------------------------------------------------------------------------- /docs/_build/html/src/introduction/how_to_update.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | How to update — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

How to update

56 |
57 |

Update from Beta to 1.0

58 |

There are no special adjustments required for this version. 59 | Beta releases will not be covered by any adaptation. 60 | Therefore consult the Changelog for more details.

61 |
62 |
63 |

Update from classy.js to class.js

64 |

There is not yet an official adapter from classy.js (Divio internal version) to class.js. 65 | You need to change your code to be compatible with class.js. Please follow this guide for a smooth transition:

66 |

Comparison from old to new:

67 |
var Animal = Class.$extend(obj); // old
 68 | var Animal = new Class(obj); // new
 69 | 
 70 | var Tiger = Animal.$extend(obj); // old
 71 | var Tiger = Animal.extend(obj); // new
 72 | 
 73 | Class.$classyVersion; // old
 74 | Class.version; // new
 75 | 
 76 | Class.$withData(obj); // old
 77 | Class.setOptions(obj); // new
 78 | 
 79 | Class.$noConflict(); // old
 80 | Class.noConflict(); // new
 81 | 
 82 | this.$super(); // old
 83 | this.parent(); // new
 84 | 
 85 | initialize: function () {} // identical in both versions
 86 | 
 87 | implement: [array] // identical in both version
 88 | 
89 |
90 |

Additionally class.js provides the following features:

91 |
Class.getOptions();
 92 | Class.implement([array]);
 93 | 
94 |
95 |
96 |
97 | 98 | 99 |
100 |
101 |
102 |
103 |
104 |

Table Of Contents

105 | 112 | 113 |

Previous topic

114 |

How to implement

116 |

Next topic

117 |

methods

119 |

This Page

120 | 124 | 136 | 137 |
138 |
139 |
140 |
141 | 156 | 160 | 161 | -------------------------------------------------------------------------------- /docs/_build/html/src/introduction/why_classjs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Why class.js — classjs 1.0 documentation 12 | 13 | 14 | 15 | 16 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 |

Why class.js

56 |

I started learning JavaScript roughly in 2002 without the use of any framework. 57 | Back than Prototype was the big player and I did not understand its concept. 58 | I also had issues with Prototype’s none-modular approach splitting animation 59 | (script-aculo-us) from the core library.

60 |

After I finishing my study I came across MooTools and quickly adapted my code to 61 | a more modular and re-usable style. At a certain point of my career the requirements 62 | for use of jQuery grew. jQuery’s popularity grow and we had to adapt.

63 |

I am not a big fan of jQuery, especially jQuery’s UI approach. It is missing any 64 | modular structure and is almost impossible to extend. The fame of jQuery makes it 65 | hard to find a plugin for your case. If you end up finding one you end up changing 66 | the code to work for your specific case. This is wrong. I should be able to take 67 | the plugin and extend it, leaving the code untouched. This enables me to easily 68 | update and maintain the plugin without re-implementing your own changes.

69 |

There is also a second reason. A lot of developers do not understand the principles 70 | of prototypal inheritance. All in all JavaScript is one of the few popular languages 71 | which adapts this concept. This is confusing and leads to misinterpretation.

72 |

This is why I created class.js.

73 |
74 | 75 | 76 |
77 |
78 |
79 |
80 |
81 |

Previous topic

82 |

Welcome

84 |

Next topic

85 |

How to implement

87 |

This Page

88 | 92 | 104 | 105 |
106 |
107 |
108 |
109 | 124 | 128 | 129 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # classjs documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Apr 3 09:48:09 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = [] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'classjs' 44 | copyright = u'2012, Angelo Dini' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '1.0' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '1.0' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | #language = None 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build', 'html'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | highlight_language = 'javascript' 87 | 88 | # A list of ignored prefixes for module index sorting. 89 | #modindex_common_prefix = [] 90 | 91 | 92 | # -- Options for HTML output --------------------------------------------------- 93 | 94 | # The theme to use for HTML and HTML Help pages. See the documentation for 95 | # a list of builtin themes. 96 | html_theme = 'default' 97 | 98 | # Theme options are theme-specific and customize the look and feel of a theme 99 | # further. For a list of options available for each theme, see the 100 | # documentation. 101 | #html_theme_options = {} 102 | 103 | # Add any paths that contain custom themes here, relative to this directory. 104 | #html_theme_path = [] 105 | 106 | # The name for this set of Sphinx documents. If None, it defaults to 107 | # " v documentation". 108 | #html_title = None 109 | 110 | # A shorter title for the navigation bar. Default is the same as html_title. 111 | #html_short_title = None 112 | 113 | # The name of an image file (relative to this directory) to place at the top 114 | # of the sidebar. 115 | #html_logo = None 116 | 117 | # The name of an image file (within the static path) to use as favicon of the 118 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 119 | # pixels large. 120 | #html_favicon = None 121 | 122 | # Add any paths that contain custom static files (such as style sheets) here, 123 | # relative to this directory. They are copied after the builtin static files, 124 | # so a file named "default.css" will overwrite the builtin "default.css". 125 | html_static_path = ['_static'] 126 | 127 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 128 | # using the given strftime format. 129 | #html_last_updated_fmt = '%b %d, %Y' 130 | 131 | # If true, SmartyPants will be used to convert quotes and dashes to 132 | # typographically correct entities. 133 | #html_use_smartypants = True 134 | 135 | # Custom sidebar templates, maps document names to template names. 136 | #html_sidebars = {} 137 | 138 | # Additional templates that should be rendered to pages, maps page names to 139 | # template names. 140 | #html_additional_pages = {} 141 | 142 | # If false, no module index is generated. 143 | #html_domain_indices = True 144 | 145 | # If false, no index is generated. 146 | #html_use_index = True 147 | 148 | # If true, the index is split into individual pages for each letter. 149 | #html_split_index = False 150 | 151 | # If true, links to the reST sources are added to the pages. 152 | #html_show_sourcelink = True 153 | 154 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 155 | #html_show_sphinx = True 156 | 157 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 158 | #html_show_copyright = True 159 | 160 | # If true, an OpenSearch description file will be output, and all pages will 161 | # contain a tag referring to it. The value of this option must be the 162 | # base URL from which the finished HTML is served. 163 | #html_use_opensearch = '' 164 | 165 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 166 | #html_file_suffix = None 167 | 168 | # Output file base name for HTML help builder. 169 | htmlhelp_basename = 'classjsdoc' 170 | 171 | 172 | # -- Options for LaTeX output -------------------------------------------------- 173 | 174 | latex_elements = { 175 | # The paper size ('letterpaper' or 'a4paper'). 176 | #'papersize': 'letterpaper', 177 | 178 | # The font size ('10pt', '11pt' or '12pt'). 179 | #'pointsize': '10pt', 180 | 181 | # Additional stuff for the LaTeX preamble. 182 | #'preamble': '', 183 | } 184 | 185 | # Grouping the document tree into LaTeX files. List of tuples 186 | # (source start file, target name, title, author, documentclass [howto/manual]). 187 | latex_documents = [ 188 | ('index', 'classjs.tex', u'classjs Documentation', 189 | u'Angelo Dini', 'manual'), 190 | ] 191 | 192 | # The name of an image file (relative to this directory) to place at the top of 193 | # the title page. 194 | #latex_logo = None 195 | 196 | # For "manual" documents, if this is true, then toplevel headings are parts, 197 | # not chapters. 198 | #latex_use_parts = False 199 | 200 | # If true, show page references after internal links. 201 | #latex_show_pagerefs = False 202 | 203 | # If true, show URL addresses after external links. 204 | #latex_show_urls = False 205 | 206 | # Documents to append as an appendix to all manuals. 207 | #latex_appendices = [] 208 | 209 | # If false, no module index is generated. 210 | #latex_domain_indices = True 211 | 212 | 213 | # -- Options for manual page output -------------------------------------------- 214 | 215 | # One entry per manual page. List of tuples 216 | # (source start file, name, description, authors, manual section). 217 | man_pages = [ 218 | ('index', 'classjs', u'classjs Documentation', 219 | [u'Angelo Dini'], 1) 220 | ] 221 | 222 | # If true, show URL addresses after external links. 223 | #man_show_urls = False 224 | 225 | 226 | # -- Options for Texinfo output ------------------------------------------------ 227 | 228 | # Grouping the document tree into Texinfo files. List of tuples 229 | # (source start file, target name, title, author, 230 | # dir menu entry, description, category) 231 | texinfo_documents = [ 232 | ('index', 'classjs', u'classjs Documentation', 233 | u'Angelo Dini', 'classjs', 'simple class based inheritance.', 234 | 'Miscellaneous'), 235 | ] 236 | 237 | # Documents to append as an appendix to all manuals. 238 | #texinfo_appendices = [] 239 | 240 | # If false, no module index is generated. 241 | #texinfo_domain_indices = True 242 | 243 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 244 | #texinfo_show_urls = 'footnote' 245 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. classjs documentation master file, created by 2 | sphinx-quickstart on Tue Apr 3 09:48:09 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | 7 | ####### 8 | Welcome 9 | ####### 10 | 11 | Class.js is a JavaScript library for building class based object-oriented programs using 12 | JavaScript's prototypal inheritance. class.js strives to mimic classical class inheritance 13 | provided by other languages such as Python, Java or C. Its syntax is heavily inspired 14 | by MooTools class implementation. 15 | 16 | The latest stable version is |release| - https://github.com/finalangel/classjs 17 | 18 | 19 | ############ 20 | Introduction 21 | ############ 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | 26 | src/introduction/why_classjs.rst 27 | src/introduction/how_to_implement.rst 28 | src/introduction/how_to_update.rst 29 | 30 | 31 | ######### 32 | Class API 33 | ######### 34 | 35 | .. toctree:: 36 | :maxdepth: 2 37 | 38 | src/class_api/methods.rst 39 | src/class_api/properties.rst 40 | 41 | 42 | ############ 43 | Contributing 44 | ############ 45 | 46 | .. toctree:: 47 | :maxdepth: 2 48 | 49 | src/contributing/guide.rst 50 | src/contributing/plugins.rst 51 | src/contributing/plugins_list.rst -------------------------------------------------------------------------------- /docs/src/class_api/methods.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | methods 3 | ******* 4 | 5 | The following methods can be attached to a new class. 6 | 7 | 8 | new Class(object); 9 | ================== 10 | 11 | ``(returns object)`` - This is the class constructor and passes the provided object to the instances prototype. 12 | 13 | Create a new Class:: 14 | 15 | var Animal = new Class({ 16 | initialize: function (name, age) { 17 | this.name = name; 18 | this.age = age; 19 | }, 20 | eat: function () { 21 | alert(this.name + ' is eating now.'); 22 | } 23 | }); 24 | 25 | For a better explanation to ``initialize`` consult the class.js properties section. 26 | 27 | 28 | Class.extend(object) 29 | ==================== 30 | 31 | ``(returns object)`` - The object or class passed through extend will be **merged** with the assigned class following 32 | the previous example. 33 | 34 | Extend the class:: 35 | 36 | Animal.extend({ 37 | die: function () { 38 | alert(this.name + ' died at age ' + this.age); 39 | } 40 | }); 41 | 42 | var cat = new Animal('Sora', 4); 43 | cat.die(); // alerts "Sora died at age 4" 44 | 45 | You can create a new instance and extend it, without modififying the parent class:: 46 | 47 | var MyAnimal = new Class(Animal); 48 | MyAnimal.extend({ 49 | clone: function () { 50 | alert(this.name + ' can clone itself now.'); 51 | } 52 | }); 53 | 54 | // can't clone 55 | var sora = new Animal('Sora', 4); 56 | var pitschy = new MyAnimal('Pitschy', 4); 57 | // sora.clone(); fails 58 | pitschy.clone(); // can clone 59 | 60 | 61 | Class.implement(array) 62 | ====================== 63 | 64 | ``(returns object)`` - Each object or class within the array will be **added** to the assigned class following 65 | the previous example. 66 | 67 | Implementing new methods:: 68 | 69 | // preparing a class 70 | var Mammal = new Class({ 71 | swim: function () { 72 | alert(this.name + ' can swim now.'); 73 | }, 74 | dive: function () { 75 | alert(this.name + ' can dive now.'); 76 | } 77 | }); 78 | 79 | // preparing a normal object 80 | var Bird = { 81 | fly: function () { 82 | alert(this.name + ' can fly now.'); 83 | } 84 | }; 85 | 86 | Animal.implement([Mammal, Bird]); 87 | 88 | var cat = new Animal('Sora', 4); 89 | cat.swim(); // alerts "Sora can swim now." 90 | cat.dive(); // alerts "Sora can dive now." 91 | cat.fly(); // alerts "Sora can fly now." 92 | 93 | .. note:: 94 | implement simply **copies** object methods over into the new class and breaks the prototypal chain. 95 | It does not create a parent link nor does it copy ``initialize`` into the new class. 96 | Implemented methods cannot be overwritten to prevent accidental conflicts. Use extend to modify 97 | available class methods. 98 | 99 | 100 | Class.getOptions() 101 | ================== 102 | 103 | ``(returns object)`` - Gathers assigned options and returns them. 104 | 105 | Getting options from a class:: 106 | 107 | var Animal = new Class({ 108 | options: { 109 | 'name': '', 110 | 'age': null 111 | }, 112 | initialize: function (name, age) { 113 | this.name = this.options.name || name; 114 | this.age = this.options.age || age; 115 | } 116 | }); 117 | 118 | Animal.getOptions(); // returns { 'name': '', 'age': null } 119 | 120 | It is not possible to get the options once an instance has been created. 121 | You can access the instance objects through their options name ``cat.options.name``. 122 | 123 | 124 | Class.setOptions(object) 125 | ======================== 126 | 127 | ``(returns object)`` - Sets and merges a given options object to the classes internal options object. 128 | 129 | Setting options for a class:: 130 | 131 | var Animal = new Class({ 132 | options: { 133 | 'name': '', 134 | 'age': null 135 | }, 136 | initialize: function (name, age) { 137 | this.name = this.options.name || name; 138 | this.age = this.options.age || age; 139 | } 140 | }); 141 | 142 | Animal.setOptions({ 143 | 'name': undefined, 144 | 'dead': false 145 | }); 146 | 147 | Animal.getOptions(); // returns { 'name': undefined, 'age': null, 'dead': false } 148 | 149 | It is not possible to change the options once an instance has been created. 150 | You can access the instance objects through their options name ``cat.options.name``. 151 | 152 | 153 | Class.noConflict() 154 | ================== 155 | 156 | ``(returns Class)`` - Removes the class object from the window object and restores what was there before 157 | class.js was loaded. 158 | 159 | Using class.js with multiple libraries:: 160 | 161 | // loading MooTools 162 | var Classy = Class.noConflict(); 163 | 164 | var Animal = new Classy({ 165 | initialize: function (name, age) { 166 | this.name = name; 167 | this.age = age; 168 | }, 169 | eat: function () { 170 | alert(this.name + ' is eating now.'); 171 | } 172 | }); 173 | 174 | var cat = new Animal('Sora', 4); 175 | cat.eat(); // alerts "Sora is eating now." 176 | 177 | 178 | Class.version 179 | =============== 180 | 181 | ``(returns string)`` - Returns the current running class.js version as a string. 182 | 183 | alert(Class.version); // alerts current class.js version -------------------------------------------------------------------------------- /docs/src/class_api/properties.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | properties 3 | ********** 4 | 5 | The following properties can be used within the Classes passing object. 6 | 7 | 8 | initialize: function 9 | ==================== 10 | 11 | ``(returns constructor)`` - The initialize function serves as constructor on instance creation. 12 | 13 | Create a new Class:: 14 | 15 | var Animal = new Class({ 16 | initialize: function(name, age) { 17 | this.name = name; 18 | this.age = age; 19 | } 20 | }); 21 | 22 | // the passing options will be passed through the constructor initialize 23 | new Animal('Satan', 21); 24 | 25 | 26 | implement: array 27 | ================ 28 | 29 | ``(returns object)`` - Each object or class within the array will be **added** to the assigned class. 30 | 31 | Implementing new methods:: 32 | 33 | // preparing a class 34 | var Mammal = new Class({ 35 | swim: function () { 36 | alert(this.name + ' can swim now.'); 37 | }, 38 | dive: function () { 39 | alert(this.name + ' can dive now.'); 40 | } 41 | }); 42 | 43 | // preparing a normal object 44 | var Bird = { 45 | fly: function () { 46 | alert(this.name + ' can fly now.'); 47 | } 48 | }; 49 | 50 | var Animal = new Class({ 51 | implement: [Mammal, Bird], 52 | initialize: function (name, age) { 53 | this.name = name; 54 | this.age = age; 55 | }, 56 | eat: function () { 57 | alert(this.name + ' is eating now.'); 58 | } 59 | }); 60 | 61 | var cat = new Animal('Sora', 4); 62 | cat.swim(); // alerts "Sora can swim now." 63 | cat.dive(); // alerts "Sora can dive now." 64 | cat.fly(); // alerts "Sora can fly now." 65 | 66 | This property works identical to the Class.implement method. 67 | 68 | 69 | options: object 70 | =============== 71 | 72 | ``(returns object)`` - The options object represents a JSON structure. 73 | 74 | Attach options to a Class:: 75 | 76 | var Animal = new Class({ 77 | options: { 78 | 'name': '', 79 | 'age': null, 80 | 'dead': false 81 | }, 82 | initialize: function (options) { 83 | // merging objects using jQuery 84 | this.options = options; 85 | 86 | // you might want to merge the two ojects using jQuery 87 | // this.options = jQuery.extend(true, {}, this.options, options) 88 | } 89 | }); 90 | 91 | var cat = new Animal({ 92 | 'name': 'Sora', 93 | 'age': 4 94 | }); 95 | 96 | // call options direct 97 | alert(cat.options.name); // alerts 'Sora' 98 | 99 | 100 | this.parent() 101 | ============= 102 | 103 | ``(returns function)`` - When called from within a class.js function this invokes the parent function of the same name. 104 | This is useful when extending an existing class.js plugin. 105 | 106 | Example usage of parent:: 107 | 108 | var Animal = new Class({ 109 | initialize: function (name, age) { 110 | this.name = name; 111 | this.age = age; 112 | }, 113 | getName: function () { 114 | alert(this.name + ' is eating now.'); 115 | } 116 | }); 117 | 118 | Animal.extend({ 119 | getName: function () { 120 | // calls previous getName first 121 | this.parent(); 122 | alert(this.name + ' is ' + this.age + ' years old.'); 123 | } 124 | }); 125 | 126 | var cat = new Animal('Sora', 4); 127 | cat.getName(); // alerts both calls, name and age -------------------------------------------------------------------------------- /docs/src/contributing/guide.rst: -------------------------------------------------------------------------------- 1 | ****************** 2 | Contribution guide 3 | ****************** 4 | 5 | All open-source projects live through their community, so does class.js. You are very welcome to contribute 6 | bug fixes and feature proposals. Please note the following guidelines: 7 | 8 | * class.js is hosted on github: http://github.com/FinalAngel/classjs 9 | 10 | * Use github's issues tracker to submit bug fixes or feature proposals 11 | 12 | * Whenever possible include a `jsfiddle `_ to an issue. 13 | 14 | * It is good practice to fork a project and make your changes through your own fork. 15 | 16 | * Always send a pull request with a reference to the github ticket. 17 | 18 | * Include enough information within your commit messages and pull request to make life easier for us. 19 | 20 | 21 | Don't feel offended if a pull or feature request has been rejected. We always provide reasonable comments 22 | or information's about how your code could be improved. 23 | 24 | Start by fixing or extending the documentation ;) -------------------------------------------------------------------------------- /docs/src/contributing/plugins.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | Plugins 3 | ******* 4 | 5 | Creating and extending plugins is the entire purpose of class.js. 6 | To encourage users to write and extend plugins, we need to establish some common guidelines. 7 | 8 | 9 | Creating a plugin 10 | ================= 11 | 12 | First of all, create a JavaScript file and include the following information within the top of your script: 13 | 14 | * the authors name 15 | * the plugins version 16 | * the plugins license 17 | * the plugins dependencies 18 | 19 | For example:: 20 | 21 | /** 22 | * @author Angelo Dini 23 | * @version 1.0 24 | * @copyright Distributed under the BSD License. 25 | * @requires class.js, jQuery 26 | */ 27 | 28 | You can include the information at any style of your choice whatsoever. 29 | Just insure that you include the required information within the development and minified versions alike. 30 | 31 | 32 | ==== 33 | 34 | 35 | Creating a namespace is important to keep the amount of global variables as low as possible. 36 | 37 | I prefere to use Cl as the shorthand for **Cl** ass:: 38 | 39 | var Cl = window.Cl || {}; 40 | 41 | You are welcome to use this namespace as well. You might want to crossreference the core plugins 42 | for already reservated names like Cl.Lightbox or Cl.Carousel. 43 | 44 | 45 | ==== 46 | 47 | 48 | Creating a closure allows you to create an environment where you don't have to worry about other 49 | plugins namespaces. class.js uses this system by itself:: 50 | 51 | (function(){ 52 | // your code here 53 | })(); 54 | 55 | // you might want to pass some custom variables 56 | (function($){ 57 | // your code here 58 | })(jQuery); 59 | 60 | 61 | ==== 62 | 63 | 64 | When choosing names be descriptive and use CamelCase for naming conventions:: 65 | 66 | Cl.MyPlugin = new Class({ 67 | initialize: function () { 68 | return 'My first plugin'; 69 | } 70 | }); 71 | 72 | 73 | ==== 74 | 75 | 76 | If we combine those techniques your plugin would look like this:: 77 | 78 | /** 79 | * @author Angelo Dini, Distributed under the BSD License. 80 | * @version 1.0 81 | * @requires class.js, jQuery 82 | */ 83 | (function(){ 84 | Cl.MyPlugin = new Class({ 85 | initialize: function () { 86 | return 'My first plugin'; 87 | } 88 | }); 89 | })(); 90 | 91 | 92 | Submitting a plugin 93 | =================== 94 | 95 | If you successfully created a plugin worth spreading let us know https://twitter.com/finalangel and we will 96 | include it within the plugins list. We just require the a website or download link. 97 | 98 | 99 | Core plugins 100 | ============ 101 | 102 | Besides the above described plugins we maintain several core plugins like ``Cl.Lightbox`` or 103 | ``Cl.Carousel``. Those core plugins differ in various ways: 104 | 105 | **A core plugin requires tests and documentation** preferable within the repository itself, 106 | with the option of external documentation. This allows for an easy development process and 107 | insures a high level of quality. Those plugins receive a **reserved namespace** like 108 | ``Cl.AutoComplete`` and will be listed separately. 109 | 110 | It is also a **must** to provide an example page in which the functionality of the plugin can 111 | be demonstrated. Either through using github or a dedicated microsite. 112 | 113 | You are encouraged to use classjs as a name prefix when using a subversion system. For 114 | example ``classjs-lightbox`` or ``classjs-autocomplete``. 115 | 116 | Your plugin also needs to be easily extendable while providing meaningful options. 117 | 118 | You can find a full list of the core plugins on the `Demo page `_. 119 | -------------------------------------------------------------------------------- /docs/src/introduction/how_to_implement.rst: -------------------------------------------------------------------------------- 1 | **************** 2 | How to implement 3 | **************** 4 | 5 | Download the production version of class.js (minified) and implement it in your html code. 6 | 7 | For **HTML5** use:: 8 | 9 | 10 | 11 | For **HTML** and **XHTML** versions use:: 12 | 13 | 14 | 15 | You will be able to call ``Class.version`` within your preferred browsers console 16 | if class.js is implemented or initialized correctly. Feel free to explore the source. -------------------------------------------------------------------------------- /docs/src/introduction/how_to_update.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | How to update 3 | ************* 4 | 5 | Update from Beta to 1.0 6 | ======================= 7 | 8 | There are no special adjustments required for this version. 9 | Beta releases will not be covered by any adaptation. 10 | Therefore consult the Changelog for more details. 11 | 12 | 13 | Update from classy.js to class.js 14 | ================================= 15 | 16 | There is not **yet** an official adapter from classy.js (Divio internal version) to class.js. 17 | You need to change your code to be compatible with class.js. Please follow this guide for a smooth transition: 18 | 19 | Comparison from old to new:: 20 | 21 | var Animal = Class.$extend(obj); // old 22 | var Animal = new Class(obj); // new 23 | 24 | var Tiger = Animal.$extend(obj); // old 25 | var Tiger = Animal.extend(obj); // new 26 | 27 | Class.$classyVersion; // old 28 | Class.version; // new 29 | 30 | Class.$withData(obj); // old 31 | Class.setOptions(obj); // new 32 | 33 | Class.$noConflict(); // old 34 | Class.noConflict(); // new 35 | 36 | this.$super(); // old 37 | this.parent(); // new 38 | 39 | initialize: function () {} // identical in both versions 40 | 41 | implement: [array] // identical in both version 42 | 43 | Additionally class.js provides the following features:: 44 | 45 | Class.getOptions(); 46 | Class.implement([array]); -------------------------------------------------------------------------------- /docs/src/introduction/why_classjs.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Why class.js 3 | ************ 4 | 5 | I started learning JavaScript roughly in 2002 without the use of any framework. 6 | Back then, Prototype was the big player and I did not understand its concept. 7 | I also had issues with Prototype’s none-modular approach splitting animation 8 | (script-aculo-us) from the core library. 9 | 10 | After I finishing my study I came across MooTools and quickly adapted my code to 11 | a more modular and re-usable style. At a certain point of my career the requirements 12 | for use of jQuery grew. jQuery’s popularity grow and we had to adapt. 13 | 14 | I am not a big fan of jQuery, especially jQuery’s UI approach. It is missing any 15 | modular structure and is almost impossible to extend. The fame of jQuery makes it 16 | hard to find a plugin for your case. If you end up finding one you end up changing 17 | the code to work for your specific case. This is wrong. I should be able to take 18 | the plugin and extend it, leaving the code untouched. This enables me to easily 19 | update and maintain the plugin without re-implementing your own changes. 20 | 21 | There is also a second reason. A lot of developers do not understand the principles 22 | of prototypal inheritance. All in all JavaScript is one of the few popular languages 23 | which adapts this concept. This is confusing and leads to misinterpretation. 24 | 25 | This is why I created class.js. 26 | 27 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/class.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @author Angelo Dini 3 | * @version 1.0 4 | * @copyright Distributed under the BSD License. 5 | */ 6 | 7 | (function(){ 8 | 'use strict'; 9 | 10 | // saving constants 11 | var VERSION = '1.0'; 12 | var ORIGINAL = window.Class; 13 | 14 | // creating global class variable 15 | var Class = window.Class = function (obj) { 16 | obj = obj || {}; 17 | // call initialize if given 18 | var constructor = function () { 19 | return (this.initialize) ? this.initialize.apply(this, arguments) : self; 20 | }; 21 | // adds implement to the class itself 22 | if(obj.implement) { 23 | var self = window === this ? copy(constructor.prototype) : this; 24 | var imp = obj.implement; 25 | remove(obj, 'implement'); 26 | obj = extend(obj, implement(imp)); 27 | } 28 | // assign prototypes 29 | constructor.prototype = copy(obj); 30 | // assign correct constructor for correct instanceof comparison 31 | constructor.constructor = constructor; 32 | // save initial object as parent so it can be called by this.parent 33 | constructor._parent = copy(obj); 34 | // attaching class properties to constructor 35 | for(var i = 0, values = ['extend', 'implement', 'getOptions', 'setOptions']; i < values.length; i++) { 36 | constructor[values[i]] = Class[values[i]]; 37 | } 38 | 39 | return constructor; 40 | }; 41 | 42 | // adding class method extend 43 | Class.extend = function (obj) { 44 | var self = this; 45 | // check if implement is passed through extend 46 | if(obj.implement) { 47 | this.prototype = extend(this.prototype, implement(obj.implement)); 48 | // remove implement from obj 49 | remove(obj, 'implement'); 50 | } 51 | // check if we should invoke parent when its called within a method 52 | for(var key in obj) { 53 | obj[key] = typeof obj[key] === 'function' && /parent/.test(obj[key].toString()) ? (function (method, name) { 54 | return function () { 55 | this.parent = self._parent[name]; 56 | return method.apply(this, arguments); 57 | }; 58 | })(obj[key], key) : obj[key] 59 | } 60 | // assign new parent 61 | this._parent = extend(this._parent, obj, true); 62 | // assign new prototype 63 | this.prototype = extend(this.prototype, obj); 64 | // return the class if its assigned 65 | return this; 66 | }; 67 | 68 | // adding class method implement 69 | Class.implement = function (array) { 70 | return this.prototype = extend(this.prototype, implement(array)); 71 | }; 72 | 73 | // gets options from constructor 74 | Class.getOptions = function () { 75 | return this.prototype.options || {}; 76 | }; 77 | 78 | // sets options for constructor 79 | Class.setOptions = function (options) { 80 | return this.prototype.options = extend(this.prototype.options, options); 81 | }; 82 | 83 | // preventing conflicts 84 | Class.noConflict = function () { 85 | // reassign original Class obj to window 86 | window.Class = ORIGINAL; 87 | return Class; 88 | }; 89 | 90 | // returns current running version 91 | Class.version = VERSION; 92 | 93 | // helper for assigning methods to a new prototype 94 | function copy(obj) { 95 | var F = function () {}; 96 | F.prototype = obj.prototype || obj; 97 | return new F(); 98 | } 99 | 100 | // insures the removal of a given method name 101 | function remove(obj , name, safe){ 102 | // if save is active we need to copy all attributes over. 103 | if(safe) { 104 | var safeObj = {}; 105 | for(var key in obj) { 106 | if(key !== name) safeObj[key] = obj[key]; 107 | } 108 | } else { 109 | delete obj[name]; 110 | } 111 | return safeObj || obj; 112 | } 113 | 114 | // helper for merging two object with each other 115 | function extend(oldObj, newObj, preserve) { 116 | // failsave if something goes wrong 117 | if(!oldObj || !newObj) return oldObj || newObj || {}; 118 | 119 | // make sure we work with copies 120 | oldObj = copy(oldObj); 121 | newObj = copy(newObj); 122 | 123 | for(var key in newObj) { 124 | if(Object.prototype.toString.call(newObj[key]) === '[object Object]') { 125 | extend(oldObj[key], newObj[key]); 126 | } else { 127 | // if preserve is set to true oldObj will not be overwritten by newObj if 128 | // oldObj has already a method key 129 | oldObj[key] = (preserve && oldObj[key]) ? oldObj[key] : newObj[key]; 130 | } 131 | } 132 | 133 | return oldObj; 134 | } 135 | 136 | // helper for implementing other classes or objects 137 | function implement(array) { 138 | var collection = {}; 139 | 140 | for(var i = 0; i < array.length; i++) { 141 | // check if a class is implemented and save its prototype 142 | if(typeof(array[i]) === 'function') array[i] = array[i].prototype; 143 | 144 | // safely remove initialize 145 | var safe = remove(array[i], 'initialize', true); 146 | 147 | // we use implement again if array has the apropriate methiod, otherwise we extend 148 | if(safe.implement) { 149 | collection = implement(safe.implement); 150 | } else { 151 | collection = extend(collection, safe); 152 | } 153 | } 154 | 155 | return collection; 156 | } 157 | 158 | })(); -------------------------------------------------------------------------------- /src/class.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @author Angelo Dini 3 | * @version 1.0 4 | * @copyright Distributed under the BSD License. 5 | */ 6 | (function(){var d="1.0";var c=window.Class;var b=window.Class=function(n){n=n||{};var m=function(){return(this.initialize)?this.initialize.apply(this,arguments):j};if(n.implement){var j=window===this?g(m.prototype):this;var l=n.implement;a(n,"implement");n=f(n,e(l))}m.prototype=g(n);m.constructor=m;m._parent=g(n);for(var k=0,h=["extend","implement","getOptions","setOptions"];k 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 |

QUnit Test Suite

12 |

13 |
14 | 15 |

16 |
  1.  
17 |
test markup
18 | 19 | -------------------------------------------------------------------------------- /tests/qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /** Font Family and Sizes */ 2 | 3 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 4 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 5 | } 6 | 7 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 8 | #qunit-tests { font-size: smaller; } 9 | 10 | 11 | /** Resets */ 12 | 13 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { 14 | margin: 0; 15 | padding: 0; 16 | } 17 | 18 | 19 | /** Header */ 20 | 21 | #qunit-header { 22 | padding: 0.5em 0 0.5em 2em; 23 | font-size:medium; 24 | 25 | color: #fff; 26 | background-color: #0d3349; 27 | } 28 | 29 | #qunit-header a { 30 | text-decoration: none; 31 | color: white; 32 | } 33 | 34 | #qunit-banner { 35 | height: 5px; 36 | } 37 | 38 | #qunit-testrunner-toolbar { 39 | padding: 0em 0 0.5em 2em; 40 | } 41 | 42 | #qunit-userAgent { 43 | padding: 0.5em 0 0.5em 2.5em; 44 | background-color: #2b81af; 45 | color: #fff; 46 | } 47 | 48 | 49 | /** Tests: Pass/Fail */ 50 | 51 | #qunit-tests { 52 | list-style-position: inside; 53 | } 54 | 55 | #qunit-tests li { 56 | padding: 0.4em 0.5em 0.4em 2.5em; 57 | border-bottom: 1px solid #fff; 58 | list-style-position: inside; 59 | } 60 | 61 | #qunit-tests li strong { 62 | cursor: pointer; 63 | } 64 | 65 | #qunit-tests ol { 66 | margin-top: 0.5em; 67 | padding: 0.5em; 68 | 69 | background-color: #fff; 70 | 71 | box-shadow: inset 0px 0px 5px #999; 72 | -moz-box-shadow: inset 0px 0px 5px #999; 73 | -webkit-box-shadow: inset 0px 0px 5px #999; 74 | } 75 | 76 | /*** Test Counts */ 77 | 78 | #qunit-tests b.counts { color: black; } 79 | #qunit-tests b.passed { color: #5E740B; } 80 | #qunit-tests b.failed { color: #710909; } 81 | 82 | #qunit-tests li li { 83 | margin: 0.5em; 84 | padding: 0.4em 0.5em 0.4em 0.5em; 85 | background-color: #fff; 86 | border-bottom: none; 87 | list-style-position: inside; 88 | } 89 | 90 | /*** Passing Styles */ 91 | 92 | #qunit-tests li li.pass { 93 | color: #5E740B; 94 | background-color: #fff; 95 | border-left: 26px solid #C6E746; 96 | } 97 | 98 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 99 | #qunit-tests .pass .test-name { color: #366097; } 100 | 101 | #qunit-tests .pass .test-actual, 102 | #qunit-tests .pass .test-expected { color: #999999; } 103 | 104 | #qunit-banner.qunit-pass { background-color: #C6E746; } 105 | 106 | /*** Failing Styles */ 107 | 108 | #qunit-tests li li.fail { 109 | color: #710909; 110 | background-color: #fff; 111 | border-left: 26px solid #EE5757; 112 | } 113 | 114 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 115 | #qunit-tests .fail .test-name, 116 | #qunit-tests .fail .module-name { color: #000000; } 117 | 118 | #qunit-tests .fail .test-actual { color: #EE5757; } 119 | #qunit-tests .fail .test-expected { color: green; } 120 | 121 | #qunit-banner.qunit-fail, 122 | #qunit-testrunner-toolbar { background-color: #EE5757; } 123 | 124 | 125 | /** Footer */ 126 | 127 | #qunit-testresult { 128 | padding: 0.5em 0.5em 0.5em 2.5em; 129 | 130 | color: #2b81af; 131 | background-color: #D2E0E6; 132 | } 133 | 134 | /** Fixture */ 135 | 136 | #qunit-fixture { 137 | position: absolute; 138 | top: -10000px; 139 | left: -10000px; 140 | } 141 | -------------------------------------------------------------------------------- /tests/testDemo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 9 | 10 | 11 | 121 | 122 | 123 | 124 | 127 | 128 | -------------------------------------------------------------------------------- /tests/testLibs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | QUnit Test Suite 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 37 | 38 | -------------------------------------------------------------------------------- /tests/tests.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * @author Angelo Dini - github.com/finalangel/classjs 3 | * @copyright Distributed under the BSD License. 4 | * @version 2.0.1 5 | */ 6 | 7 | /* 8 | * TESTS 9 | */ 10 | module("class.js"); 11 | 12 | test('Core functionality', function() { 13 | // tests 14 | equal(typeof(window.Class), 'function', 'class is available within the window object'); 15 | equal(typeof(Class), 'function', 'Class is available to be called'); 16 | equal(objIsEmpty(Class.prototype), true, 'prototype is empty'); 17 | 18 | testConstructor(Class); 19 | }); 20 | 21 | test('Class constructor', function () { 22 | // setup 23 | var Animal = new Class(); 24 | var Person = new Class({}); 25 | var Computer = new Class({ 26 | 'calc': function () {} 27 | }); 28 | 29 | // tests 30 | equal(typeof(Animal), 'function', 'class is created'); 31 | equal(objIsEmpty(Animal.prototype), true, 'animal prototype is empty'); 32 | equal(objIsEmpty(Person.prototype), true, 'person prototype is empty'); 33 | equal(objIsEmpty(Computer.prototype), false, 'computer prototype is not empty'); 34 | 35 | ok(!(Animal instanceof Class), 'animal is not an instance of class'); 36 | 37 | var Correct = new Class({ 38 | 'isCorrect': function () {} 39 | }); 40 | // using strict mode allows it at this point to "forget" the new keyword 41 | var Wrong = Class({ 42 | 'isWrong': function () {} 43 | }); 44 | equal(typeof(Correct.prototype.isCorrect), 'function', 'invoking class with new keyword works'); 45 | equal(typeof(Wrong.prototype.isWrong), 'function', 'invoking class without the new keyword works'); 46 | 47 | equal(typeof(new Correct().isCorrect), 'function', 'invoking instance with new keyword works'); 48 | // you should not be able to call Wrong().isWrong without the new keyword 49 | equal(typeof(new Wrong().isWrong), 'function', 'invoking instance with new keyword works'); 50 | 51 | testConstructor(Animal); 52 | }); 53 | 54 | test('Class noConflict', function () { 55 | // setup 56 | var Original = window.Class; 57 | var Classy = Class.noConflict(); 58 | var Animal = new Classy(); 59 | 60 | // tests 61 | strictEqual(window.Class, undefined, 'noConflict unsets Class from window'); 62 | deepEqual(Classy, Original, 'noConflict binds the new variable with Class behaviour'); 63 | 64 | testConstructor(Animal); 65 | 66 | ok(true, 'For a live example consult libsTest.html'); 67 | 68 | window.Class = Original; 69 | }); 70 | 71 | test('Class method extend', function () { 72 | // setup 73 | var Animal = new Class({ 74 | 'initialize': function (name, age) { 75 | this.name = name; 76 | this.age = age; 77 | } 78 | }); 79 | Animal.extend({ 80 | 'eat': function () { 81 | return this.name + ' is eating'; 82 | }, 83 | 'die': function () { 84 | return this.name + ' died at age ' + this.age; 85 | } 86 | }); 87 | var name = 'Cat', age = 43, instance = new Animal(name, age); 88 | 89 | // tests 90 | equal(typeof(Animal.prototype.initialize), 'function', 'initialize has been added'); 91 | equal(typeof(Animal.prototype.eat), 'function', 'eat has been added'); 92 | equal(typeof(Animal.prototype.die), 'function', 'die has been added'); 93 | 94 | equal(instance.name, name, 'this.name can be called'); 95 | equal(instance.age, age, 'this.age can be called'); 96 | 97 | equal(instance.eat(), name + ' is eating', 'this.eat() can be called'); 98 | equal(instance.die(), name + ' died at age ' + age, 'this.die() can be called'); 99 | 100 | ok(instance instanceof Animal, 'correct instance for class is given'); 101 | }); 102 | 103 | test('Class method implement', function () { 104 | // setup 105 | var Animal = new Class({ 106 | 'initialize': function (name, age) { 107 | this.name = name; 108 | this.age = age; 109 | } 110 | }); 111 | var essentials = { 112 | 'eat': function () { 113 | return this.name + ' is eating'; 114 | }, 115 | 'die': function () { 116 | return this.name + ' died at age ' + this.age; 117 | } 118 | }; 119 | var advanced = { 120 | 'dance': function () { 121 | return this.name + ' is dancing'; 122 | }, 123 | 'fly': function () { 124 | return this.name + ' is flying'; 125 | } 126 | }; 127 | var professional = { 128 | 'invincible': true 129 | }; 130 | 131 | Animal.implement([essentials, advanced]); 132 | 133 | var Cat = new Class({ 134 | 'implement': [Animal], 135 | // initialize is not passed by implement 136 | 'initialize': function (name, age) { 137 | this.name = name; 138 | this.age = age; 139 | }, 140 | 'cuteness': function () { 141 | return this.name + '\'s level is 99'; 142 | } 143 | }); 144 | Cat.extend({ 145 | 'implement': [professional], 146 | 'superpower': true 147 | }); 148 | var myCat = new Cat('Sora', 2); 149 | 150 | // tests 151 | equal(typeof(Cat.prototype.initialize), 'function', 'initialize has been added'); 152 | equal(typeof(Cat.prototype.eat), 'function', 'eat has been added'); 153 | equal(typeof(Cat.prototype.die), 'function', 'die has been added'); 154 | equal(typeof(Cat.prototype.dance), 'function', 'dance has been added'); 155 | equal(typeof(Cat.prototype.fly), 'function', 'fly has been added'); 156 | equal(typeof(Cat.prototype.cuteness), 'function', 'cuteness has been added'); 157 | strictEqual(Cat.prototype.invincible, true, 'cuteness has been added'); 158 | strictEqual(Cat.prototype.superpower, true, 'cuteness has been added'); 159 | strictEqual(Cat.prototype.implement, undefined, 'implement has not been passed'); 160 | equal(myCat.cuteness(), 'Sora\'s level is 99', 'appropriate methods can be called'); 161 | }); 162 | 163 | test('Class method getOptions', function () { 164 | // setup 165 | var Animal = new Class({ 166 | 'options': { 167 | 'name': 'Unnamed', 168 | 'age': 5 169 | }, 170 | 'initialize': function (name, age) { 171 | this.name = name || this.options.name; 172 | this.age = age || this.options.age; 173 | } 174 | }); 175 | var options = Animal.getOptions(); 176 | var Cat = new Animal('Sora', 2); 177 | 178 | // tests 179 | equal(options.name, 'Unnamed', 'option name can be read via getOptions'); 180 | equal(options.age, 5, 'option age can be read via getOptions'); 181 | 182 | equal(Cat.options.name, 'Unnamed', 'option name can be read via method call'); 183 | equal(Cat.options.age, 5, 'option age can be read via method call'); 184 | 185 | equal(Cat.name, 'Sora', 'class name is set correctly'); 186 | equal(Cat.age, 2, 'class age is set correctly'); 187 | }); 188 | 189 | test('Class method setOptions', function () { 190 | // setup 191 | var Animal = new Class({ 192 | 'options': { 193 | 'name': 'Unnamed', 194 | 'age': 5 195 | }, 196 | 'initialize': function (name, age) { 197 | this.name = name || this.options.name; 198 | this.age = age || this.options.age; 199 | } 200 | }); 201 | 202 | var Cat = new Animal('Sora', 2); 203 | var Dog = new Animal('Pitschy', 1); 204 | 205 | // tests 206 | equal(Cat.options.age, 5, 'option age can be read via method call'); 207 | equal(Dog.options.age, 5, 'option age can be read via method call'); 208 | 209 | Animal.setOptions({ 'age': 10 }); 210 | equal(Cat.options.age, 10, 'option age can be read via method call'); 211 | equal(Dog.options.age, 10, 'option age can be read via method call'); 212 | 213 | Animal.setOptions({ 'age': 15 }); 214 | equal(Cat.options.age, 15, 'option age can be read via method call'); 215 | equal(Dog.options.age, 15, 'option age can be read via method call'); 216 | 217 | equal(Cat.age, 2, 'correct age is given'); 218 | equal(Dog.age, 1, 'correct age is given'); 219 | 220 | equal(Cat.options.name, 'Unnamed', 'option name can be read via method call'); 221 | equal(Dog.options.name, 'Unnamed', 'option name can be read via method call'); 222 | 223 | ok(Cat instanceof Animal, 'correct instance for class is given'); 224 | ok(Dog instanceof Animal, 'correct instance for class is given'); 225 | }); 226 | 227 | test('Class method parent', function () { 228 | // setup 229 | var Animal = new Class({ 230 | 'initialize': function (name, age) { 231 | this.name = name; 232 | this.age = age; 233 | }, 234 | 'eat': function () { 235 | this.name = 'Pitschy'; 236 | 237 | return this.name + ' call FIRST eat'; 238 | }, 239 | 'live': function () { 240 | // the return value will be overwritten 241 | return this.age + ' call FIRST live'; 242 | } 243 | }); 244 | Animal.extend({ 245 | 'die': function () {} 246 | }); 247 | Animal.extend({ 248 | 'eat': function () { 249 | this.parent(); 250 | 251 | return this.name + ' call SECOND eat'; 252 | }, 253 | 'live': function () { 254 | this.parent(); 255 | 256 | return this.age + ' call SECOND live'; 257 | } 258 | }); 259 | 260 | var Cat = new Animal('Sora', 2); 261 | 262 | // tests 263 | equal(Cat.eat(), 'Pitschy call SECOND eat', 'parent works on first invocation'); 264 | equal(Cat.live(), '2 call SECOND live', 'parent works on second invocation'); 265 | equal(typeof(Cat.die), 'function', 'extending function has been attached'); 266 | 267 | ok(Cat.parent(), 'parent is attached to the normal object'); 268 | }); 269 | 270 | test('Class method version', function () { 271 | // tests 272 | equal(typeof(Class.version), 'string', 'Class.version() can be called'); 273 | }); 274 | 275 | test('Class demo examples', function () { 276 | var Dimmer = new Class({ 277 | initialize: function (container) { 278 | this.container = document.getElementById(container); 279 | }, 280 | showDim: function () { 281 | console.log('first'); 282 | return 'show dim'; 283 | }, 284 | hideDim: function () { 285 | return 'hide dim'; 286 | } 287 | }); 288 | 289 | var Lightbox = new Class({ 290 | implement: [Dimmer], 291 | initialize: function (container) { 292 | this.container = document.getElementById(container); 293 | }, 294 | show: function () { 295 | this.showDim(); 296 | }, 297 | hide: function () { 298 | this.hideDim(); 299 | }, 300 | hideDim: function () { 301 | // this does NOT work, implement overwrites custom methods 302 | // if you want to create a custom hideDime use extend on Dimmer 303 | this.parent(); 304 | return 'hide custom dim'; 305 | } 306 | }); 307 | 308 | Lightbox.implement([Dimmer]); 309 | 310 | var lb = new Lightbox(); 311 | 312 | // tests 313 | equal(lb.hideDim(), 'hide dim', 'implement successfully overwrites the instnace method'); 314 | }); 315 | 316 | test('Cleanup check', function () { 317 | // tests 318 | equal(typeof(window.Class), 'function', 'class is available within the window object'); 319 | equal(typeof(Class), 'function', 'Class is available to be called'); 320 | equal(objIsEmpty(Class.prototype), true, 'prototype is empty'); 321 | 322 | testConstructor(Class); 323 | }); 324 | 325 | /* 326 | * HELPERS 327 | */ 328 | // test if an obj is empty or not 329 | function objIsEmpty(obj) { 330 | for(var prop in obj) { 331 | if(prop) return false; 332 | } 333 | return true; 334 | } 335 | // base constructor tests 336 | function testConstructor(obj) { 337 | equal(typeof(obj.extend), 'function', 'extend is available'); 338 | equal(typeof(obj.implement), 'function', 'implement is available'); 339 | equal(typeof(obj.setOptions), 'function', 'setOptions is available'); 340 | equal(typeof(obj.getOptions), 'function', 'getOptions is available'); 341 | } --------------------------------------------------------------------------------