Merge "Added Changes for result panel integration into plugin mechanism"
diff --git a/dev/js/spec/panelSpec.js b/dev/js/spec/panelSpec.js
index bc065fd..9df1c22 100644
--- a/dev/js/spec/panelSpec.js
+++ b/dev/js/spec/panelSpec.js
@@ -18,7 +18,14 @@
       return e;
     }
   };
+  
+  var secViewClass = {
+      create : function () {
+        return Object.create(viewClass)._init(['secview']).upgradeTo(this);
+      },
+  };
 
+  
   describe('KorAP.View', function () {
     it('should be initializable', function () {
       var view = viewClass.create();
@@ -126,6 +133,25 @@
       expect(viewE.firstChild.tagName).toEqual("SPAN");
       expect(viewE.firstChild.firstChild.data).toEqual("Hello World!");
     });
+    
+    it('views should be appended or prepended', function () {
+      let panel = panelClass.create();
+      let view = helloViewClass.create();
+      let e = panel.element();
+      panel.add(view);      
+      let secview = secViewClass.create();
+      panel.add(secview);
+      let viewFirst = e.firstChild.firstChild;
+      expect(viewFirst.classList.contains('myview')).toBeTruthy();
+      
+      let prependPanel = panelClass.create();
+      prependPanel.prepend = true;
+      prependPanel.add(view);
+      prependPanel.add(secview);
+      viewFirst = prependPanel.element().firstChild.firstChild;
+      expect(viewFirst.classList.contains('secview')).toBeTruthy();
+    });
+    
   });
 
   describe('KorAP.Panel.Result', function () {
diff --git a/dev/js/src/panel.js b/dev/js/src/panel.js
index acdf6d8..4ebef1e 100644
--- a/dev/js/src/panel.js
+++ b/dev/js/src/panel.js
@@ -29,6 +29,9 @@
         c.push.apply(c,classes);
       this.actions = buttonGroupClass.create(c).bind(this);
 
+      //prepend or append views of the panel
+      this.prepend = false;
+      
       // Warning: This is circular
       this.actions.panel = this;
       return this;
@@ -79,12 +82,18 @@
       // Add view to views list
       this.views.push(view);
 
-      // Append element to panel element
-
+      // Append or prepend element to panel element
+      if(this.prepend){
+        this._viewElement().prepend(
+            view.element()
+          );
+        }
+      else{
       this._viewElement().appendChild(
         view.element()
       );
-
+      }
+      
       if (view.afterEmbed)
         view.afterEmbed();
       
diff --git a/dev/js/src/panel/result.js b/dev/js/src/panel/result.js
index 02c6e53..15eb479 100644
--- a/dev/js/src/panel/result.js
+++ b/dev/js/src/panel/result.js
@@ -37,6 +37,7 @@
         KorAP.Plugin.clearButtonGroup("result");
       };
       
+      this.prepend = true;
       
       return this;
     },