Path: blob/master/webroot/rsrc/externals/javelin/ext/view/HTMLView.js
12242 views
/**1* Dumb HTML views. Mostly to demonstrate how the visitor pattern over these2* views works, as driven by validation. I'm not convinced it's actually a good3* idea to do validation.4*5* @provides javelin-view-html6* @requires javelin-install7* javelin-dom8* javelin-view-visitor9* javelin-util10*/1112JX.install('HTMLView', {13extend: 'View',14members : {15render: function(rendered_children) {16return JX.$N(this.getName(), this.getAllAttributes(), rendered_children);17},18validate: function() {19this.accept(JX.HTMLView.getValidatingVisitor());20}21},2223statics: {24getValidatingVisitor: function() {25return new JX.ViewVisitor(JX.HTMLView.validate);26},2728validate: function(view) {29var spec = this._getHTMLSpec();30if (!(view.getName() in spec)) {31throw new Error('invalid tag');32}3334var tag_spec = spec[view.getName()];3536var attrs = view.getAllAttributes();37for (var attr in attrs) {38if (!(attr in tag_spec)) {39throw new Error('invalid attr');40}4142var validator = tag_spec[attr];43if (typeof validator === 'function') {44return validator(attrs[attr]);45}46}4748return true;49},5051_validateRel: function(target) {52return target in {53'_blank': 1,54'_self': 1,55'_parent': 1,56'_top': 157};58},59_getHTMLSpec: function() {60var attrs_any_can_have = {61className: 1,62id: 1,63sigil: 164};6566var form_elem_attrs = {67name: 1,68value: 169};7071var spec = {72a: { href: 1, target: JX.HTMLView._validateRel },73b: {},74blockquote: {},75br: {},76button: JX.copy({}, form_elem_attrs),77canvas: {},78code: {},79dd: {},80div: {},81dl: {},82dt: {},83em: {},84embed: {},85fieldset: {},86form: { type: 1 },87h1: {},88h2: {},89h3: {},90h4: {},91h5: {},92h6: {},93hr: {},94i: {},95iframe: { src: 1 },96img: { src: 1, alt: 1 },97input: JX.copy({}, form_elem_attrs),98label: {'for': 1},99li: {},100ol: {},101optgroup: {},102option: JX.copy({}, form_elem_attrs),103p: {},104pre: {},105q: {},106select: {},107span: {},108strong: {},109sub: {},110sup: {},111table: {},112tbody: {},113td: {},114textarea: {},115tfoot: {},116th: {},117thead: {},118tr: {},119ul: {}120};121122for (var k in spec) {123JX.copy(spec[k], attrs_any_can_have);124}125126return spec;127},128registerToInterpreter: function(view_interpreter) {129var spec = this._getHTMLSpec();130for (var tag in spec) {131view_interpreter.register(tag, JX.HTMLView);132}133return view_interpreter;134}135}136});137138139