var shoe = require('shoe'); var sock = shoe('/sock'); var ever = require('ever'); var Widget = require('widget'); var w = Widget(); var elem = document.createElement('div'); document.body.appendChild(elem); w.appendTo(elem); var form = elem.querySelector('form'); w.on('message', function (msg) { sock.write(JSON.stringify(['msg',msg]) + '\n'); }); var txt = form.querySelector('textarea[name="msg"]') txt.value = 'howdee pardner'; ever(form).emit('submit'); var style = window.getComputedStyle(txt); sock.write(JSON.stringify(['bg',style.backgroundColor]) + '\n'); sock.write(JSON.stringify(['fg',style.color]) + '\n'); sock.write(JSON.stringify(['style',true]) + '\n');
module.exports = function(Opts){ var that, conf, init, destroy; // 参数 conf = parseParam({ id: '', // 容器id module: null, require: [], // 依赖的JS,CSS exports: null, // 加载完成之后的回调 async: false, // 串行加载 isDepend: true, // 加载的资源是否互相依赖 requireParams: [], // 加载的资源,如果需要配置参数 initialize: false, // 是否初始化(模块需要有init方法) rate: 0, // 加载的优先级,优先级越高,加载越靠前 media: false, // 加载的media的大小,格式为min-width=480px。默认为全部,此方式不对IE9以下支持 platform: true, // 要加载的平台,默认为全部 template: '', // 相关的模板 loadTime: '', // 加载时机 initTime: '' // 执行时机 },Opts); that = widget(conf); /** * 获取容器节点 * @return {[type]} [description] */ function getBox(){ var box = $('#'+conf.id); return box[0] && box; }; /** * 获取模板 * @param {[type]} id [description] * @return {[type]} [description] */ function getTemplate(id){ var tpl, conf = that.getConfig(); try{ tpl = $('#'+id).html(); }catch(e){ tpl = ''; } if(!tpl){ tpl = conf.template && conf.template[id]; } return tpl; } init = function(){ var conf, box; if(box = getBox()){ that.setConfig('box',box); conf = that.getConfig(); } if(conf && box && that.inVisibleArea()){ that.setConfig('rate',conf.rate++); } }; // api that.getTemplate = getTemplate; that.init = init; return that; };
asWidget('about', function(hub) { var widget = this this.template('/widgets/about/index.html') this.on('installed', function() { widget.start() hub.trigger('aboutNeeded') hub.trigger('teamNeeded') hub.trigger('partnersNeeded') }) hub.on('aboutLoaded', function(about) { //hack about.about = about.about.replace(/Please donate/, 'Please <a href="#_/donation">donate</a>') widget.set('about', about) }) hub.on('teamLoaded', function(team) { widget.set('team', team) hub.trigger('appReady') }) hub.on('partnersLoaded', function(partners) { widget.set('accelerationPartners', partners.filter(function(p) { return p.terms.involvement[0].slug == 'acceleration-partner' })) widget.set('movementPartners', partners.filter(function(p) { return p.terms.involvement[0].slug == 'movement-partner' })) widget.set('organizationalAllies', partners.filter(function(p) { return p.terms.involvement[0].slug == 'organizational-ally' })) }) widget.toggleShowingPartnersApplication = function() { var current = widget.get('showingPartnersApplication') widget.set('showingPartnersApplication', !current) if (current) hub.trigger('urlHash', '') else hub.trigger('urlHash', 'partnersApplication') } hub.on('navTo', function(place) { if (place == 'partnersApplication') { hub.trigger('urlHash', place) widget.toggleShowingPartnersApplication() } }) })
var asWidget = require('widget') var Backbone = require('backbone') module.exports = asWidget('login-modal', function(hub) { var widget = this var user = new Backbone.Model({ email: '', password: '' }) widget.user = user widget.template('/features/sessions/widgets/login_modal/template.html') widget.on('installed', function() { widget.start().hide() }) widget.login = function() { hub.trigger('user:login', user) } hub.on('user:loggedIn', function(user) { widget.hide() }) hub.on('user:login:error', function(e) { }) hub.on('modal:login', widget.show, widget) }) //==========================================================================// // This file is part of multi-site-client-poc. //
define("ui.vcode", ["require", "exports", "module", "util", "widget", "util.rule","ui.validator"],function(require, exports, module){ /** * @fileoverview 表单验证组件 * @author zh(zhangguoqiang@baidu.com) * @date 2013-08-29 */ var util = require('util'); var widget = require('widget'); var ruleFactory = require('util.rule'); var Validator = require('ui.validator'); /** * @name Vcode * @class 验证码组件 * @constructor * @extends Widget * @requires widget * @requires util * @param {Object} config 组件配置(下面的参数为配置项,配置会写入属性,详细的配置说明请看属性部分) * @param {String} config.formId 表单id * @param {String} config.tipClass 描述className * @param {String} config.errClass 错误className * @param {Boolean} config.checkBeforeSubmit 提交前是否校验 * @param {Boolean} config.breakWhenError 校验未通过时,是否停止校验 * @param {Object} config.rules 表单规则 {表单项id:{}} * @example * var dialog = new Validator({...}); */ var Vcode = widget({ Options: { btnId: '', ajaxUrl: '', params: {}, timeout: 60, btnText: '点此免费获取', successText: '验证码已发送至您的手机', itemClass: 'form-item', tipClass: 'form-tip', warningClass: 'form-item-warning', errClass: 'form-item-error', successClass: 'form-item-success', defaultActionAfterValite: function(ele, validator, flag, msg){ var formItem = this.getFormitem(ele); var formTip = this._getTipNode(ele); this.clearStatus(ele); if(!flag){ if('required' == validator){ formItem.addClass(this.warningClass); }else{ formItem.addClass(this.errClass); } formTip.html(msg); }else{ formItem.addClass(this.successClass); formTip.html(''); } }, defaultActionAfterRequest: function(ele, data){ var _this = this; if(0 == data.ret){ _this._getTipNode(ele).html(_this.successText); _this.getFormitem(ele).addClass(_this.successClass); }else if ('50000' === data.ret){ _this.unlogin && _this.unlogin(); }else{ _this.clearStatus(ele); _this._getTipNode(ele).html(data.ret_msg); _this.getFormitem(ele).addClass(_this.errClass); } }, SendAndDo:null }, _init: function(){ if(!this.formId || !$('#' + this.formId).length){ try{ throw new Error( this.formId + '表单元素不存在,请检查'); }catch(e){ alert(e); } } this.formNode = $('#' + this.formId); this.btnNode = $('#' + this.btnId); this.btnNode.val(this.btnText); this.validators = this._colloectValidator(); this._action(); }, _action: function(){ var _this = this; this.btnNode.bind('click', function(){ var isValid = _this.validateAll(); if(isValid){ _this.SendAndDo && _this.SendAndDo(); _this._sendRequest(); _this.countDown(); } }); this.bind('onvalidatebefore', function(e, args){ }); this.bind('onvalidateafter', function(e, args){ this.defaultActionAfterValite.apply(_this, args); }); this.bind('onvalidateallafter', function(e, args){ //console.log(args) }); this.bind('onvalidateallbefore', function(e, args){ //console.log(args) }); }, _colloectValidator: function(){ var obj = {}; $.each(this.params, function(index, id){ var ruleName = $('#' + id).attr('data-validator'); if(!ruleName){ return false; } var rule = ruleFactory.getRule(ruleName); if('object' == typeof rule){ if(rule instanceof RegExp){ obj[id] = { type: ruleName }; }else{ obj[id] = rule; } }else if('function' == typeof rule){ obj[id] = { type: ruleName }; } }); return obj; }, _sendRequest: function(){ var params = []; var _this = this; var ele = _this.btnNode; $.each(this.params, function(index, id){ params.push(index + '=' + $('#' + id).val()); }); params = params.join('&'); $.get(this.ajaxUrl + '?' + params, function(data){ _this.defaultActionAfterRequest(ele, data); }); }, countDown: function(){ var _this = this; var i = 0; _this.setDisable(); _this.btnNode.val(_this.timeout - i + '秒后重新发送'); _this.timer = setInterval(function(){ if(_this.timeout - 1 == i){ _this.stopCountDown(); return false; } i++; _this.btnNode.val(_this.timeout - i + '秒后重新发送'); }, 1000); }, stopCountDown: function(){ var _this = this; clearInterval(_this.timer); _this.btnNode.val(_this.btnText); _this.setEnable(); }, setDisable: function(){ this.btnNode.attr('disabled', true); }, setEnable: function(){ this.btnNode.removeAttr('disabled'); } }, { 'superClass': Validator //继承 }); module.exports = Vcode; });
asWidget('faq', function(hub) { var widget = this widget.template('/widgets/faq/index.html') widget.on('installed', function() { widget.start().hide() hub.trigger('faqNeeded') }) var FAQ = Backbone.Model.extend({ toggle: function() { this.set('open', !this.get('open')) } }) hub.on('showFaq', function() { widget.show() hub.trigger('urlHash', 'faq') }) widget.on('change:visible', function() { hub.trigger('urlHash', '') }) hub.on('faqLoaded', function(faqs) { widget.set('faqs', faqs.map(function(faq) { return new FAQ(faq) })) }) hub.on('navTo', function(place) { if (place !== 'faq') widget.hide() }) })