Skip to content

Commit

Permalink
- first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumepotier committed Dec 16, 2012
0 parents commit 66e756c
Show file tree
Hide file tree
Showing 14 changed files with 6,805 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js

node_js:
- 0.6

before_script:
- npm install mocha-phantomjs

script: ./bin/test-suite.sh
15 changes: 15 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

if [[ -z "$1" ]]
then
echo "You must give a version number. eg: ./bin/build.sh 1.0.0"

else
echo "** building parsley.min.js version " $1
ruby ./bin/minify parsley.js dist/parsley.min.js $1 --force
echo " done!"

echo "** building parsley-standalone.min.js version " $1
ruby ./bin/minify resources/zepto-1.0rc1[zepto.event.data].min.js parsley.js dist/parsley-standalone.min.js $1 --force
echo " done!"
fi
41 changes: 41 additions & 0 deletions bin/minify
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env ruby

# heavily inspired by https://gist.github.com/765432 :)

dry_run = ARGV.delete('--dry-run')
force = ARGV.delete('--force')

input, output, garlic_version = ARGV.length == 1 ?
[ARGV, ARGV.first.sub(/\.js$/, '.min.js'), 'x.x.x'] :
[ARGV[0..-3], ARGV.at(-2), ARGV.last]

if (missing = input.select { |path| !File.exists?(path) }).any?
puts "Some input files do not exist:\n #{missing.join(" \n")}"
exit 1
end

if File.exists?(output) && !force
puts "Output file #{output} already exists, use the --force to overwrite"
exit 1
end

if dry_run
puts "#{input.inspect} => #{output}"
else
require 'rubygems'

begin
require 'closure-compiler'
rescue LoadError
puts "Error loading Closure Compiler gem:\n gem install closure-compiler"
exit 1
end

File.open(output, 'w') do |f|
f.write "/* Garlicjs %s build version %s http://garlicjs.org */\n" %
[output, garlic_version]
f.write Closure::Compiler.new.compile(input.map { |file|
File.read(file)
})
end
end
3 changes: 3 additions & 0 deletions bin/test-suite.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

mocha-phantomjs tests/index.html && mocha-phantomjs tests/index.html#jquery-min && mocha-phantomjs tests/index.html#zepto && mocha-phantomjs tests/index.html#zepto-min && mocha-phantomjs tests/index.html#standalone
37 changes: 37 additions & 0 deletions dist/parsley-standalone.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/parsley.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions parsley.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Parsley.js allows you to verify your form inputs frontend side, without writing a line of javascript. Or so..
author: Guillaume Potier - @guillaumepotier
*/

!function ($) {

"use strict";

/* PARSLEY PUBLIC CLASS DEFINITION
* =============================== */
var Parsley = function ( element, options ) {
this.init( 'parsley', element, options );
}

Parsley.prototype = {

constructor: Parsley

/* init data, bind jQuery on() actions */
, init: function ( type, element, options ) {
this.type = type;
this.$element = $( element );
this.options = this.getOptions( options );
this.parentForm = this.$element.closest( 'form' );
this.$element.addClass( 'parsley-validated' );

// bind parsley verification events
// this.$element.on( this.options.events.join( '.' + this.type + ' ') , false, $.proxy( this.persist, this ) );
}

, getOptions: function ( options ) {
options = $.extend( {}, $.fn[this.type].defaults, options, this.$element.data() );

return options;
}
}

/* PARSLEY PLUGIN DEFINITION
* ========================= */

$.fn.parsley = function ( option, fn ) {
var options = $.extend(true, {}, $.fn.parsley.defaults, option, this.data() )
, returnValue = false;

function bind ( self ) {
var $this = $( self )
, data = $this.data( 'parsley' )
, fieldOptions = $.extend( {}, options, $this.data() );

// if data never binded, bind it right now!
if ( !data ) {
$this.data( 'parsley', ( data = new Parsley( self, fieldOptions ) ) );
}

// here is our parsley public function accessor, currently does not support args
if ( 'string' === typeof option && 'function' === typeof data[option] ) {
return data[option]();
}
}

// loop through every elemt we want to parsley
this.each(function () {
// if a form elem is given, bind all its input children
if ( $( this ).is( 'form' ) ) {
$( this ).find( options.inputs ).each( function () {
returnValue = bind( $( this ) );
});

// if it is a Parsley supported single element, bind it too
// add here a return instance, cuz' we could call public methods on single elems with data[option]() above
} else if ( $( this ).is( options.inputs ) ) {
returnValue = bind( $( this ) );
}
});

return 'function' === typeof fn ? fn() : returnValue;
}

/* PARSLEY CONFIGS & OPTIONS
* ========================= */
$.fn.parsley.Constructor = Parsley;

$.fn.parsley.defaults = {
inputs: 'input, textarea, select' // Default supported inputs.
}

/* PARSLEY DATA-API
* =============== */
$( window ).on( 'load', function () {
$( '[data-validate="parsley"]' ).each( function () {
$(this).parsley();
})
});

// This plugin works with jQuery or Zepto (with data extension builded for Zepto.)
}(window.jQuery || window.Zepto);
2 changes: 2 additions & 0 deletions resources/jquery-1.8.2.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/zepto-1.0rc1[zepto.event.data].min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 66e756c

Please sign in to comment.