From a365bf45a44550a9d70f889c870396c0766dabe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 5 Mar 2011 01:53:32 +0000 Subject: [PATCH] Apply the same optimisation from previous commit to Layer. --- src/item/Layer.js | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/item/Layer.js b/src/item/Layer.js index b5cbd137..04d28c27 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -24,30 +24,6 @@ var Layer = this.Layer = Group.extend({ } }, - moveAbove: function(item) { - // if the item is a layer and contained within Document#layers - if (item instanceof Layer && !item.parent) { - this.removeFromParent(); - item.document.layers.splice(item.getIndex() + 1, 0, this); - this.document = item.document; - return true; - } else { - return this.base(item); - } - }, - - moveBelow: function(item) { - // if the item is a layer and contained within Document#layers - if (item instanceof Layer && !item.parent) { - this.removeFromParent(); - item.document.layers.splice(item.getIndex() - 1, 0, this); - this.document = item.document; - return true; - } else { - return this.base(item); - } - }, - getNextSibling: function() { return this.parent ? this.base() : this.document.layers[this.getIndex() + 1] || null; @@ -61,4 +37,25 @@ var Layer = this.Layer = Group.extend({ activate: function() { this.document.activeLayer = this; } +}, new function () { + function move(above) { + return function(item) { + // if the item is a layer and contained within Document#layers + if (item instanceof Layer && !item.parent) { + this.removeFromParent(); + item.document.layers.splice(item.getIndex() + (above ? 1 : -1), + 0, this); + this.document = item.document; + return true; + } else { + return this.base(item); + } + } + } + + return { + moveAbove: move(true), + + moveBelow: move(false) + }; });