mirror of
https://github.com/konvajs/konva.git
synced 2025-12-29 02:03:29 +08:00
container selector
This commit is contained in:
20
konva.js
20
konva.js
@@ -3,7 +3,7 @@
|
|||||||
* Konva JavaScript Framework v0.11.1
|
* Konva JavaScript Framework v0.11.1
|
||||||
* http://konvajs.github.io/
|
* http://konvajs.github.io/
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Fri Feb 05 2016
|
* Date: Fri Feb 26 2016
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
||||||
@@ -8657,10 +8657,20 @@
|
|||||||
* @memberof Konva.Stage.prototype
|
* @memberof Konva.Stage.prototype
|
||||||
* @param {DomElement} container can pass in a dom element or id string
|
* @param {DomElement} container can pass in a dom element or id string
|
||||||
*/
|
*/
|
||||||
setContainer: function(container) {
|
setContainer: function (container) {
|
||||||
if( typeof container === STRING) {
|
if (typeof container === STRING) {
|
||||||
var id = container;
|
if (container.charAt(0) === '.') {
|
||||||
container = Konva.document.getElementById(container);
|
var className = container.slice(1);
|
||||||
|
container = Konva.document.getElementsByClassName(className)[0];
|
||||||
|
} else {
|
||||||
|
var id;
|
||||||
|
if (container.charAt(0) !== '#') {
|
||||||
|
id = container;
|
||||||
|
} else {
|
||||||
|
id = container.slice(1);
|
||||||
|
}
|
||||||
|
container = Konva.document.getElementById(id);
|
||||||
|
}
|
||||||
if (!container) {
|
if (!container) {
|
||||||
throw 'Can not find container in document with id ' + id;
|
throw 'Can not find container in document with id ' + id;
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/Stage.js
18
src/Stage.js
@@ -95,10 +95,20 @@
|
|||||||
* @memberof Konva.Stage.prototype
|
* @memberof Konva.Stage.prototype
|
||||||
* @param {DomElement} container can pass in a dom element or id string
|
* @param {DomElement} container can pass in a dom element or id string
|
||||||
*/
|
*/
|
||||||
setContainer: function(container) {
|
setContainer: function (container) {
|
||||||
if( typeof container === STRING) {
|
if (typeof container === STRING) {
|
||||||
var id = container;
|
if (container.charAt(0) === '.') {
|
||||||
container = Konva.document.getElementById(container);
|
var className = container.slice(1);
|
||||||
|
container = Konva.document.getElementsByClassName(className)[0];
|
||||||
|
} else {
|
||||||
|
var id;
|
||||||
|
if (container.charAt(0) !== '#') {
|
||||||
|
id = container;
|
||||||
|
} else {
|
||||||
|
id = container.slice(1);
|
||||||
|
}
|
||||||
|
container = Konva.document.getElementById(id);
|
||||||
|
}
|
||||||
if (!container) {
|
if (!container) {
|
||||||
throw 'Can not find container in document with id ' + id;
|
throw 'Can not find container in document with id ' + id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user