Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

sammy.form-0.7.6.min.js 4.0KB

12345
  1. // -- Sammy.js -- /plugins/sammy.form.js
  2. // http://sammyjs.org
  3. // Version: 0.7.6
  4. // Built: 2014-08-26 10:45:31 +0300
  5. (function(factory){if(typeof define==="function"&&define.amd){define(["jquery","sammy"],factory)}else{(window.Sammy=window.Sammy||{}).Form=factory(window.jQuery,window.Sammy)}})(function($,Sammy){function getStringContent(object,content){if(typeof content==="undefined"){return""}else if($.isFunction(content)){content=content.apply(object)}return content.toString()}function simple_element(tag,attributes,content){var html="<";html+=tag;if(typeof attributes!="undefined"){$.each(attributes,function(key,value){if(value!==null){html+=" "+key+"='";html+=getStringContent(attributes,value).replace(/\'/g,"'");html+="'"}})}if(content===false){html+=">"}else if(typeof content!="undefined"){html+=">";html+=getStringContent(this,content);html+="</"+tag+">"}else{html+=" />"}return html}Sammy.FormBuilder=function(name,object){this.name=name;this.object=object};$.extend(Sammy.FormBuilder.prototype,{open:function(attributes){return simple_element("form",$.extend({method:"post",action:"#/"+this.name+"s"},attributes),false)},close:function(){return"</form>"},label:function(keypath,content,attributes){var attrs={"for":this._attributesForKeyPath(keypath).name};return simple_element("label",$.extend(attrs,attributes),content)},hidden:function(keypath,attributes){attributes=$.extend({type:"hidden"},this._attributesForKeyPath(keypath),attributes);return simple_element("input",attributes)},text:function(keypath,attributes){attributes=$.extend({type:"text"},this._attributesForKeyPath(keypath),attributes);return simple_element("input",attributes)},textarea:function(keypath,attributes){var current;attributes=$.extend(this._attributesForKeyPath(keypath),attributes);current=attributes.value;delete attributes["value"];return simple_element("textarea",attributes,current)},password:function(keypath,attributes){return this.text(keypath,$.extend({type:"password"},attributes))},select:function(keypath,options,attributes){var option_html="",selected;attributes=$.extend(this._attributesForKeyPath(keypath),attributes);selected=attributes.value;delete attributes["value"];$.each(options,function(i,option){var value,text,option_attrs;if($.isArray(option)){value=option[1];text=option[0]}else{value=option;text=option}option_attrs={value:getStringContent(this.object,value)};if(value===selected){option_attrs.selected="selected"}option_html+=simple_element("option",option_attrs,text)});return simple_element("select",attributes,option_html)},radio:function(keypath,value,attributes){var selected;attributes=$.extend(this._attributesForKeyPath(keypath),attributes);selected=attributes.value;attributes.value=getStringContent(this.object,value);if(selected==attributes.value){attributes.checked="checked"}return simple_element("input",$.extend({type:"radio"},attributes))},checkbox:function(keypath,value,attributes){var content="";if(!attributes){attributes={}}if(attributes.hidden_element!==false){content+=this.hidden(keypath,{value:!value})}delete attributes["hidden_element"];content+=this.radio(keypath,value,$.extend({type:"checkbox"},attributes));return content},submit:function(attributes){return simple_element("input",$.extend({type:"submit"},attributes))},_attributesForKeyPath:function(keypath){var builder=this,keys=$.isArray(keypath)?keypath:keypath.split(/\./),name=builder.name,value=builder.object,class_name=builder.name;$.each(keys,function(i,key){if(typeof value==="undefined"||value===""){value=""}else if(typeof key=="number"||key.match(/^\d+$/)){value=value[parseInt(key,10)]}else{value=value[key]}name+="["+key+"]";class_name+="-"+key});return{name:name,value:getStringContent(builder.object,value),"class":class_name}}});Sammy.Form=function(app){app.helpers({simple_element:simple_element,formFor:function(name,object,content_callback){var builder;if($.isFunction(object)){content_callback=object;object=this[name]}builder=new Sammy.FormBuilder(name,object);content_callback.apply(this,[builder]);return builder}})};return Sammy.Form});