Prettified all files.
This commit is contained in:
+80
-63
@@ -11,10 +11,9 @@ import Theme from './theme.js'
|
||||
* @see {@link http://pixijs.download/dev/docs/PIXI.Graphics.html|PIXI.Graphics}
|
||||
*/
|
||||
export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
/**
|
||||
* Creates an instance of an AbstractPopup (only for internal use).
|
||||
*
|
||||
*
|
||||
* @constructor
|
||||
* @param {object} [opts] - An options object to specify to style and behaviour of the popup.
|
||||
* @param {number} [opts.id=auto generated] - The id of the popup.
|
||||
@@ -45,34 +44,37 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
* to landscape, the popup cannot be displayed in portrait mode.
|
||||
*/
|
||||
constructor(opts = {}) {
|
||||
|
||||
super()
|
||||
|
||||
|
||||
const theme = Theme.fromString(opts.theme)
|
||||
this.theme = theme
|
||||
|
||||
this.opts = Object.assign({}, {
|
||||
id: PIXI.utils.uid(),
|
||||
x: 0,
|
||||
y: 0,
|
||||
header: null, // null or null
|
||||
content: null, // null or String or PIXI.DisplayObject
|
||||
minWidth: 320,
|
||||
minHeight: 130,
|
||||
maxWidth: null,
|
||||
padding: theme.padding,
|
||||
fill: theme.fill,
|
||||
fillAlpha: theme.fillAlpha,
|
||||
stroke: theme.stroke,
|
||||
strokeWidth: theme.strokeWidth,
|
||||
strokeAlpha: theme.strokeAlpha,
|
||||
headerStyle: theme.textStyleLarge,
|
||||
textStyle: theme.textStyleSmall,
|
||||
radius: theme.radius,
|
||||
onHidden: null,
|
||||
visible: true,
|
||||
orientation: null
|
||||
}, opts)
|
||||
this.opts = Object.assign(
|
||||
{},
|
||||
{
|
||||
id: PIXI.utils.uid(),
|
||||
x: 0,
|
||||
y: 0,
|
||||
header: null, // null or null
|
||||
content: null, // null or String or PIXI.DisplayObject
|
||||
minWidth: 320,
|
||||
minHeight: 130,
|
||||
maxWidth: null,
|
||||
padding: theme.padding,
|
||||
fill: theme.fill,
|
||||
fillAlpha: theme.fillAlpha,
|
||||
stroke: theme.stroke,
|
||||
strokeWidth: theme.strokeWidth,
|
||||
strokeAlpha: theme.strokeAlpha,
|
||||
headerStyle: theme.textStyleLarge,
|
||||
textStyle: theme.textStyleSmall,
|
||||
radius: theme.radius,
|
||||
onHidden: null,
|
||||
visible: true,
|
||||
orientation: null
|
||||
},
|
||||
opts
|
||||
)
|
||||
|
||||
this.id = this.opts.id
|
||||
|
||||
@@ -81,10 +83,12 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
if (this.opts.maxWidth) {
|
||||
this.headerStyle.wordWrap = true
|
||||
this.headerStyle.wordWrapWidth = this.opts.maxWidth - (2 * this.opts.padding)
|
||||
this.headerStyle.wordWrapWidth =
|
||||
this.opts.maxWidth - 2 * this.opts.padding
|
||||
|
||||
this.textStyle.wordWrap = true
|
||||
this.textStyle.wordWrapWidth = this.opts.maxWidth - (2 * this.opts.padding)
|
||||
this.textStyle.wordWrapWidth =
|
||||
this.opts.maxWidth - 2 * this.opts.padding
|
||||
}
|
||||
|
||||
this.alpha = 0
|
||||
@@ -99,7 +103,7 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
// padding
|
||||
this.innerPadding = this.opts.padding * 1.5
|
||||
|
||||
|
||||
// interaction
|
||||
//-----------------
|
||||
this.interactive = true
|
||||
@@ -107,15 +111,14 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
this.show()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the framework and instantiates everything.
|
||||
*
|
||||
*
|
||||
* @private
|
||||
* @return {AbstractPopup} A reference to the popup for chaining.
|
||||
*/
|
||||
setup() {
|
||||
|
||||
// position
|
||||
//-----------------
|
||||
this.sy = this.opts.padding
|
||||
@@ -123,15 +126,17 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
// header
|
||||
//-----------------
|
||||
if (this.opts.header != null) {
|
||||
|
||||
let header = null
|
||||
|
||||
if (this.opts.header instanceof PIXI.Text) {
|
||||
header = this.opts.header
|
||||
} else if (typeof this.opts.header === 'number') {
|
||||
header = new PIXI.Text(this.opts.header.toString(), this.headerStyle)
|
||||
header = new PIXI.Text(
|
||||
this.opts.header.toString(),
|
||||
this.headerStyle
|
||||
)
|
||||
} else {
|
||||
header = new PIXI.Text(this.opts.header, this.headerStyle)
|
||||
header = new PIXI.Text(this.opts.header, this.headerStyle)
|
||||
}
|
||||
|
||||
header.x = this.opts.padding
|
||||
@@ -151,13 +156,15 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
// content
|
||||
//-----------------
|
||||
if (this.opts.content != null) {
|
||||
|
||||
let content = null
|
||||
|
||||
if (typeof this.opts.content === 'string') {
|
||||
content = new PIXI.Text(this.opts.content, this.textStyle)
|
||||
} else if (typeof this.opts.content === 'number') {
|
||||
content = new PIXI.Text(this.opts.content.toString(), this.textStyle)
|
||||
content = new PIXI.Text(
|
||||
this.opts.content.toString(),
|
||||
this.textStyle
|
||||
)
|
||||
} else {
|
||||
content = this.opts.content
|
||||
}
|
||||
@@ -174,24 +181,23 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should be called to refresh the layout of the popup. Can be used after resizing.
|
||||
*
|
||||
*
|
||||
* @return {AbstractPopup} A reference to the popup for chaining.
|
||||
*/
|
||||
layout() {
|
||||
|
||||
// wanted width & wanted height
|
||||
//-----------------
|
||||
const padding = this.opts.padding
|
||||
const size = this.getInnerSize()
|
||||
const width = size.width + (2 * padding)
|
||||
const height = size.height + (2 * padding)
|
||||
const width = size.width + 2 * padding
|
||||
const height = size.height + 2 * padding
|
||||
|
||||
this.wantedWidth = Math.max(width, this.opts.minWidth)
|
||||
this.wantedHeight = Math.max(height, this.opts.minHeight)
|
||||
|
||||
|
||||
if (this.opts.maxWidth) {
|
||||
this.wantedWidth = Math.min(this.wantedWidth, this.opts.maxWidth)
|
||||
}
|
||||
@@ -221,41 +227,54 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draws the canvas.
|
||||
*
|
||||
*
|
||||
* @private
|
||||
* @return {AbstractPopup} A reference to the popup for chaining.
|
||||
*/
|
||||
draw() {
|
||||
|
||||
const square = Math.round(this.wantedWidth) === Math.round(this.wantedHeight)
|
||||
const square =
|
||||
Math.round(this.wantedWidth) === Math.round(this.wantedHeight)
|
||||
const diameter = Math.round(this.opts.radius * 2)
|
||||
|
||||
this.clear()
|
||||
this.lineStyle(this.opts.strokeWidth, this.opts.stroke, this.opts.strokeAlpha)
|
||||
this.lineStyle(
|
||||
this.opts.strokeWidth,
|
||||
this.opts.stroke,
|
||||
this.opts.strokeAlpha
|
||||
)
|
||||
this.beginFill(this.opts.fill, this.opts.fillAlpha)
|
||||
if (square && diameter === this.wantedWidth) {
|
||||
this.drawCircle(this.wantedWidth / 2, this.wantedHeight / 2, this.opts.radius)
|
||||
this.drawCircle(
|
||||
this.wantedWidth / 2,
|
||||
this.wantedHeight / 2,
|
||||
this.opts.radius
|
||||
)
|
||||
} else {
|
||||
this.drawRoundedRect(0, 0, this.wantedWidth, this.wantedHeight, this.opts.radius)
|
||||
this.drawRoundedRect(
|
||||
0,
|
||||
0,
|
||||
this.wantedWidth,
|
||||
this.wantedHeight,
|
||||
this.opts.radius
|
||||
)
|
||||
}
|
||||
this.endFill()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the size of the children of the AbstractPopup.
|
||||
* Cannot use getBounds() because it is not updated when children
|
||||
* are removed.
|
||||
*
|
||||
*
|
||||
* @private
|
||||
* @returns {object} An JavaScript object width the keys width and height.
|
||||
*/
|
||||
getInnerSize() {
|
||||
|
||||
let width = 0
|
||||
let height = 0
|
||||
|
||||
@@ -273,17 +292,16 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
height += this._content.height
|
||||
}
|
||||
|
||||
return {width, height}
|
||||
return { width, height }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the popup (sets his alpha values to 1).
|
||||
*
|
||||
*
|
||||
* @param {callback} [cb] - Executed when show animation was completed.
|
||||
* @return {AbstractPopup} A reference to the popup for chaining.
|
||||
*/
|
||||
show(cb) {
|
||||
|
||||
TweenLite.to(this, this.theme.fast, {
|
||||
alpha: 1,
|
||||
onComplete: () => {
|
||||
@@ -295,15 +313,14 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hides the popup (sets his alpha values to 0).
|
||||
*
|
||||
*
|
||||
* @param {callback} [cb] - Executed when hide animation was completed.
|
||||
* @return {AbstractPopup} A reference to the popup for chaining.
|
||||
*/
|
||||
hide(cb) {
|
||||
|
||||
TweenLite.to(this, this.theme.fast, {
|
||||
alpha: 0,
|
||||
onComplete: () => {
|
||||
@@ -324,7 +341,7 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
/**
|
||||
* Sets or gets the header. The getter always returns a PIXI.Text object. The setter can receive
|
||||
* a string, a number or a PIXI.Text object.
|
||||
*
|
||||
*
|
||||
* @member {string|number|PIXI.Text}
|
||||
*/
|
||||
get header() {
|
||||
@@ -337,11 +354,11 @@ export default class AbstractPopup extends PIXI.Graphics {
|
||||
this.opts.header = value
|
||||
this.setup().layout()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets or gets the content. The getter always returns an PIXI.DisplayObject. The setter can receive
|
||||
* a string, a number or a PIXI.DisplayObject.
|
||||
*
|
||||
*
|
||||
* @member {string|number|PIXI.DisplayObject}
|
||||
*/
|
||||
get content() {
|
||||
|
||||
Reference in New Issue
Block a user