Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tag.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. 'use strict';
  2. var Attrs = require('./attrs');
  3. var Block = require('./block');
  4. var inlineTags = require('../inline-tags');
  5. /**
  6. * Initialize a `Tag` node with the given tag `name` and optional `block`.
  7. *
  8. * @param {String} name
  9. * @param {Block} block
  10. * @api public
  11. */
  12. var Tag = module.exports = function Tag(name, block) {
  13. Attrs.call(this);
  14. this.name = name;
  15. this.block = block || new Block;
  16. };
  17. // Inherit from `Attrs`.
  18. Tag.prototype = Object.create(Attrs.prototype);
  19. Tag.prototype.constructor = Tag;
  20. Tag.prototype.type = 'Tag';
  21. /**
  22. * Clone this tag.
  23. *
  24. * @return {Tag}
  25. * @api private
  26. */
  27. Tag.prototype.clone = function(){
  28. var err = new Error('tag.clone is deprecated and will be removed in v2.0.0');
  29. console.warn(err.stack);
  30. var clone = new Tag(this.name, this.block.clone());
  31. clone.line = this.line;
  32. clone.attrs = this.attrs;
  33. clone.textOnly = this.textOnly;
  34. return clone;
  35. };
  36. /**
  37. * Check if this tag is an inline tag.
  38. *
  39. * @return {Boolean}
  40. * @api private
  41. */
  42. Tag.prototype.isInline = function(){
  43. return ~inlineTags.indexOf(this.name);
  44. };
  45. /**
  46. * Check if this tag's contents can be inlined. Used for pretty printing.
  47. *
  48. * @return {Boolean}
  49. * @api private
  50. */
  51. Tag.prototype.canInline = function(){
  52. var nodes = this.block.nodes;
  53. function isInline(node){
  54. // Recurse if the node is a block
  55. if (node.isBlock) return node.nodes.every(isInline);
  56. return node.isText || (node.isInline && node.isInline());
  57. }
  58. // Empty tag
  59. if (!nodes.length) return true;
  60. // Text-only or inline-only tag
  61. if (1 == nodes.length) return isInline(nodes[0]);
  62. // Multi-line inline-only tag
  63. if (this.block.nodes.every(isInline)) {
  64. for (var i = 1, len = nodes.length; i < len; ++i) {
  65. if (nodes[i-1].isText && nodes[i].isText)
  66. return false;
  67. }
  68. return true;
  69. }
  70. // Mixed tag
  71. return false;
  72. };