classjs-1.0.0/000077500000000000000000000000001212165172300131525ustar00rootroot00000000000000classjs-1.0.0/.gitignore000066400000000000000000000000201212165172300151320ustar00rootroot00000000000000.idea/ .DS_Storeclassjs-1.0.0/AUTHORS.rst000066400000000000000000000004071212165172300150320ustar00rootroot00000000000000the class.js library is written and maintained by: - Angelo Dini class.js is heavily inspired by the following libraries: - MooTools Class - JS.Class - Classy classjs-1.0.0/CHANGELOG.rst000066400000000000000000000003661212165172300152000ustar00rootroot00000000000000======== class.js ======== v1.0 ---- - Versioning change, codebase did not encounter any bigger issues. v1.0.beta1 ---------- - Adding initial release with support for extend, implement, getOptions, setOptions, noConflict, parent and version.classjs-1.0.0/LICENSE.rst000066400000000000000000000030101212165172300147600ustar00rootroot00000000000000# class.js - simple class based inheritance # copyright (c) 2012 Angelo Dini and contributors # https://github.com/finalangel Some rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.classjs-1.0.0/README.rst000066400000000000000000000015551212165172300146470ustar00rootroot00000000000000========================================= class.js - simple class based inheritance ========================================= https://github.com/finalangel/classjs class.js is a JavaScript library for building class based object-oriented programms using JavaScript's prototypal inheritance. It strives to mimic classical class inheritance provided by other languages such as Python, Java or C. Its syntax is heavily inspired by MooTools's class implementation. Documentation ============= Go to `http://classjs.rtfd.org` for a full documentation. Please use github to report bugs or feature requests. Include a `jsfiddle `_ or equivalent example whenever possible for issues and bugs. Testet in Chrome, Fierfox 4+, Internet Explorer 7+ and Opera. License ======= Distributed under the BSD Licence. Copyright (c) 2012 Angelo Dini and contributorsclassjs-1.0.0/docs/000077500000000000000000000000001212165172300141025ustar00rootroot00000000000000classjs-1.0.0/docs/Makefile000066400000000000000000000107661212165172300155540ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ClassyJS.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ClassyJS.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/ClassyJS" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ClassyJS" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." make -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." classjs-1.0.0/docs/conf.py000066400000000000000000000171201212165172300154020ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # classjs documentation build configuration file, created by # sphinx-quickstart on Tue Apr 3 09:48:09 2012. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'classjs' copyright = u'2012, Angelo Dini' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '1.0' # The full version, including alpha/beta/rc tags. release = '1.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build', 'html'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' highlight_language = 'javascript' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'classjsdoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'classjs.tex', u'classjs Documentation', u'Angelo Dini', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'classjs', u'classjs Documentation', [u'Angelo Dini'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'classjs', u'classjs Documentation', u'Angelo Dini', 'classjs', 'simple class based inheritance.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' classjs-1.0.0/docs/index.html000066400000000000000000000001371212165172300161000ustar00rootroot00000000000000classjs-1.0.0/docs/index.rst000066400000000000000000000021341212165172300157430ustar00rootroot00000000000000.. classjs documentation master file, created by sphinx-quickstart on Tue Apr 3 09:48:09 2012. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. ####### Welcome ####### class.js is a JavaScript library for building class based object-oriented programs using JavaScript's prototypal inheritance. class.js strives to mimic classical class inheritance provided by other languages such as Python, Java or C. Its syntax is heavily inspired by MooTools class implementation. The latest stable version is |release| - https://github.com/finalangel/classjs ############ Introduction ############ .. toctree:: :maxdepth: 1 src/introduction/why_classjs.rst src/introduction/how_to_implement.rst src/introduction/how_to_update.rst ######### Class API ######### .. toctree:: :maxdepth: 2 src/class_api/methods.rst src/class_api/properties.rst ############ Contributing ############ .. toctree:: :maxdepth: 2 src/contributing/guide.rst src/contributing/plugins.rst src/contributing/plugins_list.rstclassjs-1.0.0/docs/src/000077500000000000000000000000001212165172300146715ustar00rootroot00000000000000classjs-1.0.0/docs/src/class_api/000077500000000000000000000000001212165172300166275ustar00rootroot00000000000000classjs-1.0.0/docs/src/class_api/methods.rst000066400000000000000000000101761212165172300210310ustar00rootroot00000000000000******* methods ******* The following methods can be attached to a new class. new Class(object); ================== ``(returns object)`` - This is the class constructor and passes the provided object to the instances prototype. Create a new Class:: var Animal = new Class({ initialize: function (name, age) { this.name = name; this.age = age; }, eat: function () { alert(this.name + ' is eating now.'); } }); For a better explanation to ``initialize`` consult the class.js properties section. Class.extend(object) ==================== ``(returns object)`` - The object or class passed through extend will be **merged** with the assigned class following the previous example. Extend the class:: Animal.extend({ die: function () { alert(this.name + ' died at age ' + this.age); } }); var cat = new Animal('Sora', 4); cat.die(); // alerts "Sora died at age 4" Class.implement(array) ====================== ``(returns object)`` - Each object or class within the array will be **added** to the assigned class following the previous example. Implementing new methods:: // preparing a class var Mammal = new Class({ swim: function () { alert(this.name + ' can swim now.'); }, dive: function () { alert(this.name + ' can dive now.'); } }); // preparing a normal object var Bird = { fly: function () { alert(this.name + ' can fly now.'); } }; Animal.implement([Mammal, Bird]); var cat = new Animal('Sora', 4); cat.swim(); // alerts "Sora can swim now." cat.dive(); // alerts "Sora can dive now." cat.fly(); // alerts "Sora can fly now." .. note:: implement simply **copies** object methods over into the new class and breaks the prototypal chain. It does not create a parent link nor does it copy ``initialize`` into the new class. Implemented methods cannot be overwritten to prevent accidental conflicts. Use extend to modify available class methods. Class.getOptions() ================== ``(returns object)`` - Gathers assigned options and returns them. Getting options from a class:: var Animal = new Class({ options: { 'name': '', 'age': null }, initialize: function (name, age) { this.name = this.options.name || name; this.age = this.options.age || age; } }); Animal.getOptions(); // returns { 'name': '', 'age': null } It is not possible to get the options once an instance has been created. You can access the instance objects through their options name ``cat.options.name``. Class.setOptions(object) ======================== ``(returns object)`` - Sets and merges a given options object to the classes internal options object. Setting options for a class:: var Animal = new Class({ options: { 'name': '', 'age': null }, initialize: function (name, age) { this.name = this.options.name || name; this.age = this.options.age || age; } }); Animal.setOptions({ 'name': undefined, 'dead': false }); Animal.getOptions(); // returns { 'name': undefined, 'age': null, 'dead': false } It is not possible to change the options once an instance has been created. You can access the instance objects through their options name ``cat.options.name``. Class.noConflict() ================== ``(returns Class)`` - Removes the class object from the window object and restores what was there before class.js was loaded. Using class.js with multiple libraries:: // loading MooTools var Classy = Class.noConflict(); var Animal = new Classy({ initialize: function (name, age) { this.name = name; this.age = age; }, eat: function () { alert(this.name + ' is eating now.'); } }); var cat = new Animal('Sora', 4); cat.eat(); // alerts "Sora is eating now." Class.version =============== ``(returns string)`` - Returns the current running class.js version as a string. alert(Class.version); // alerts current class.js versionclassjs-1.0.0/docs/src/class_api/properties.rst000066400000000000000000000057011212165172300215600ustar00rootroot00000000000000********** properties ********** The following properties can be used within the Classes passing object. initialize: function ==================== ``(returns constructor)`` - The initialize function serves as constructor on instance creation. Create a new Class:: var Animal = new Class({ initialize: function(name, age) { this.name = name; this.age = age; } }); // the passing options will be passed through the constructor initialize new Animal('Satan', 21); implement: array ================ ``(returns object)`` - Each object or class within the array will be **added** to the assigned class. Implementing new methods:: // preparing a class var Mammal = new Class({ swim: function () { alert(this.name + ' can swim now.'); }, dive: function () { alert(this.name + ' can dive now.'); } }); // preparing a normal object var Bird = { fly: function () { alert(this.name + ' can fly now.'); } }; var Animal = new Class({ implement: [Mammal, Bird], initialize: function (name, age) { this.name = name; this.age = age; }, eat: function () { alert(this.name + ' is eating now.'); } }); var cat = new Animal('Sora', 4); cat.swim(); // alerts "Sora can swim now." cat.dive(); // alerts "Sora can dive now." cat.fly(); // alerts "Sora can fly now." This property works identical to the Class.implement method. options: object =============== ``(returns object)`` - The options object represents a JSON structure. Attach options to a Class:: var Animal = new Class({ options: { 'name': '', 'age': null, 'dead': false }, initialize: function (options) { // merging objects using jQuery this.options = options; // you might want to merge the two ojects using jQuery // this.options = jQuery.extend(true, {}, this.options, options) } }); var cat = new Animal({ 'name': 'Sora', 'age': 4 }); // call options direct alert(cat.options.name); // alerts 'Sora' this.parent() ============= ``(returns function)`` - When called from within a class.js function this invokes the parent function of the same name. This is useful when extending an existing class.js plugin. Example usage of parent:: var Animal = new Class({ initialize: function (name, age) { this.name = name; this.age = age; }, getName: function () { alert(this.name + ' is eating now.'); } }); Animal.extend({ getName: function () { // calls previous getName first this.parent(); alert(this.name + ' is ' + this.age + ' years old.'); } }); var cat = new Animal('Sora', 4); cat.getName(); // alerts both calls, name and ageclassjs-1.0.0/docs/src/contributing/000077500000000000000000000000001212165172300174005ustar00rootroot00000000000000classjs-1.0.0/docs/src/contributing/guide.rst000066400000000000000000000016411212165172300212310ustar00rootroot00000000000000****************** Contribution guide ****************** All open-source projects live through their community, so does class.js. You are very welcome to contribute bug fixes and feature proposals. Please note the following guidelines: * class.js is hosted on github: http://github.com/FinalAngel/classjs * Use github's issues tracker to submit bug fixes or feature proposals * Whenever possible include a `jsfiddle `_ to an issue. * It is good practice to fork a project and make your changes through your own fork. * Always send a pull request with a reference to the github ticket. * Include enough information within your commit messages and pull request to make life easier for us. Don't feel offended if a pull or feature request has been rejected. We always provide reasonable comments or information's about how your code could be improved. Start by fixing or extending the documentation ;)classjs-1.0.0/docs/src/contributing/plugins.rst000066400000000000000000000061641212165172300216220ustar00rootroot00000000000000******* Plugins ******* Creating and extending plugins is the entire purpose of class.js. To encourage users to write and extend plugins, we need to establish some common guidelines. Creating a plugin ================= First of all, create a JavaScript file and include the following information within the top of your script: * the authors name * the plugins version * the plugins license * the plugins dependencies For example:: /** * @author Angelo Dini * @version 1.0 * @copyright Distributed under the BSD License. * @requires class.js, jQuery */ You can include the information at any style of your choice whatsoever. Just insure that you include the required information within the development and minified versions alike. ==== Creating a namespace is important to keep the amount of global variables as low as possible. I prefere to use Cl as the shorthand for **Cl** ass:: var Cl = window.Cl || {}; You are welcome to use this namespace as well. You might want to crossreference the core plugins for already reservated names like Cl.Lightbox or Cl.Carousel. ==== Creating a closure allows you to create an environment where you don't have to worry about other plugins namespaces. class.js uses this system by itself:: (function(){ // your code here })(); // you might want to pass some custom variables (function($){ // your code here })(jQuery); ==== When choosing names be descriptive and use CamelCase for naming conventions:: Cl.MyPlugin = new Class({ initialize: function () { return 'My first plugin'; } }); ==== If we combine those techniques your plugin would look like this:: /** * @author Angelo Dini, Distributed under the BSD License. * @version 1.0 * @requires class.js, jQuery */ (function(){ Cl.MyPlugin = new Class({ initialize: function () { return 'My first plugin'; } }); })(); Submitting a plugin =================== If you successfully created a plugin worth spreading let us know https://twitter.com/finalangel and we will include it within the plugins list. We just require the a website or download link. Core plugins ============ Besides the above described plugins we maintain several core plugins like ``Cl.Lightbox`` or ``Cl.Carousel``. Those core plugins differ in various ways: **A core plugin requires tests and documentation** preferable within the repository itself, with the option of external documentation. This allows for an easy development process and insures a high level of quality. Those plugins receive a **reserved namespace** like ``Cl.AutoComplete`` and will be listed separately. It is also a **must** to provide an example page in which the functionality of the plugin can be demonstrated. Either through using github or a dedicated microsite. You are encouraged to use classjs as a name prefix when using a subversion system. For example ``classjs-lightbox`` or ``classjs-autocomplete``. Your plugin also needs to be easily extendable while providing meaningful options.classjs-1.0.0/docs/src/contributing/plugins_list.rst000066400000000000000000000006301212165172300226450ustar00rootroot00000000000000*************** List of plugins *************** Thanks for the following authors for their amazing plugins and effort: Core plugins ============ * `Cl.Carousel `_ [Angelo Dini] * `Cl.Lightbox `_ [Angelo Dini] User plugins ============ * Please refer to the :doc:`how_to` page for creating your own plugin.classjs-1.0.0/docs/src/introduction/000077500000000000000000000000001212165172300174125ustar00rootroot00000000000000classjs-1.0.0/docs/src/introduction/how_to_implement.rst000066400000000000000000000007461212165172300235240ustar00rootroot00000000000000**************** How to implement **************** Download the production version of class.js (minified) and implement it in your html code. For **HTML5** use:: For **HTML** and **XHTML** versions use:: You will be able to call ``Class.version`` within your preferred browsers console if class.js is implemented or initialized correctly. Feel free to explore the source.classjs-1.0.0/docs/src/introduction/how_to_update.rst000066400000000000000000000022651212165172300230120ustar00rootroot00000000000000************* How to update ************* Update from Beta to 1.0 ======================= There are no special adjustments required for this version. Beta releases will not be covered by any adaptation. Therefore consult the Changelog for more details. Update from classy.js to class.js ================================= There is not **yet** an official adapter from classy.js (Divio internal version) to class.js. You need to change your code to be compatible with class.js. Please follow this guide for a smooth transition: Comparison from old to new:: var Animal = Class.$extend(obj); // old var Animal = new Class(obj); // new var Tiger = Animal.$extend(obj); // old var Tiger = Animal.extend(obj); // new Class.$classyVersion; // old Class.version; // new Class.$withData(obj); // old Class.setOptions(obj); // new Class.$noConflict(); // old Class.noConflict(); // new this.$super(); // old this.parent(); // new initialize: function () {} // identical in both versions implement: [array] // identical in both version Additionally class.js provides the following features:: Class.getOptions(); Class.implement([array]);classjs-1.0.0/docs/src/introduction/why_classjs.rst000066400000000000000000000024501212165172300224760ustar00rootroot00000000000000************ Why class.js ************ I started learning JavaScript roughly in 2002 without the use of any framework. Back than Prototype was the big player and I did not understand its concept. I also had issues with Prototype’s none-modular approach splitting animation (script-aculo-us) from the core library. After I finishing my study I came across MooTools and quickly adapted my code to a more modular and re-usable style. At a certain point of my career the requirements for use of jQuery grew. jQuery’s popularity grow and we had to adapt. I am not a big fan of jQuery, especially jQuery’s UI approach. It is missing any modular structure and is almost impossible to extend. The fame of jQuery makes it hard to find a plugin for your case. If you end up finding one you end up changing the code to work for your specific case. This is wrong. I should be able to take the plugin and extend it, leaving the code untouched. This enables me to easily update and maintain the plugin without re-implementing your own changes. There is also a second reason. A lot of developers do not understand the principles of prototypal inheritance. All in all JavaScript is one of the few popular languages which adapts this concept. This is confusing and leads to misinterpretation. This is why I created class.js. classjs-1.0.0/index.html000066400000000000000000000001161212165172300151450ustar00rootroot00000000000000classjs-1.0.0/src/000077500000000000000000000000001212165172300137415ustar00rootroot00000000000000classjs-1.0.0/src/class.js000066400000000000000000000104631212165172300154100ustar00rootroot00000000000000/*! * @author Angelo Dini * @version 1.0 * @copyright Distributed under the BSD License. */ (function(){ 'use strict'; // saving constants var VERSION = '1.0'; var ORIGINAL = window.Class; // creating global class variable var Class = window.Class = function (obj) { obj = obj || {}; // call initialize if given var constructor = function () { return (this.initialize) ? this.initialize.apply(this, arguments) : self; }; // adds implement to the class itself if(obj.implement) { var self = window === this ? copy(constructor.prototype) : this; var imp = obj.implement; remove(obj, 'implement'); obj = extend(obj, implement(imp)); } // assign prototypes constructor.prototype = copy(obj); // assign correct constructor for correct instanceof comparison constructor.constructor = constructor; // save initial object as parent so it can be called by this.parent constructor._parent = copy(obj); // attaching class properties to constructor for(var i = 0, values = ['extend', 'implement', 'getOptions', 'setOptions']; i < values.length; i++) { constructor[values[i]] = Class[values[i]]; } return constructor; }; // adding class method extend Class.extend = function (obj) { var self = this; // check if implement is passed through extend if(obj.implement) { this.prototype = extend(this.prototype, implement(obj.implement)); // remove implement from obj remove(obj, 'implement'); } // check if we should invoke parent when its called within a method for(var key in obj) { obj[key] = typeof obj[key] === 'function' && /parent/.test(obj[key].toString()) ? (function (method, name) { return function () { this.parent = self._parent[name]; return method.apply(this, arguments); }; })(obj[key], key) : obj[key] } // assign new parent this._parent = extend(this._parent, obj, true); // assign new prototype this.prototype = extend(this.prototype, obj); // return the class if its assigned return this; }; // adding class method implement Class.implement = function (array) { return this.prototype = extend(this.prototype, implement(array)); }; // gets options from constructor Class.getOptions = function () { return this.prototype.options || {}; }; // sets options for constructor Class.setOptions = function (options) { return this.prototype.options = extend(this.prototype.options, options); }; // preventing conflicts Class.noConflict = function () { // reassign original Class obj to window window.Class = ORIGINAL; return Class; }; // returns current running version Class.version = VERSION; // helper for assigning methods to a new prototype function copy(obj) { var F = function () {}; F.prototype = obj.prototype || obj; return new F(); } // insures the removal of a given method name function remove(obj , name, safe){ // if save is active we need to copy all attributes over. if(safe) { var safeObj = {}; for(var key in obj) { if(key !== name) safeObj[key] = obj[key]; } } else { delete obj[name]; } return safeObj || obj; } // helper for merging two object with each other function extend(oldObj, newObj, preserve) { // failsave if something goes wrong if(!oldObj || !newObj) return oldObj || newObj || {}; // make sure we work with copies oldObj = copy(oldObj); newObj = copy(newObj); for(var key in newObj) { if(Object.prototype.toString.call(newObj[key]) === '[object Object]') { extend(oldObj[key], newObj[key]); } else { // if preserve is set to true oldObj will not be overwritten by newObj if // oldObj has already a method key oldObj[key] = (preserve && oldObj[key]) ? oldObj[key] : newObj[key]; } } return oldObj; } // helper for implementing other classes or objects function implement(array) { var collection = {}; for(var i = 0; i < array.length; i++) { // check if a class is implemented and save its prototype if(typeof(array[i]) === 'function') array[i] = array[i].prototype; // safely remove initialize var safe = remove(array[i], 'initialize', true); // we use implement again if array has the apropriate methiod, otherwise we extend if(safe.implement) { collection = implement(safe.implement); } else { collection = extend(collection, safe); } } return collection; } })();classjs-1.0.0/tests/000077500000000000000000000000001212165172300143145ustar00rootroot00000000000000classjs-1.0.0/tests/index.html000077500000000000000000000012551212165172300163170ustar00rootroot00000000000000 QUnit Test Suite

