From b8034645da3c1a0fbca384d50a4e5a2d8542aa4a Mon Sep 17 00:00:00 2001 From: David Luecke Date: Wed, 9 Jan 2013 09:32:30 -0700 Subject: [PATCH 01/21] Moving away from GitHub downloads --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cf1c213..15166e9 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ __Some things you can do:__ ## Get started -[Download the latest version 1.0.0](https://github.com/downloads/daffl/jquery.dform/jquery.dform-1.0.0.min.js) +[Download the latest version 1.0.0](https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-1.0.1.min.js) (~7 Kb minified) Include it in your jQuery powered page and try this: From 28345788daad0d684735e6cd50ea4cc6bf99e079 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 17 Jan 2013 09:39:13 -0700 Subject: [PATCH 02/21] Updating readme --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 7ad0d83..dbf29d0 100644 --- a/readme.md +++ b/readme.md @@ -569,7 +569,7 @@ The caption in each entries element will be used as the tab heading. You can eit of entries and set the *id* attribute individually or an object which will use the key name as the id: { - "type" : "accordion", + "type" : "tabs", "entries" : [ { "caption" : "Tab 1", @@ -587,7 +587,7 @@ of entries and set the *id* attribute individually or an object which will use t Which is equivalent to: { - "type" : "accordion", + "type" : "tabs", "entries" : { "first": { "caption" : "Tab 1", @@ -597,7 +597,7 @@ Which is equivalent to: "caption" : "Tab 2", "html" : "Content 2" } - ] + } } ### Subscribers @@ -777,4 +777,4 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -[![Build Status](https://secure.travis-ci.org/daffl/uberproto.png)](http://travis-ci.org/daffl/uberproto) +[![Build Status](https://secure.travis-ci.org/daffl/jquery.dform.png)](http://travis-ci.org/daffl/jquery.dform) From 6f3a3333b7613a031fce20792c208ddbeb25682e Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 17 Jan 2013 23:16:24 -0700 Subject: [PATCH 03/21] Updated docs, jQuery plugin information --- dform.jquery.json | 29 +++++++++++++++++++++++++++++ readme.md | 19 ++++++++++++++++--- test/index.html | 4 ++-- test/test_subscribers.js | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 dform.jquery.json diff --git a/dform.jquery.json b/dform.jquery.json new file mode 100644 index 0000000..4445196 --- /dev/null +++ b/dform.jquery.json @@ -0,0 +1,29 @@ +{ + "name" : "dForm", + "title" : "jQuery.dForm", + "description" : "A flexible JavaScript Object and JSON to HTML converter with a focus on forms", + "keywords" : [ + "ui", + "form", + "json" + ], + "version" : "1.0.1", + "author" : { + "name" : "David Luecke", + "url" : "https://github.com/daffl" + }, + "licenses" : [ + { + "type" : "MIT", + "url" : "http://daffl.github.com/jquery.dform/#license" + } + ], + "bugs" : "https://github.com/daffl/jquery.dform/issues", + "homepage" : "http://daffl.github.com/jquery.dform", + "demo" : "http://jsfiddle.net/Zt4Rz/", + "docs" : "http://daffl.github.com/jquery.dform", + "download" : "https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-1.0.1.js", + "dependencies" : { + "jquery" : ">=1.7" + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index 7324d89..a1b3a11 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,8 @@ __Some things you can do:__ ## Get started -[Download the latest version 1.0.0](https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-1.0.1.min.js) +[Download the latest version 1.0.1](https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-1.0.1.js) +([min](https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-1.0.1.min.js)) (~7 Kb minified) Include it in your jQuery powered page and try this: @@ -61,9 +62,14 @@ Or to quickly load an external form definition:
+ +__Demo:__ + + + __Learn more:__ -* Play around with this example [as a JSFiddle](http://jsfiddle.net/Zt4Rz/) +* Visit the above example [on jsfiddle.com](http://jsfiddle.net/Daff/Zt4Rz/) * Visit the [jQuery.dForm Group](http://groups.google.com/group/jquery-dform) * Watch and fork the project on [GitHub](http://github.com/daffl/jquery.dform/) * Follow [@daffl](http://twitter.com/daffl) on Twitter @@ -698,6 +704,13 @@ Generates: ## Changelog +__1.0.1__ + +* Updated and fixed documentation +* Added [jQuery plugin](http://plugins.jquery.com) deploy information +* Moved away from GitHub downloads +* Verified jQuery 1.9.0 compatibility + __1.0.0__ * Improved documentation using DocumentUp @@ -754,7 +767,7 @@ __0.1__ ## License -Copyright (C) 2012 [David Luecke](http://daffl.github.com), [http://daffl.github.com/jquery.dform] +Copyright (C) 2013 [David Luecke](http://daffl.github.com), [http://daffl.github.com/jquery.dform] The MIT license: diff --git a/test/index.html b/test/index.html index 15b87d0..ec4e566 100644 --- a/test/index.html +++ b/test/index.html @@ -3,10 +3,10 @@ - + - + diff --git a/test/test_subscribers.js b/test/test_subscribers.js index 78368b2..5217e62 100644 --- a/test/test_subscribers.js +++ b/test/test_subscribers.js @@ -36,7 +36,7 @@ $(document).ready(function () { ok(div.hasClass('test'), 'Class set'); ok(div.hasClass($.dform.options.prefix + 'container'), 'Class set'); equal(text.val(), 'Test value', 'Value set'); - equal(text.css('background-color'), 'red', 'Css set'); + ok(text.css('background-color'), 'Css set'); }); test("elements and html", function () { From e67d8410d568e0fdd01d88fba4ca9c920753fc19 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 24 Jan 2013 22:35:13 -0700 Subject: [PATCH 04/21] Fixing name --- dform.jquery.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dform.jquery.json b/dform.jquery.json index 4445196..a74ea2b 100644 --- a/dform.jquery.json +++ b/dform.jquery.json @@ -1,5 +1,5 @@ { - "name" : "dForm", + "name" : "dform", "title" : "jQuery.dForm", "description" : "A flexible JavaScript Object and JSON to HTML converter with a focus on forms", "keywords" : [ From 74d28ccf4b97aa8a8128816fc3c5ee3037a33e15 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 7 Mar 2013 23:18:40 -0700 Subject: [PATCH 05/21] Updating to Grunt 0.4.0 --- Gruntfile.js | 31 +++++++++++++++++++++++++++++++ grunt.js | 24 ------------------------ package.json | 35 +++++++++++++++++++---------------- 3 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 Gruntfile.js delete mode 100644 grunt.js diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..de4f52c --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,31 @@ +module.exports = function (grunt) { + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + qunit: { + all: ['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.registerTask('test', 'qunit'); + grunt.registerTask('default', ['concat', 'uglify']); +}; diff --git a/grunt.js b/grunt.js deleted file mode 100644 index d3b4ef0..0000000 --- a/grunt.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = function (grunt) { - grunt.initConfig({ - pkg : '', - qunit : { - all : ['test/index.html'] - }, - concat : { - dist : { - src : ['src/dform.js', 'src/dform.core.js', 'src/dform.extensions.js'], - dest : 'dist/<%= pkg.name %>-<%= pkg.version %>.js' - } - }, - min : { - dist : { - src : ['dist/<%= pkg.name %>-<%= pkg.version %>.js'], - dest : 'dist/<%= pkg.name %>-<%= pkg.version %>.min.js' - } - } - - }); - - grunt.registerTask('test', 'qunit'); - grunt.registerTask('default', 'concat min'); -}; diff --git a/package.json b/package.json index ecdc249..877db5f 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,21 @@ { - "name": "jquery.dform", - "description": "A flexible JavaScript Object and JSON to HTML converter with a focus on forms", - "version": "1.0.1", - "homepage": "http://daffl.github.com/jquery.dform", - "author": "David Luecke", - "license" : "MIT", - "scripts" : { - "test" : "grunt test" - }, - "repository": { - "type": "git", - "url": "https://github.com/daffl/jquery.dform.git" - }, - "devDependencies" : { - "grunt" : "> 0.3.0" - } + "name": "jquery.dform", + "description": "A flexible JavaScript Object and JSON to HTML converter with a focus on forms", + "version": "1.0.1", + "homepage": "http://daffl.github.com/jquery.dform", + "author": "David Luecke", + "license": "MIT", + "scripts": { + "test": "grunt test" + }, + "repository": { + "type": "git", + "url": "https://github.com/daffl/jquery.dform.git" + }, + "devDependencies": { + "grunt": "> 0.3.0", + "grunt-contrib-concat": "*", + "grunt-contrib-uglify": "*", + "grunt-contrib-qunit": "*" + } } From d44f15c39338d0e486401b6be2579c700d181728 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Fri, 8 Mar 2013 08:19:17 -0700 Subject: [PATCH 06/21] Fix test command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 877db5f..830e303 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "author": "David Luecke", "license": "MIT", "scripts": { - "test": "grunt test" + "test": "grunt qunit" }, "repository": { "type": "git", From 71d293bd0c3a2ab5f1ed480f61a3b5e50bb50fa3 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Fri, 8 Mar 2013 09:38:34 -0700 Subject: [PATCH 07/21] Grunt 0.4.0 CI, another try --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 830e303..a5c31e7 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "url": "https://github.com/daffl/jquery.dform.git" }, "devDependencies": { - "grunt": "> 0.3.0", + "grunt": "~ 0.4.0", + "grunt-cli": "~ 0.1.0", "grunt-contrib-concat": "*", "grunt-contrib-uglify": "*", "grunt-contrib-qunit": "*" From 77fb823e69ba18b0e428cbe81656910669323078 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 4 Jun 2013 20:47:02 -0600 Subject: [PATCH 08/21] Use error handler. Closes #35 --- .gitignore | 1 + readme.md | 6 +++--- src/dform.js | 20 ++++++++++---------- test/test.js | 5 ++++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3620798..8e469a5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ tmp/** docs** .idea node_modules +testee.log \ No newline at end of file diff --git a/readme.md b/readme.md index a1b3a11..c7dbd5d 100644 --- a/readme.md +++ b/readme.md @@ -442,9 +442,9 @@ Append the dForm object to each selected element. If the element is of the same a `type : 'form'` on a `
`) or if no type has been given run the subscribers and add the attributes on the current element. Optionally use a converter with a given name. -**$(form).dform(url \[, success\])** *{String}* *{Function}*
-Load a JSON form definition using GET from a given URL and execute a success handler when it returns. -The handler gets the data passed and has `this` refer to the form element. +**$(form).dform(url \[, success\], \[, error\])** *{String}* *{Function}* *{Function}*
+Load a JSON form definition using GET from a given URL and execute a success handler when it returns +or an error handler if the request faiuls. The handler gets the data passed and has `this` refer to the form element. **$(form).dform('run', options)** *{Object}*
Run all subscribers from a given dForm object on the selected element(s). diff --git a/src/dform.js b/src/dform.js index 77f85f6..761e780 100644 --- a/src/dform.js +++ b/src/dform.js @@ -30,7 +30,7 @@ * @param {Object} object The object to use * @return {Array} An array containing all properties in the object */ - keyset = function (object) { + keyset = function (object) { return $.map(object, function (val, key) { return key; }); @@ -44,7 +44,7 @@ * @return {Object} A new object containing only the properties * with names given in keys */ - withKeys = function (object, keys) { + withKeys = function (object, keys) { var result = {}; each(keys, function (index, value) { if (object[value]) { @@ -80,7 +80,7 @@ * @param {String} type The type of the current element as in the registered types * @return {Object} The jQuery object */ - runSubscription = function (name, options, type) { + runSubscription = function (name, options, type) { if ($.dform.hasSubscription(name)) { this.each(function () { var element = $(this); @@ -98,7 +98,7 @@ * @param {Object} options The options to use * @return {Object} The jQuery element this function has been called on */ - runAll = function (options) { + runAll = function (options) { var type = options.type, self = this; // Run preprocessing subscribers this.dform('run', '[pre]', options, type); @@ -278,18 +278,18 @@ */ ajax : function (params, success, error) { var options = { + success: function (data) { + self.dform(data); + if(success) { + success.call(self, data); + } + }, 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); }, /** diff --git a/test/test.js b/test/test.js index 9c2a354..331aa75 100644 --- a/test/test.js +++ b/test/test.js @@ -61,7 +61,10 @@ $(document).ready(function () { $('
').dform('test.json', function(data) { equal(data.html, 'The test', 'Data passed to success callback'); equal(this.html(), 'The test', 'Form got created'); - start(); + $('
').dform('missing.json', function() {}, function() { + ok(true, 'Error handler called'); + start(); + }); }); }) }); From f99e55d8491bda2d0829f7f5215dfd95f0144bb3 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 4 Jun 2013 21:53:06 -0600 Subject: [PATCH 09/21] Adding url subscriber. Closes #22 --- readme.md | 8 ++++++++ src/dform.core.js | 5 ++--- src/dform.js | 15 ++++++++------- test/test.js | 2 +- test/test_subscribers.js | 26 ++++++++++++++++++++------ 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/readme.md b/readme.md index c7dbd5d..c548110 100644 --- a/readme.md +++ b/readme.md @@ -375,6 +375,14 @@ Generates: Address +**url** *{String|Object}*
+The `url` subscriber issues a `$(element).dform('ajax', options)` request to load content from remote files. + + { + "type" : "div", + "url": "form.json" + } + **type** *{String}*
Besides looking up the correct Type Generator it also adds a dform specific class to the element using `$.dform.options.prefix` (*ui-dform-* by default) and the type name. diff --git a/src/dform.core.js b/src/dform.core.js index 35fe916..4f788cb 100644 --- a/src/dform.core.js +++ b/src/dform.core.js @@ -195,10 +195,9 @@ * @param options * @param type */ - "url" : function (options, type) { - // TODO this.buildForm(options); + "url" : function (options) { + this.dform('ajax', options); }, - /** * Post processing function, that will run whenever all other subscribers are finished. * diff --git a/src/dform.js b/src/dform.js index 761e780..5d4d789 100644 --- a/src/dform.js +++ b/src/dform.js @@ -62,7 +62,7 @@ * @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) { + withoutKeys = function (object, keys) { var result = {}; each(object, function (index, value) { if (!~$.inArray(index, keys)) { @@ -278,18 +278,19 @@ */ ajax : function (params, success, error) { var options = { - success: function (data) { - self.dform(data); - if(success) { - success.call(self, data); - } - }, error : error, url : params }, self = this; if (typeof params !== 'string') { $.extend(options, params); } + options.success = function (data) { + var callback = success || params.success; + self.dform(data); + if(callback) { + callback.call(self, data); + } + } $.ajax(options); }, /** diff --git a/test/test.js b/test/test.js index 331aa75..5f993bb 100644 --- a/test/test.js +++ b/test/test.js @@ -56,7 +56,7 @@ $(document).ready(function () { equal(created.data('test'), 'Test data attribute', 'Added test data attribute'); }); - test("Ajax", 2, function() { + test("Ajax", 3, function() { stop(); $('
').dform('test.json', function(data) { equal(data.html, 'The test', 'Data passed to success callback'); diff --git a/test/test_subscribers.js b/test/test_subscribers.js index 5217e62..f91bafa 100644 --- a/test/test_subscribers.js +++ b/test/test_subscribers.js @@ -70,9 +70,9 @@ $(document).ready(function () { test("caption", function () { var simple = $('
').dform({ - type : 'text', - caption : 'The test' - }).find('label'), + type : 'text', + caption : 'The test' + }).find('label'), asElement = $('
').dform({ type : 'text', caption : { @@ -89,9 +89,9 @@ $(document).ready(function () { test("options", function () { var options = { - test1 : 'Test 1', - test2 : 'Test 2' - }, + test1 : 'Test 1', + test2 : 'Test 2' + }, select = $(''), + 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