Repository: daffl/jquery.dform Branch: master Commit: 90d2447bac56 Files: 375 Total size: 1.9 MB Directory structure: gitextract_g3jmq8p2/ ├── .gitignore ├── .npmignore ├── .travis.yml ├── Gruntfile.js ├── bower.json ├── dist/ │ ├── jquery.dform-1.0.1.js │ └── jquery.dform-1.1.0.js ├── package.json ├── readme.md ├── src/ │ ├── dform.converters.js │ ├── dform.core.js │ ├── dform.extensions.js │ └── dform.js ├── start.html └── test/ ├── index.html ├── libs/ │ ├── cultures/ │ │ ├── globalize.culture.af-ZA.js │ │ ├── globalize.culture.af.js │ │ ├── globalize.culture.am-ET.js │ │ ├── globalize.culture.am.js │ │ ├── globalize.culture.ar-AE.js │ │ ├── globalize.culture.ar-BH.js │ │ ├── globalize.culture.ar-DZ.js │ │ ├── globalize.culture.ar-EG.js │ │ ├── globalize.culture.ar-IQ.js │ │ ├── globalize.culture.ar-JO.js │ │ ├── globalize.culture.ar-KW.js │ │ ├── globalize.culture.ar-LB.js │ │ ├── globalize.culture.ar-LY.js │ │ ├── globalize.culture.ar-MA.js │ │ ├── globalize.culture.ar-OM.js │ │ ├── globalize.culture.ar-QA.js │ │ ├── globalize.culture.ar-SA.js │ │ ├── globalize.culture.ar-SY.js │ │ ├── globalize.culture.ar-TN.js │ │ ├── globalize.culture.ar-YE.js │ │ ├── globalize.culture.ar.js │ │ ├── globalize.culture.arn-CL.js │ │ ├── globalize.culture.arn.js │ │ ├── globalize.culture.as-IN.js │ │ ├── globalize.culture.as.js │ │ ├── globalize.culture.az-Cyrl-AZ.js │ │ ├── globalize.culture.az-Cyrl.js │ │ ├── globalize.culture.az-Latn-AZ.js │ │ ├── globalize.culture.az-Latn.js │ │ ├── globalize.culture.az.js │ │ ├── globalize.culture.ba-RU.js │ │ ├── globalize.culture.ba.js │ │ ├── globalize.culture.be-BY.js │ │ ├── globalize.culture.be.js │ │ ├── globalize.culture.bg-BG.js │ │ ├── globalize.culture.bg.js │ │ ├── globalize.culture.bn-BD.js │ │ ├── globalize.culture.bn-IN.js │ │ ├── globalize.culture.bn.js │ │ ├── globalize.culture.bo-CN.js │ │ ├── globalize.culture.bo.js │ │ ├── globalize.culture.br-FR.js │ │ ├── globalize.culture.br.js │ │ ├── globalize.culture.bs-Cyrl-BA.js │ │ ├── globalize.culture.bs-Cyrl.js │ │ ├── globalize.culture.bs-Latn-BA.js │ │ ├── globalize.culture.bs-Latn.js │ │ ├── globalize.culture.bs.js │ │ ├── globalize.culture.ca-ES.js │ │ ├── globalize.culture.ca.js │ │ ├── globalize.culture.co-FR.js │ │ ├── globalize.culture.co.js │ │ ├── globalize.culture.cs-CZ.js │ │ ├── globalize.culture.cs.js │ │ ├── globalize.culture.cy-GB.js │ │ ├── globalize.culture.cy.js │ │ ├── globalize.culture.da-DK.js │ │ ├── globalize.culture.da.js │ │ ├── globalize.culture.de-AT.js │ │ ├── globalize.culture.de-CH.js │ │ ├── globalize.culture.de-DE.js │ │ ├── globalize.culture.de-LI.js │ │ ├── globalize.culture.de-LU.js │ │ ├── globalize.culture.de.js │ │ ├── globalize.culture.dsb-DE.js │ │ ├── globalize.culture.dsb.js │ │ ├── globalize.culture.dv-MV.js │ │ ├── globalize.culture.dv.js │ │ ├── globalize.culture.el-GR.js │ │ ├── globalize.culture.el.js │ │ ├── globalize.culture.en-029.js │ │ ├── globalize.culture.en-AU.js │ │ ├── globalize.culture.en-BZ.js │ │ ├── globalize.culture.en-CA.js │ │ ├── globalize.culture.en-GB.js │ │ ├── globalize.culture.en-IE.js │ │ ├── globalize.culture.en-IN.js │ │ ├── globalize.culture.en-JM.js │ │ ├── globalize.culture.en-MY.js │ │ ├── globalize.culture.en-NZ.js │ │ ├── globalize.culture.en-PH.js │ │ ├── globalize.culture.en-SG.js │ │ ├── globalize.culture.en-TT.js │ │ ├── globalize.culture.en-US.js │ │ ├── globalize.culture.en-ZA.js │ │ ├── globalize.culture.en-ZW.js │ │ ├── globalize.culture.es-AR.js │ │ ├── globalize.culture.es-BO.js │ │ ├── globalize.culture.es-CL.js │ │ ├── globalize.culture.es-CO.js │ │ ├── globalize.culture.es-CR.js │ │ ├── globalize.culture.es-DO.js │ │ ├── globalize.culture.es-EC.js │ │ ├── globalize.culture.es-ES.js │ │ ├── globalize.culture.es-GT.js │ │ ├── globalize.culture.es-HN.js │ │ ├── globalize.culture.es-MX.js │ │ ├── globalize.culture.es-NI.js │ │ ├── globalize.culture.es-PA.js │ │ ├── globalize.culture.es-PE.js │ │ ├── globalize.culture.es-PR.js │ │ ├── globalize.culture.es-PY.js │ │ ├── globalize.culture.es-SV.js │ │ ├── globalize.culture.es-US.js │ │ ├── globalize.culture.es-UY.js │ │ ├── globalize.culture.es-VE.js │ │ ├── globalize.culture.es.js │ │ ├── globalize.culture.et-EE.js │ │ ├── globalize.culture.et.js │ │ ├── globalize.culture.eu-ES.js │ │ ├── globalize.culture.eu.js │ │ ├── globalize.culture.fa-IR.js │ │ ├── globalize.culture.fa.js │ │ ├── globalize.culture.fi-FI.js │ │ ├── globalize.culture.fi.js │ │ ├── globalize.culture.fil-PH.js │ │ ├── globalize.culture.fil.js │ │ ├── globalize.culture.fo-FO.js │ │ ├── globalize.culture.fo.js │ │ ├── globalize.culture.fr-BE.js │ │ ├── globalize.culture.fr-CA.js │ │ ├── globalize.culture.fr-CH.js │ │ ├── globalize.culture.fr-FR.js │ │ ├── globalize.culture.fr-LU.js │ │ ├── globalize.culture.fr-MC.js │ │ ├── globalize.culture.fr.js │ │ ├── globalize.culture.fy-NL.js │ │ ├── globalize.culture.fy.js │ │ ├── globalize.culture.ga-IE.js │ │ ├── globalize.culture.ga.js │ │ ├── globalize.culture.gd-GB.js │ │ ├── globalize.culture.gd.js │ │ ├── globalize.culture.gl-ES.js │ │ ├── globalize.culture.gl.js │ │ ├── globalize.culture.gsw-FR.js │ │ ├── globalize.culture.gsw.js │ │ ├── globalize.culture.gu-IN.js │ │ ├── globalize.culture.gu.js │ │ ├── globalize.culture.ha-Latn-NG.js │ │ ├── globalize.culture.ha-Latn.js │ │ ├── globalize.culture.ha.js │ │ ├── globalize.culture.he-IL.js │ │ ├── globalize.culture.he.js │ │ ├── globalize.culture.hi-IN.js │ │ ├── globalize.culture.hi.js │ │ ├── globalize.culture.hr-BA.js │ │ ├── globalize.culture.hr-HR.js │ │ ├── globalize.culture.hr.js │ │ ├── globalize.culture.hsb-DE.js │ │ ├── globalize.culture.hsb.js │ │ ├── globalize.culture.hu-HU.js │ │ ├── globalize.culture.hu.js │ │ ├── globalize.culture.hy-AM.js │ │ ├── globalize.culture.hy.js │ │ ├── globalize.culture.id-ID.js │ │ ├── globalize.culture.id.js │ │ ├── globalize.culture.ig-NG.js │ │ ├── globalize.culture.ig.js │ │ ├── globalize.culture.ii-CN.js │ │ ├── globalize.culture.ii.js │ │ ├── globalize.culture.is-IS.js │ │ ├── globalize.culture.is.js │ │ ├── globalize.culture.it-CH.js │ │ ├── globalize.culture.it-IT.js │ │ ├── globalize.culture.it.js │ │ ├── globalize.culture.iu-Cans-CA.js │ │ ├── globalize.culture.iu-Cans.js │ │ ├── globalize.culture.iu-Latn-CA.js │ │ ├── globalize.culture.iu-Latn.js │ │ ├── globalize.culture.iu.js │ │ ├── globalize.culture.ja-JP.js │ │ ├── globalize.culture.ja.js │ │ ├── globalize.culture.ka-GE.js │ │ ├── globalize.culture.ka.js │ │ ├── globalize.culture.kk-KZ.js │ │ ├── globalize.culture.kk.js │ │ ├── globalize.culture.kl-GL.js │ │ ├── globalize.culture.kl.js │ │ ├── globalize.culture.km-KH.js │ │ ├── globalize.culture.km.js │ │ ├── globalize.culture.kn-IN.js │ │ ├── globalize.culture.kn.js │ │ ├── globalize.culture.ko-KR.js │ │ ├── globalize.culture.ko.js │ │ ├── globalize.culture.kok-IN.js │ │ ├── globalize.culture.kok.js │ │ ├── globalize.culture.ky-KG.js │ │ ├── globalize.culture.ky.js │ │ ├── globalize.culture.lb-LU.js │ │ ├── globalize.culture.lb.js │ │ ├── globalize.culture.lo-LA.js │ │ ├── globalize.culture.lo.js │ │ ├── globalize.culture.lt-LT.js │ │ ├── globalize.culture.lt.js │ │ ├── globalize.culture.lv-LV.js │ │ ├── globalize.culture.lv.js │ │ ├── globalize.culture.mi-NZ.js │ │ ├── globalize.culture.mi.js │ │ ├── globalize.culture.mk-MK.js │ │ ├── globalize.culture.mk.js │ │ ├── globalize.culture.ml-IN.js │ │ ├── globalize.culture.ml.js │ │ ├── globalize.culture.mn-Cyrl.js │ │ ├── globalize.culture.mn-MN.js │ │ ├── globalize.culture.mn-Mong-CN.js │ │ ├── globalize.culture.mn-Mong.js │ │ ├── globalize.culture.mn.js │ │ ├── globalize.culture.moh-CA.js │ │ ├── globalize.culture.moh.js │ │ ├── globalize.culture.mr-IN.js │ │ ├── globalize.culture.mr.js │ │ ├── globalize.culture.ms-BN.js │ │ ├── globalize.culture.ms-MY.js │ │ ├── globalize.culture.ms.js │ │ ├── globalize.culture.mt-MT.js │ │ ├── globalize.culture.mt.js │ │ ├── globalize.culture.nb-NO.js │ │ ├── globalize.culture.nb.js │ │ ├── globalize.culture.ne-NP.js │ │ ├── globalize.culture.ne.js │ │ ├── globalize.culture.nl-BE.js │ │ ├── globalize.culture.nl-NL.js │ │ ├── globalize.culture.nl.js │ │ ├── globalize.culture.nn-NO.js │ │ ├── globalize.culture.nn.js │ │ ├── globalize.culture.no.js │ │ ├── globalize.culture.nso-ZA.js │ │ ├── globalize.culture.nso.js │ │ ├── globalize.culture.oc-FR.js │ │ ├── globalize.culture.oc.js │ │ ├── globalize.culture.or-IN.js │ │ ├── globalize.culture.or.js │ │ ├── globalize.culture.pa-IN.js │ │ ├── globalize.culture.pa.js │ │ ├── globalize.culture.pl-PL.js │ │ ├── globalize.culture.pl.js │ │ ├── globalize.culture.prs-AF.js │ │ ├── globalize.culture.prs.js │ │ ├── globalize.culture.ps-AF.js │ │ ├── globalize.culture.ps.js │ │ ├── globalize.culture.pt-BR.js │ │ ├── globalize.culture.pt-PT.js │ │ ├── globalize.culture.pt.js │ │ ├── globalize.culture.qut-GT.js │ │ ├── globalize.culture.qut.js │ │ ├── globalize.culture.quz-BO.js │ │ ├── globalize.culture.quz-EC.js │ │ ├── globalize.culture.quz-PE.js │ │ ├── globalize.culture.quz.js │ │ ├── globalize.culture.rm-CH.js │ │ ├── globalize.culture.rm.js │ │ ├── globalize.culture.ro-RO.js │ │ ├── globalize.culture.ro.js │ │ ├── globalize.culture.ru-RU.js │ │ ├── globalize.culture.ru.js │ │ ├── globalize.culture.rw-RW.js │ │ ├── globalize.culture.rw.js │ │ ├── globalize.culture.sa-IN.js │ │ ├── globalize.culture.sa.js │ │ ├── globalize.culture.sah-RU.js │ │ ├── globalize.culture.sah.js │ │ ├── globalize.culture.se-FI.js │ │ ├── globalize.culture.se-NO.js │ │ ├── globalize.culture.se-SE.js │ │ ├── globalize.culture.se.js │ │ ├── globalize.culture.si-LK.js │ │ ├── globalize.culture.si.js │ │ ├── globalize.culture.sk-SK.js │ │ ├── globalize.culture.sk.js │ │ ├── globalize.culture.sl-SI.js │ │ ├── globalize.culture.sl.js │ │ ├── globalize.culture.sma-NO.js │ │ ├── globalize.culture.sma-SE.js │ │ ├── globalize.culture.sma.js │ │ ├── globalize.culture.smj-NO.js │ │ ├── globalize.culture.smj-SE.js │ │ ├── globalize.culture.smj.js │ │ ├── globalize.culture.smn-FI.js │ │ ├── globalize.culture.smn.js │ │ ├── globalize.culture.sms-FI.js │ │ ├── globalize.culture.sms.js │ │ ├── globalize.culture.sq-AL.js │ │ ├── globalize.culture.sq.js │ │ ├── globalize.culture.sr-Cyrl-BA.js │ │ ├── globalize.culture.sr-Cyrl-CS.js │ │ ├── globalize.culture.sr-Cyrl-ME.js │ │ ├── globalize.culture.sr-Cyrl-RS.js │ │ ├── globalize.culture.sr-Cyrl.js │ │ ├── globalize.culture.sr-Latn-BA.js │ │ ├── globalize.culture.sr-Latn-CS.js │ │ ├── globalize.culture.sr-Latn-ME.js │ │ ├── globalize.culture.sr-Latn-RS.js │ │ ├── globalize.culture.sr-Latn.js │ │ ├── globalize.culture.sr.js │ │ ├── globalize.culture.sv-FI.js │ │ ├── globalize.culture.sv-SE.js │ │ ├── globalize.culture.sv.js │ │ ├── globalize.culture.sw-KE.js │ │ ├── globalize.culture.sw.js │ │ ├── globalize.culture.syr-SY.js │ │ ├── globalize.culture.syr.js │ │ ├── globalize.culture.ta-IN.js │ │ ├── globalize.culture.ta.js │ │ ├── globalize.culture.te-IN.js │ │ ├── globalize.culture.te.js │ │ ├── globalize.culture.tg-Cyrl-TJ.js │ │ ├── globalize.culture.tg-Cyrl.js │ │ ├── globalize.culture.tg.js │ │ ├── globalize.culture.th-TH.js │ │ ├── globalize.culture.th.js │ │ ├── globalize.culture.tk-TM.js │ │ ├── globalize.culture.tk.js │ │ ├── globalize.culture.tn-ZA.js │ │ ├── globalize.culture.tn.js │ │ ├── globalize.culture.tr-TR.js │ │ ├── globalize.culture.tr.js │ │ ├── globalize.culture.tt-RU.js │ │ ├── globalize.culture.tt.js │ │ ├── globalize.culture.tzm-Latn-DZ.js │ │ ├── globalize.culture.tzm-Latn.js │ │ ├── globalize.culture.tzm.js │ │ ├── globalize.culture.ug-CN.js │ │ ├── globalize.culture.ug.js │ │ ├── globalize.culture.uk-UA.js │ │ ├── globalize.culture.uk.js │ │ ├── globalize.culture.ur-PK.js │ │ ├── globalize.culture.ur.js │ │ ├── globalize.culture.uz-Cyrl-UZ.js │ │ ├── globalize.culture.uz-Cyrl.js │ │ ├── globalize.culture.uz-Latn-UZ.js │ │ ├── globalize.culture.uz-Latn.js │ │ ├── globalize.culture.uz.js │ │ ├── globalize.culture.vi-VN.js │ │ ├── globalize.culture.vi.js │ │ ├── globalize.culture.wo-SN.js │ │ ├── globalize.culture.wo.js │ │ ├── globalize.culture.xh-ZA.js │ │ ├── globalize.culture.xh.js │ │ ├── globalize.culture.yo-NG.js │ │ ├── globalize.culture.yo.js │ │ ├── globalize.culture.zh-CHS.js │ │ ├── globalize.culture.zh-CHT.js │ │ ├── globalize.culture.zh-CN.js │ │ ├── globalize.culture.zh-HK.js │ │ ├── globalize.culture.zh-Hans.js │ │ ├── globalize.culture.zh-Hant.js │ │ ├── globalize.culture.zh-MO.js │ │ ├── globalize.culture.zh-SG.js │ │ ├── globalize.culture.zh-TW.js │ │ ├── globalize.culture.zh.js │ │ ├── globalize.culture.zu-ZA.js │ │ ├── globalize.culture.zu.js │ │ └── globalize.cultures.js │ └── globalize.js ├── test.js ├── test.json ├── test_extensions.js ├── test_jqueryui.js ├── test_subscribers.js └── test_types.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .project *.settings/ /.project /.project /build/compiler** tmp/** docs** .idea node_modules testee.log ================================================ FILE: .npmignore ================================================ .idea/ ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - 0.10 ================================================ FILE: Gruntfile.js ================================================ module.exports = function (grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), connect: { server: { options: { port: 9001, base: '.' } } }, qunit: { all: { options: { urls: ['http://localhost:9001/test/index.html'] } } }, concat: { dist: { src: ['src/dform.js', 'src/dform.core.js', 'src/dform.extensions.js'], dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.js' } }, uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, build: { src: ['dist/<%= pkg.name %>-<%= pkg.version %>.js'], dest: 'dist/<%= pkg.name %>-<%= pkg.version %>.min.js' } } }); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-qunit'); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.registerTask('test', ['connect', 'qunit']); grunt.registerTask('default', ['concat', 'uglify']); }; ================================================ FILE: bower.json ================================================ { "name": "jquery.dform", "version": "1.1.0", "main": "dist/jquery.dform-1.1.0.js", "ignore": [ ".jshintrc", "**/*.txt" ], "dependencies": { "jquery": ">= 1.7.1" } } ================================================ FILE: dist/jquery.dform-1.0.1.js ================================================ /* * jQuery dform plugin * Copyright (C) 2012 David Luecke , [http://daffl.github.com/jquery.dform] * * Licensed under the MIT license */ (function ($) { var _subscriptions = {}, _types = {}, each = $.each, addToObject = function (obj) { var result = function (data, fn, condition) { if (typeof data === 'object') { $.each(data, function (name, val) { result(name, val, condition); }); } else if (condition === undefined || condition === true) { if (!obj[data]) { obj[data] = []; } obj[data].push(fn); } } return result; }, isArray = $.isArray, /** * Returns an array of keys (properties) contained in the given object. * * @param {Object} object The object to use * @return {Array} An array containing all properties in the object */ keyset = function (object) { return $.map(object, function (val, key) { return key; }); }, /** * Returns an object that contains all values from the given * object that have a key which is also in the array keys. * * @param {Object} object The object to traverse * @param {Array} keys The keys the new object should contain * @return {Object} A new object containing only the properties * with names given in keys */ withKeys = function (object, keys) { var result = {}; each(keys, function (index, value) { if (object[value]) { result[value] = object[value]; } }); return result; }, /** * Returns an object that contains all value from the given * object that do not have a key which is also in the array keys. * * @param {Object} object The object to traverse * @param {Array} keys A list of keys that should not be contained in the new object * @return {Object} A new object with all properties of the given object, except * for the ones given in the list of keys */ withoutKeys = function (object, keys) { var result = {}; each(object, function (index, value) { if (!~$.inArray(index, keys)) { result[index] = value; } }); return result; }, /** * Run all subscriptions with the given name and options * on an element. * * @param {String} name The name of the subscriber function * @param {Object} options ptions for the function * @param {String} type The type of the current element as in the registered types * @return {Object} The jQuery object */ runSubscription = function (name, options, type) { if ($.dform.hasSubscription(name)) { this.each(function () { var element = $(this); each(_subscriptions[name], function (i, sfn) { // run subscriber function with options sfn.call(element, options, type); }); }); } return this; }, /** * Run all subscription functions with given options. * * @param {Object} options The options to use * @return {Object} The jQuery element this function has been called on */ runAll = function (options) { var type = options.type, self = this; // Run preprocessing subscribers this.dform('run', '[pre]', options, type); each(options, function (name, sopts) { self.dform('run', name, sopts, type); }); // Run post processing subscribers this.dform('run', '[post]', options, type); return this; }; /** * Globals added directly to the jQuery object */ $.extend($, { keyset : keyset, withKeys : withKeys, withoutKeys : withoutKeys, dform : { /** * Default options the plugin is initialized with: * * ## prefix * * The Default prefix used for element classnames generated by the dform plugin. * Defaults to _ui-dform-_ * E.g. an element with type text will have the class ui-dform-text * */ options : { prefix : "ui-dform-" }, /** * A function that is called, when no registered type has been found. * The default behaviour returns an HTML element with the tag * as specified in type and the HTML attributes given in options * (without subscriber options). * * @param {Object} options * @return {Object} The created object */ defaultType : function (options) { return $("<" + options.type + ">").dform('attr', options); }, /** * Return all types. * * @params {String} name (optional) If passed return * all type generators for a given name. * @return {Object} Mapping from type name to * an array of generator functions. */ types : function (name) { return name ? _types[name ] : _types; }, /** * Register an element type function. * * @param {String|Array} data Can either be the name of the type * function or an object that contains name : type function pairs * @param {Function} fn The function that creates a new type element */ addType : addToObject(_types), /** * Returns all subscribers or all subscribers for a given name. * * @params {String} name (optional) If passed return all * subscribers for a given name * @return {Object} Mapping from subscriber names * to an array of subscriber functions. */ subscribers : function (name) { return name ? _subscriptions[name] : _subscriptions; }, /** * Register a subscriber function. * * @param {String|Object} data Can either be the name of the subscriber * function or an object that contains name : subscriber function pairs * @param {Function} fn The function to subscribe or nothing if an object is passed for data * @param {Array} deps An optional list of dependencies */ subscribe : addToObject(_subscriptions), /** * Returns if a subscriber function with the given name * has been registered. * * @param {String} name The subscriber name * @return {Boolean} True if the given name has at least one subscriber registered, * false otherwise */ hasSubscription : function (name) { return _subscriptions[name] ? true : false; }, /** * Create a new element. * * @param {Object} options - The options to use * @return {Object} The element as created by the builder function specified * or returned by the defaultType function. */ createElement : function (options) { if (!options.type) { throw "No element type given! Must always exist."; } var type = options.type, element = null, // We don't need the type key in the options opts = $.withoutKeys(options, ["type"]); if (_types[type]) { // Run all type element builder functions called typename each(_types[type], function (i, sfn) { element = sfn.call(element, opts); }); } else { // Call defaultType function if no type was found element = $.dform.defaultType(options); } return $(element); }, methods : { /** * Run all subscriptions with the given name and options * on an element. * * @param {String} name The name of the subscriber function * @param {Object} options ptions for the function * @param {String} type The type of the current element as in the registered types * @return {Object} The jQuery object */ run : function (name, options, type) { if (typeof name !== 'string') { return runAll.call(this, name); } return runSubscription.call(this, name, options, type); }, /** * Creates a form element on an element with given options * * @param {Object} options The options to use * @return {Object} The jQuery element this function has been called on */ append : function (options, converter) { if (converter && $.dform.converters && $.isFunction($.dform.converters[converter])) { options = $.dform.converters[converter](options); } // Create element (run builder function for type) var element = $.dform.createElement(options); this.append(element); // Run all subscriptions element.dform('run', options); }, /** * Adds HTML attributes to the current element from the given options. * Any subscriber will be omitted so that the attributes will contain any * key value pair where the key is not the name of a subscriber function * and is not in the string array excludes. * * @param {Object} object The attribute object * @param {Array} excludes A list of keys that should also be excluded * @return {Object} The jQuery object of the this reference */ attr : function (object, excludes) { // Ignore any subscriber name and the objects given in excludes var ignores = $.keyset(_subscriptions); isArray(excludes) && $.merge(ignores, excludes); this.attr($.withoutKeys(object, ignores)); }, /** * * * @param params * @param success * @param error */ ajax : function (params, success, error) { var options = { error : error, url : params }, self = this; if (typeof params !== 'string') { $.extend(options, params); } options.success = function (data) { self.dform(data); if(success) { success.call(self, data); } } $.ajax(options); }, /** * * * @param options */ init : function (options, converter) { var opts = options.type ? options : $.extend({ "type" : "form" }, options); if (converter && $.dform.converters && $.isFunction($.dform.converters[converter])) { opts = $.dform.converters[converter](opts); } if (this.is(opts.type)) { this.dform('attr', opts); this.dform('run', opts); } else { this.dform('append', opts); } } } } }); /** * The jQuery plugin function * * @param options The form options * @param {String} converter The name of the converter in $.dform.converters * that will be used to convert the options */ $.fn.dform = function (options, converter, error) { var self = $(this); if ($.dform.methods[options]) { $.dform.methods[options].apply(self, Array.prototype.slice.call(arguments, 1)); } else { if (typeof options === 'string') { $.dform.methods.ajax.call(self, { url : options, dataType : 'json' }, converter, error); } else { $.dform.methods.init.apply(self, arguments); } } return this; } })(jQuery); /* * jQuery dform plugin * Copyright (C) 2012 David Luecke , [http://daffl.github.com/jquery.dform] * * Licensed under the MIT license */ (function ($) { var each = $.each, _element = function (tag, excludes) { return function (ops) { return $(tag).dform('attr', ops, excludes); }; }, _html = function (options, type) { var self = this; if ($.isPlainObject(options)) { self.dform('append', options); } else if ($.isArray(options)) { each(options, function (index, nested) { self.dform('append', nested); }); } else { self.html(options); } }; $.dform.addType({ container : _element("
"), text : _element(''), password : _element(''), submit : _element(''), reset : _element(''), hidden : _element(''), radio : _element(''), checkbox : _element(''), file : _element(''), number : _element(''), url : _element(''), tel : _element(''), email : _element(''), checkboxes : _element("
", ["name"]), radiobuttons : _element("
", ["name"]) }); $.dform.subscribe({ /** * Adds a class to the current element. * Ovverrides the default behaviour which would be replacing the class attribute. * * @param options A list of whitespace separated classnames * @param type The type of the *this* element */ "class" : function (options, type) { this.addClass(options); }, /** * Sets html content of the current element * * @param options The html content to set as a string * @param type The type of the *this* element */ "html" : _html, /** * Recursively appends subelements to the current form element. * * @param options Either an object with key value pairs * where the key is the element name and the value the * subelement options or an array of objects where each object * is the options for a subelement * @param type The type of the *this* element */ "elements" : _html, /** * Sets the value of the current element. * * @param options The value to set * @param type The type of the *this* element */ "value" : function (options) { this.val(options); }, /** * Set CSS styles for the current element * * @param options The Styles to set * @param type The type of the *this* element */ "css" : function (options) { this.css(options); }, /** * Adds options to select type elements or radio and checkbox list elements. * * @param options A key value pair where the key is the * option value and the value the options text or the settings for the element. * @param type The type of the *this* element */ "options" : function (options, type) { var self = this; // Options for select elements if ((type === "select" || type === "optgroup") && typeof options !== 'string') { each(options, function (value, content) { var option = { type : 'option', value : value }; if (typeof (content) === "string") { option.html = content; } if (typeof (content) === "object") { option = $.extend(option, content); } self.dform('append', option); }); } else if (type === "checkboxes" || type === "radiobuttons") { // Options for checkbox and radiobutton lists each(options, function (value, content) { var boxoptions = ((type === "radiobuttons") ? { "type" : "radio" } : { "type" : "checkbox" }); if (typeof(content) === "string") { boxoptions["caption"] = content; } else { $.extend(boxoptions, content); } boxoptions["value"] = value; self.dform('append', boxoptions); }); } }, /** * Adds caption to elements. * * Depending on the element type the following elements will * be used: * - A legend for
elements * - A