QUnit Test Suite

  1.  
test markup
classjs-1.0.0/tests/testDemo.html000066400000000000000000000062761212165172300170010ustar00rootroot00000000000000 QUnit Test Suite classjs-1.0.0/tests/testLibs.html000066400000000000000000000021631212165172300167750ustar00rootroot00000000000000 QUnit Test Suite classjs-1.0.0/tests/tests.js000066400000000000000000000225511212165172300160210ustar00rootroot00000000000000/** * @author Angelo Dini * @version 2.0 * @copyright http://www.divio.ch under the BSD Licence */ /** * TESTS */ module("class.js"); test('Core functionality', function() { // tests equal(typeof(window.Class), 'function', 'class is available within the window object'); equal(typeof(Class), 'function', 'Class is available to be called'); equal(objIsEmpty(Class.prototype), true, 'prototype is empty'); testConstructor(Class); }); test('Class constructor', function () { // setup var Animal = new Class(); var Person = new Class({}); var Computer = new Class({ 'calc': function () {} }); // tests equal(typeof(Animal), 'function', 'class is created'); equal(objIsEmpty(Animal.prototype), true, 'animal prototype is empty'); equal(objIsEmpty(Person.prototype), true, 'person prototype is empty'); equal(objIsEmpty(Computer.prototype), false, 'computer prototype is not empty'); ok(!(Animal instanceof Class), 'animal is not an instance of class'); var Correct = new Class({ 'isCorrect': function () {} }); // using strict mode allows it at this point to "forget" the new keyword var Wrong = Class({ 'isWrong': function () {} }); equal(typeof(Correct.prototype.isCorrect), 'function', 'invoking class with new keyword works'); equal(typeof(Wrong.prototype.isWrong), 'function', 'invoking class without the new keyword works'); equal(typeof(new Correct().isCorrect), 'function', 'invoking instance with new keyword works'); // you should not be able to call Wrong().isWrong without the new keyword equal(typeof(new Wrong().isWrong), 'function', 'invoking instance with new keyword works'); testConstructor(Animal); }); test('Class noConflict', function () { // setup var Original = window.Class; var Classy = Class.noConflict(); var Animal = new Classy(); // tests strictEqual(window.Class, undefined, 'noConflict unsets Class from window'); deepEqual(Classy, Original, 'noConflict binds the new variable with Class behaviour'); testConstructor(Animal); ok(true, 'For a live example consult libsTest.html'); window.Class = Original; }); test('Class method extend', function () { // setup var Animal = new Class({ 'initialize': function (name, age) { this.name = name; this.age = age; } }); Animal.extend({ 'eat': function () { return this.name + ' is eating'; }, 'die': function () { return this.name + ' died at age ' + this.age; } }); var name = 'Cat', age = 43, instance = new Animal(name, age); // tests equal(typeof(Animal.prototype.initialize), 'function', 'initialize has been added'); equal(typeof(Animal.prototype.eat), 'function', 'eat has been added'); equal(typeof(Animal.prototype.die), 'function', 'die has been added'); equal(instance.name, name, 'this.name can be called'); equal(instance.age, age, 'this.age can be called'); equal(instance.eat(), name + ' is eating', 'this.eat() can be called'); equal(instance.die(), name + ' died at age ' + age, 'this.die() can be called'); ok(instance instanceof Animal, 'correct instance for class is given'); }); test('Class method implement', function () { // setup var Animal = new Class({ 'initialize': function (name, age) { this.name = name; this.age = age; } }); var essentials = { 'eat': function () { return this.name + ' is eating'; }, 'die': function () { return this.name + ' died at age ' + this.age; } }; var advanced = { 'dance': function () { return this.name + ' is dancing'; }, 'fly': function () { return this.name + ' is flying'; } }; var professional = { 'invincible': true }; Animal.implement([essentials, advanced]); var Cat = new Class({ 'implement': [Animal], // initialize is not passed by implement 'initialize': function (name, age) { this.name = name; this.age = age; }, 'cuteness': function () { return this.name + '\'s level is 99'; } }); Cat.extend({ 'implement': [professional], 'superpower': true }); var myCat = new Cat('Sora', 2); // tests equal(typeof(Cat.prototype.initialize), 'function', 'initialize has been added'); equal(typeof(Cat.prototype.eat), 'function', 'eat has been added'); equal(typeof(Cat.prototype.die), 'function', 'die has been added'); equal(typeof(Cat.prototype.dance), 'function', 'dance has been added'); equal(typeof(Cat.prototype.fly), 'function', 'fly has been added'); equal(typeof(Cat.prototype.cuteness), 'function', 'cuteness has been added'); strictEqual(Cat.prototype.invincible, true, 'cuteness has been added'); strictEqual(Cat.prototype.superpower, true, 'cuteness has been added'); strictEqual(Cat.prototype.implement, undefined, 'implement has not been passed'); equal(myCat.cuteness(), 'Sora\'s level is 99', 'appropriate methods can be called'); }); test('Class method getOptions', function () { // setup var Animal = new Class({ 'options': { 'name': 'Unnamed', 'age': 5 }, 'initialize': function (name, age) { this.name = name || this.options.name; this.age = age || this.options.age; } }); var options = Animal.getOptions(); var Cat = new Animal('Sora', 2); // tests equal(options.name, 'Unnamed', 'option name can be read via getOptions'); equal(options.age, 5, 'option age can be read via getOptions'); equal(Cat.options.name, 'Unnamed', 'option name can be read via method call'); equal(Cat.options.age, 5, 'option age can be read via method call'); equal(Cat.name, 'Sora', 'class name is set correctly'); equal(Cat.age, 2, 'class age is set correctly'); }); test('Class method setOptions', function () { // setup var Animal = new Class({ 'options': { 'name': 'Unnamed', 'age': 5 }, 'initialize': function (name, age) { this.name = name || this.options.name; this.age = age || this.options.age; } }); var Cat = new Animal('Sora', 2); var Dog = new Animal('Pitschy', 1); // tests equal(Cat.options.age, 5, 'option age can be read via method call'); equal(Dog.options.age, 5, 'option age can be read via method call'); Animal.setOptions({ 'age': 10 }); equal(Cat.options.age, 10, 'option age can be read via method call'); equal(Dog.options.age, 10, 'option age can be read via method call'); Animal.setOptions({ 'age': 15 }); equal(Cat.options.age, 15, 'option age can be read via method call'); equal(Dog.options.age, 15, 'option age can be read via method call'); equal(Cat.age, 2, 'correct age is given'); equal(Dog.age, 1, 'correct age is given'); equal(Cat.options.name, 'Unnamed', 'option name can be read via method call'); equal(Dog.options.name, 'Unnamed', 'option name can be read via method call'); ok(Cat instanceof Animal, 'correct instance for class is given'); ok(Dog instanceof Animal, 'correct instance for class is given'); }); test('Class method parent', function () { // setup var Animal = new Class({ 'initialize': function (name, age) { this.name = name; this.age = age; }, 'eat': function () { this.name = 'Pitschy'; return this.name + ' call FIRST eat'; }, 'live': function () { // the return value will be overwritten return this.age + ' call FIRST live'; } }); Animal.extend({ 'die': function () {} }); Animal.extend({ 'eat': function () { this.parent(); return this.name + ' call SECOND eat'; }, 'live': function () { this.parent(); return this.age + ' call SECOND live'; } }); var Cat = new Animal('Sora', 2); // tests equal(Cat.eat(), 'Pitschy call SECOND eat', 'parent works on first invocation'); equal(Cat.live(), '2 call SECOND live', 'parent works on second invocation'); equal(typeof(Cat.die), 'function', 'extending function has been attached'); ok(Cat.parent(), 'parent is attached to the normal object'); }); test('Class method version', function () { // tests equal(typeof(Class.version), 'string', 'Class.version() can be called'); }); test('Class demo examples', function () { var Dimmer = new Class({ initialize: function (container) { this.container = document.getElementById(container); }, showDim: function () { console.log('first'); return 'show dim'; }, hideDim: function () { return 'hide dim'; } }); var Lightbox = new Class({ implement: [Dimmer], initialize: function (container) { this.container = document.getElementById(container); }, show: function () { this.showDim(); }, hide: function () { this.hideDim(); }, hideDim: function () { // this does NOT work, implement overwrites custom methods // if you want to create a custom hideDime use extend on Dimmer this.parent(); return 'hide custom dim'; } }); Lightbox.implement([Dimmer]); var lb = new Lightbox(); // tests equal(lb.hideDim(), 'hide dim', 'implement successfully overwrites the instnace method'); }); test('Cleanup check', function () { // tests equal(typeof(window.Class), 'function', 'class is available within the window object'); equal(typeof(Class), 'function', 'Class is available to be called'); equal(objIsEmpty(Class.prototype), true, 'prototype is empty'); testConstructor(Class); }); /** * HELPERS */ // test if an obj is empty or not function objIsEmpty(obj) { for(var prop in obj) { if(prop) return false; } return true; } // base constructor tests function testConstructor(obj) { equal(typeof(obj.extend), 'function', 'extend is available'); equal(typeof(obj.implement), 'function', 'implement is available'); equal(typeof(obj.setOptions), 'function', 'setOptions is available'); equal(typeof(obj.getOptions), 'function', 'getOptions is available'); }