Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/BlogComponent/index.js
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/BlogComponent/index.js?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/BlogComponent/index.js
 (original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/BlogComponent/index.js
 Tue Apr 11 09:30:28 2017
@@ -15,68 +15,72 @@
  * limitations under the License.
  */
 
-var Handlebars = require("handlebars");
-var marked = require("marked");
-var URL = require("url");
-
-var renderer = new marked.Renderer();
-renderer.blockquote = function (quote) {
-  return "<blockquote class='blockquote'>" + quote + "</blockquote>";
-}
-
-function resolveTitle(res) {
-   return  res.properties.navTitle || res.properties.title || 
res.properties["jcr:title"] || res.name;
-
-}
+import Handlebars from "handlebars";
+import marked from "marked";
+import URL from "url";
+import pathInfo from "pathinfo";
+
+export default class BlogComponent {
+  constructor() {
+
+    this.renderer = new marked.Renderer();
+    this.renderer.blockquote = function (quote) {
+      return "<blockquote class='blockquote'>" + quote + "</blockquote>";
+    }
 
-function BlogComponent () {
-  this.templateURL = "../../hbstemplates/layout.html"
-  this.basePath = URL.getAbsoluteParent(currentNode.resource.path, 4);
-  this.baseResource = require("resource!" + this.basePath);
-  this.stylesheet = "";
-  this.partialContentTemplateURL = "../../hbstemplates/content.html";
-  this.model = currentNode;
-  this.model.title = currentNode.properties.pageTitle || 
currentNode.properties.title || currentNode.properties["jcr:title"] || 
currentNode.resource.name;
-}
 
-BlogComponent.prototype.transformMarkdown = function (content) {
-  return marked(content, { renderer: renderer});
-}
-BlogComponent.prototype.pages = function () {
-  var pages = [];
-  var homePage =
+    this.templateURL = "../../hbstemplates/layout.html"
+    this.basePath = URL.getAbsoluteParent(currentNode.resource.path, 4);
+    this.baseResource = require("resource!" + this.basePath);
+    this.stylesheet = "";
+    this.partialContentTemplateURL = "../../hbstemplates/content.html";
+    this.model = currentNode;
+    this.model.viewTypeSmall = pathInfo.hasSelector("small");
+    this.model.title = currentNode.properties.pageTitle || 
currentNode.properties.title || currentNode.properties["jcr:title"] || 
currentNode.resource.name;
+  }
+
+  resolveTitle(res) {
+    return  res.properties.navTitle || res.properties.title || 
res.properties["jcr:title"] || res.name;
+  }
+
+  transformMarkdown(content) {
+    var self = this;
+    return marked(content, { renderer: self.renderer});
+  }
+
+  pages() {
+    var self = this;
+    var pages = [];
+    var homePage =
     pages.push({
-        path: this.basePath,
-        title: resolveTitle(this.baseResource),
-        active: (currentNode.resource.path === this.basePath ? 'active' : '')
+      path: pathInfo.hasSelector("small") ? this.basePath + ".small": 
this.basePath,
+      title: self.resolveTitle(this.baseResource),
+      active: ((currentNode.resource.path.indexOf(this.basePath + 
"/posts")===0 || currentNode.resource.path === this.basePath )? 'active' : '')
+    });
+    
+    var rootPage = require("resource!" + this.basePath + "/pages");
+    var children = rootPage.children;
+
+    children.forEach(function(child){
+      var nav = {
+        path: pathInfo.hasSelector("small") ? child.path + ".small": 
child.path,
+        title: self.resolveTitle(child),
+        active: (currentNode.resource.path === child.path ? 'active' : '')
+      };
+      pages.push(nav);
     });
 
-  var rootPage = require("resource!" + this.basePath + "/pages");
-   var children = rootPage.simpleResource.children;
-
-    for(var key in children) {
-        var child =  children[key];
-        var nav = {};
-        nav.path =child.path;
-        nav.title =  resolveTitle(child) ;
-        nav.active = (currentNode.resource.path === child.path ? 'active' : 
'');
-        pages.push(nav);
-    }
-
-  return pages;
-}
-
-BlogComponent.prototype.render = function () {
-  this.init();
-  Handlebars.registerPartial('content',require("text!" + 
this.partialContentTemplateURL));
-
+    return pages;
+  }
 
-  var templateSource= require("text!" + this.templateURL);
-  var template = Handlebars.compile(templateSource);
-  this.model.style = this.stylesheet;
-  this.model.pagesNav = this.pages();
+  render() {
+    this.init();
+    Handlebars.registerPartial('content',require("text!" + 
this.partialContentTemplateURL));
+    var templateSource= require("text!" + this.templateURL);
+    var template = Handlebars.compile(templateSource);
+    this.model.style = this.stylesheet;
+    this.model.pagesNav = this.pages();
 
-  return template(this.model);
+    return template(this.model);
+  }
 }
-
-module.exports = BlogComponent;

Added: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/calculator.js
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/calculator.js?rev=1790947&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/calculator.js
 (added)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/calculator.js
 Tue Apr 11 09:30:28 2017
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function calulate(a, b) {
+  return a + b;
+}
+exports.math = calulate;
+exports.VERSION = "version 1.1 " + __dirname + " filename: " + __filename;

Added: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/package.json
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/package.json?rev=1790947&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/package.json
 (added)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/calculator/package.json
 Tue Apr 11 09:30:28 2017
@@ -0,0 +1,3 @@
+{
+    "main" : "calculator.js"
+}

Added: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/pathinfo/index.js
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/pathinfo/index.js?rev=1790947&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/pathinfo/index.js
 (added)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/esx_modules/pathinfo/index.js
 Tue Apr 11 09:30:28 2017
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+var _ = require('underscore');
+var pathInfo = sling.request.requestPathInfo;
+
+/**
+ *
+ * @param {string} selector to be searched for
+ * @return {boolean}
+ */
+function hasSelector(selector) {
+    return _.contains(pathInfo.selectors, selector);
+}
+
+exports.extension = pathInfo.extension;
+exports.hasSelector = hasSelector;
\ No newline at end of file

Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/hbstemplates/layout.html
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/hbstemplates/layout.html?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/hbstemplates/layout.html
 (original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/hbstemplates/layout.html
 Tue Apr 11 09:30:28 2017
@@ -45,6 +45,17 @@
           {{/each}}
         </ul>
       </div>
+<div class="dropdown">
+  <a class="btn btn-secondary btn-sm dropdown-toggle" 
href="https://example.com"; id="dropdownMenuLink" data-toggle="dropdown" 
aria-haspopup="true" aria-expanded="false">
+    Change View Layout
+  </a>
+
+  <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
+    <h6 class="dropdown-header">Select</h6>
+    <a class="dropdown-item {{#if viewTypeSmall}}active{{/if}}" 
href="{{resource.path}}.small.html">List View</a>
+    <a class="dropdown-item {{#unless viewTypeSmall}}active{{/unless}}" 
href="{{resource.path}}.html">Full Article</a>
+  </div>
+</div>        
 
     </nav>
 
@@ -52,6 +63,7 @@
   <div class="container">   <p class="lead">{{date}}</p>
     <h1 class="display-2">{{title}}</h1>
     <p class="lead">{{description}}</p>
+    <p>{{math.VERSION}}</p>
   </div>
 </div>
   <div class="container">
@@ -63,6 +75,6 @@
     <!-- jQuery first, then Tether, then Bootstrap JS. -->
     <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"; 
integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
 crossorigin="anonymous"></script>
     <script 
src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"; 
integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
 crossorigin="anonymous"></script>
-    <script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js";
 
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
 crossorigin="anonymous"></script>
+    <script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js";
 
integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
 crossorigin="anonymous"></script>    
   </body>
 </html>

Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/page.esx
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/page.esx?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/page.esx
 (original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/page.esx
 Tue Apr 11 09:30:28 2017
@@ -14,33 +14,32 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-var math = require("calculator");
-var pathInfo = require("./helper/pathinfo");
-var moment = require("moment");
-var _ = require('underscore');
+import math from "calculator";
+import pathInfo from "pathinfo";
+import moment from "moment";
+import BlogComponent from "BlogComponent"
+import $ from "jquery";
 
-var BlogComponent = require("BlogComponent");
-
-function PageComponent() {
-    BlogComponent.call(this);
-    this.partialContentTemplateURL = __dirname + "/templates/listing.html"
-}
-PageComponent.prototype = Object.create(BlogComponent.prototype);
-
-PageComponent.prototype.init = function () {
+class PageComponent extends BlogComponent {
+  constructor() {
+    super();
+    var template = pathInfo.hasSelector("small") 
?"/templates/listing-small.html" : "/templates/listing.html";
+    this.partialContentTemplateURL = __dirname + template;
+  }
+  init() {
+    var self = this;
     var list = [];
-    var posts = require("resource!" + this.basePath + 
"/posts").simpleResource.children;
-    for each(var post in posts) {
+    var posts = require("resource!" + this.basePath + "/posts").children;
+    posts.forEach(function(post){
         var blogPostModel = {};
         var createdAt = parseInt(post.getDateTimeProperty("jcr:created"));
-        blogPostModel.content = 
this.transformMarkdown(post.properties.content);
+        blogPostModel.content = 
self.transformMarkdown(post.properties.content);
         blogPostModel.properties = post.properties;
-        blogPostModel.path = post.path;
+        blogPostModel.path = pathInfo.hasSelector("small") ? post.path + 
".small": post.path;
         blogPostModel.date = moment(createdAt).format('MMMM Do YYYY, h:mm:ss 
a');
         list.push(blogPostModel);
-    }
-
+    });
     this.model.posts = list;
+  }
 }
-
-module.exports = new PageComponent();
\ No newline at end of file
+module.exports = new PageComponent();

Added: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/templates/listing-small.html
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/templates/listing-small.html?rev=1790947&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/templates/listing-small.html
 (added)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/page/templates/listing-small.html
 Tue Apr 11 09:30:28 2017
@@ -0,0 +1,21 @@
+{{!--/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */--}}
+<div class="list-group">
+{{#each posts}}
+  <a href="{{this.path}}.html" class="list-group-item 
list-group-item-action">{{this.properties.jcr:title}}</a>
+  {{/each}}
+</div>
\ No newline at end of file

Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/post/post.esx
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/post/post.esx?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/post/post.esx
 (original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/components/post/post.esx
 Tue Apr 11 09:30:28 2017
@@ -14,21 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+import moment from "moment";
+import _ from "underscore";
+import BlogComponent from "BlogComponent";
 
-var moment = require("moment");
-var _ = require('underscore');
-var BlogComponent = require("BlogComponent");
-
-function BlogPostComponent() {
-    BlogComponent.call(this);
+class BlogPostComponent extends BlogComponent {
+  constructor() {
+    super();
     this.partialContentTemplateURL = __dirname + "/templates/detail.html"
-}
-BlogPostComponent.prototype = Object.create(BlogComponent.prototype);
-
-BlogPostComponent.prototype.init = function () {
+  }
+  init() {
     var createdAt = 
parseInt(simpleResource.getDateTimeProperty("jcr:created"));
     this.model.blogpost = 
this.transformMarkdown(currentNode.properties.content);
     this.model.date = moment(createdAt).format('MMMM Do YYYY');
+  }
 }
 
-module.exports = new BlogPostComponent();
\ No newline at end of file
+module.exports = new BlogPostComponent();

Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/content/demo.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/content/demo.xml?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/content/demo.xml
 (original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/content/demo.xml
 Tue Apr 11 09:30:28 2017
@@ -142,6 +142,10 @@ Praesent euismod eget mi nec porta. Done
               <value>100</value>
             </property>
                 <property>
+                  <name>navTitle</name>
+                  <value>About</value>
+                </property>            
+                <property>
                   <name>jcr:title</name>
                   <value>About this Blog</value>
                 </property>

Modified: 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/package.json
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/package.json?rev=1790947&r1=1790946&r2=1790947&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/package.json 
(original)
+++ 
sling/trunk/contrib/scripting/esx/src/main/resources/libs/esx/demo/package.json 
Tue Apr 11 09:30:28 2017
@@ -10,6 +10,7 @@
   "license": "ISC",
   "dependencies": {
     "handlebars": "^4.0.6",
+    "jquery": "^3.2.1",
     "marked": "^0.3.6",
     "moment": "^2.18.0",
     "underscore": "^1.8.3"


Reply via email to