Skip to content

Commit

Permalink
add unsocial test file b00tc4mp#173
Browse files Browse the repository at this point in the history
  • Loading branch information
angelzrc committed Oct 16, 2024
1 parent 453b9a6 commit c073f2e
Show file tree
Hide file tree
Showing 35 changed files with 1,255 additions and 0 deletions.
22 changes: 22 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

/*
class Button(text, type) {
Compo.call(this, document.createElement('button'))
this.container.innerText = text
this.container.type = type
}
Button.prototype = Object.create(Compo.prototype)
Button.prototype.constructor = Button */

class Button extends Compo {
constructor (text, type){
super(document.createElement('button'))

this.container.innerText = text
this.container.type = type
}
}


15 changes: 15 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Code extends Compo {
constructor (text) {
super(document.createElement('code'))

this.container.innerText = text
}

setText(text) {
this.container.innerText = text
}

getText() {
return this.container.innerText
}
}
61 changes: 61 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Compo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Constructs Compo instances
*
* @param {HTMLElement} container The DOM container of the Compo instance
*/
/* function Compo(container) {
this.children = []
this.container = container
this.parent = null
}
Compo.prototype.add = function (child) {
this.children.push(child)
child.parent = this
this.container.appendChild(child.container)
}
Compo.prototype.removeSelf = function () {
var index = this.parent.children.findIndex(function (child) {
return child === this
}.bind(this))
if (index > -1)
this.parent.children.splice(index, 1)
this.container.remove()
}
Compo.prototype.addBehavior= function (type, callback) {
this.container.addEventListener(type, callback)
}
*/

class Compo {
constructor (container) {
this.children = []
this.container = container
this.parent = null
}

add (child) {
this.children.push(child)
child.parent = this
this.container.appendChild(child.container)
}

removeself () {
const index = this.pΓ rent.children.findIndex( child => child === this)

if (index > -1) {
this.parent.children.splice(index, 1)
this.container.remove()
}
}

addBehavior(type, callback) {
this.container.addEventListener(type, callback)
}
}


13 changes: 13 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


/**Constructs Form instances */
class Form extends Compo{
constructor() {
super(document.createElement('form'))
}

reset() {
this.container.reset()
}
}

18 changes: 18 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Constructs Heading instances
*/
/* function Heading(text, level) {
Compo.call(this, document.createElement('h' + level))
this.container.innerText = text
}
Heading.extends(Compo) */

class Heading extends Compo {
constructor(text, level) {
super(document.createElement(`h${level}`))

this.container.innerText = text
}
}
17 changes: 17 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* function Image(address) {
Compo.call(this, document.createElement('img'))
this.container.src = address
this.container.style.width = '100%'
}
Image.extends(Compo) */

class Image extends Compo{
constructor(address) {
super(document.createElement('img'))

this.container.src = address
this.container.style.width = '100%'
}
}
55 changes: 55 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Constructs Input Instances
*/
/* function Input(type, id) {
Compo.call(this, document.createElement('input'))
this.container.style.width = '100%'
this.container.style.boxSizing = 'border-box'
this.container.type = type
this.container.id = id
}
Input.extends(Compo)
Input.prototype.getValue = function () {
return this.container.value
}
Input.prototype.setValue = function (value) {
this.container.value = value
}
Input.prototype.getType = function () {
return this.container.type
}
Input.prototype.setType = function (type) {
this.container.type = type
} */

class Input extends Compo {
constructor(type, id) {
super(document.createElement('input'))

this.container.type = type
this.container.id = id
}

getValue() {
return this.container.value
}

setValue(value) {
this.container.value = value
}

getType() {
return this.container.type
}
setType(type) {
this.container.type = type
}


}
23 changes: 23 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Constructs Label instances
*
* @param {string} text The text of the label
* @param {string} id The id of the input to relate with
*/
/* function Label(text, id) {
Compo.call(this, document.createElement('label'))
this.container.innerText = text
this.container.htmlFor = id
}
Label.extends(Compo) */

class Label extends Compo {
constructor (text, id){
super(document.createElement('label'))

this.container.innerText = text
this.container.htmlFor = id
}
}
22 changes: 22 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Constructs Link instances
*
* @param {string} text The text of the link
*/
/* function Link(text) {
Compo.call(this, document.createElement('a'))
this.container.innerText = text
this.container.href = ''
}
Link.extends(Compo) */

class Link extends Compo {
constructor(text) {
super(document.createElement('a'))

this.container.innerText = text
this.container.href = ''
}
}
6 changes: 6 additions & 0 deletions staff/angelzrc/unsocial.test/compo/ListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ListItem extends Compo {
constructor() {
super(document.createElement('li'))
}

}
34 changes: 34 additions & 0 deletions staff/angelzrc/unsocial.test/compo/Paragraph.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* function Paragraph(text) {
Compo.call(this, document.createElement('p'))
this.container.innerText = text
}
Paragraph.extends(Compo)
Paragraph.prototype.setText = function (text) {
thbis.container.innerText = text
}
Paragraph.prototype.getText = function() {
return this.container.innerText
} */

class Paragraph extends Compo{
constructor(text) {
super(document.createElement('p'))

this.container.innerText= text

}

setText(text){
this.container.innerText = text
}

getText() {
return this.container.innerText
}
}


65 changes: 65 additions & 0 deletions staff/angelzrc/unsocial.test/compo/PasswordInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* function PasswordInput(id) {
Compo.call(this, document.createElement('div'))
this.container.style.display = 'flex'
var input = new Input('password', id)
input.container.style.paddingRight = '18px'
this.add(input)
var span = new Span('😌')
this.add(span)
span.addBehavior('click', function() {
if (span.getText() === '😌') {
input.setType('text')
span.setText('😳')
} else {
input.setType('password')
span.setText('😌')
}
})
}
PasswordInput.extends(Compo)
PasswordInput.prototype.getValue = function () {
return this.children[0].container.value
}
PasswordInput.prototype.setValue = function (value) {
this.container.value = value
} */

class PasswordInput extends Compo {
constructor(id) {
super(document.createElement('div'))

const input = new Input('password', id)
this.add(input)

const span = new Span('😌')
this.container.style.cursor = 'pointer'
this.add(span)

span.addBehavior('click', () => {
if (span.getText() === '😌') {
input.setType('text')
span.setText('😳')
} else {
input.setType('password')
span.setText('😌')
}

})
}

getValue() {
return this.children[0].container.value
}

setValue(value) {
this.container.value = value
}
}
Loading

0 comments on commit c073f2e

Please sign in to comment.