container selector

This commit is contained in:
ningyi.zny
2016-02-26 22:21:49 +08:00
parent 8b23ae64df
commit 29a48662b4
2 changed files with 255 additions and 235 deletions

View File

@@ -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;
} }

View File

@@ -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;
} }