Somewhat working carousel
body {
}
+
+.navigator-breadcrumbs {
+ padding: 4pt;
+ font-size: 14pt;
+}
+
+.navigator-carousel > * {
+ min-width: 50%;
+ padding: 8pt;
+}
enyo.kind({
name: "Blerg",
+ kind: "FittableRows",
components: [
- {content: "Hello!"}
- ]
+ {kind: "onyx.Toolbar", components: [
+ {content: "Blerg Mobile"}
+ ]},
+ {name: "navigator", kind: "Navigator", fit: true}
+ ],
+ create: function() {
+ this.inherited(arguments);
+ this.$.navigator.waterfall('onContentLoad', {
+ });
+ }
});
+enyo.kind({
+ name: "Listing",
+ kind: "FittableRows",
+ published: {
+ title: "Listing"
+ },
+ components: [
+ {name: "title", content: "Listing", tag: "h2"},
+ {name: "list", kind: "List", onSetupItem: "setupItem", count:10, fit: true, components: [
+ {name: "record", kind: "blerg.Record", ontap: "itemTap"}
+ ]}
+ ],
+ create: function() {
+ this.inherited(arguments);
+ this.titleChanged();
+ },
+ setupItem: function(inSender, inEvent) {
+ this.$.record.setAuthor("Blerger");
+ this.$.record.setTimestamp(new Date().getTime() / 1000);
+ this.$.record.setData("Blerg " + inEvent.index);
+ },
+ itemTap: function(inSender, inEvent) {
+ this.bubble('onContentLoad', {author: this.$.record.getAuthor});
+ },
+ titleChanged: function() {
+ this.$.title.setContent(this.title);
+ }
+});
+enyo.kind({
+ name: "Navigator",
+ kind: "FittableRows",
+ handlers: {
+ onContentLoad: "contentLoad"
+ },
+ count: 0,
+ components: [
+ {name: "breadcrumbs", classes: "navigator-breadcrumbs"},
+ {name: "carousel", kind: "Panels", arrangerKind: "CarouselArranger", classes: "navigator-carousel", fit: true}
+ ],
+ contentLoad: function(inSender, inEvent) {
+ if (this.count > 0 && inEvent.originator.kind == "Listing") {
+ for (var i = 0; i < this.$.carousel.children.length; i++) {
+ if (this.$.carousel.children[i] == inEvent.originator)
+ break;
+ }
+ while (this.$.carousel.children.length - 1 > i) {
+ this.$.carousel.children[i + 1].destroy();
+ this.count--;
+ }
+ }
+
+ var newpage = this.$.carousel.createComponent({
+ kind: "Listing",
+ title: "Listing " + this.count
+ });
+ this.render();
+ this.count++;
+ this.$.carousel.setIndex(this.count - 1);
+ this.updateBreadcrumbs();
+ },
+ updateBreadcrumbs: function() {
+ while (this.$.breadcrumbs.children.length > 0)
+ this.$.breadcrumbs.children[0].destroy();
+
+ var crumbs = [];
+ for (var i = 0; i < this.$.carousel.children.length; i++) {
+ this.$.breadcrumbs.createComponent({
+ kind: "onyx.Button",
+ content: this.$.carousel.children[i].title
+ });
+ if (i < this.$.carousel.children.length - 1)
+ this.$.breadcrumbs.createComponent({tag: null, content: " >> "});
+ }
+ this.$.breadcrumbs.render();
+ },
+ selectPage: function(inSender, inEvent) {
+ this.$.carousel.setIndex(inSender.relatedPage);
+ }
+});
+enyo.kind({
+ name: "blerg.Record",
+ kind: "Control",
+ classes: "record",
+ published: {
+ data: "",
+ timestamp: 0,
+ author: "",
+ record: null
+ },
+ components: [
+ {name: "data", tag: null, allowHtml: true},
+ {classes: "info", components: [
+ {tag: null, content: "Posted "},
+ {name: "date", tag: null}
+ ]}
+ ],
+ create: function() {
+ this.inherited(arguments);
+ this.dataChanged();
+ this.timestampChanged();
+ this.updateLinks();
+ },
+ dataChanged: function() {
+ this.$.data.setContent(blerg.Util.blergFormat(this.data));
+ },
+ timestampChanged: function() {
+ this.$.date.setContent(new Date(this.timestamp * 1000).toString());
+ },
+ authorChanged: function() {
+ this.updateLinks();
+ },
+ recordChanged: function() {
+ this.updateLinks();
+ },
+ updateLinks: function() {
+ },
+ postPopup: function() {
+ this.bubble('onPostVisibility', {
+ showing: true,
+ data: enyo.macroize("@{$author}/{$record}: ", this)
+ });
+ return true;
+ }
+});
+
+enyo.kind({
+ name: "blerg.TagRecord",
+ kind: "blerg.Record",
+ components: [
+ {name: "data", tag: null, allowHtml: true},
+ {classes: "info", components: [
+ {tag: null, content: "Posted by "},
+ {name: "author", kind: "Control", classes: "author ref"},
+ {tag: null, content: " at "},
+ {name: "date", tag: null},
+ {tag: null, content: ". "},
+ ]}
+ ],
+ updateLinks: function() {
+ this.inherited(arguments);
+ this.$.author.setContent('@' + this.author);
+ }
+});
+
+enyo.kind({
+ name: "blerg.BriefRecord",
+ kind: "blerg.Record",
+ components: [
+ {name: "authorlink", kind: "Control", classes: "author ref"},
+ {tag: null, content: " "},
+ {name: "data", tag: null}
+ ],
+ dataChanged: function() {
+ var d = this.data.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+ this.$.data.setContent(d);
+ },
+ timestampChanged: function() { },
+ updateLinks: function() {
+ this.$.authorlink.setContent('@' + this.author);
+ },
+});
+blerg = window.blerg || {};
+
+blerg.Util = {};
+
+// Dirty, terrible shim for rewritten links below
+blerg.Util.qlink = function() {
+ try {
+ location.href = event.target.href;
+ } catch(e) { }
+ enyo.$.blerg.bubble('onNavigate');
+ return false;
+}
+
+blerg.Util.formatLinkHooks = [
+];
+
+blerg.Util.formatMarkdownLinks = function(l) {
+ m = l.match(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)(\s([^)]*))?\)/);
+ if (!m)
+ return l;
+ var whitespace = m[1];
+ var data = {
+ label: m[2],
+ url: m[3],
+ extra: m[5]
+ };
+
+ for (var i = 0; i < blerg.Util.formatLinkHooks.length; i++) {
+ var newdata = blerg.Util.formatLinkHooks[i].process(data);
+ if (newdata)
+ data = newdata;
+ else
+ console.warn("Format Link Hook " + i + " returned null");
+ }
+ var s = whitespace + '<a href="' + data.url + '">' + data.label + '</a>' +
+ (data.widget ? ' ' + data.widget : '');
+ return l.slice(0, m.index) + s + blerg.Util.formatMarkdownLinks(l.slice(m.index + m[0].length));
+}
+
+blerg.Util.blergFormat = function(text) {
+ var lines = text.split(/\r?\n/);
+ if (lines[lines.length - 1] == '')
+ lines.pop();
+
+ var out = ['<p>'];
+ var endpush = null;
+ var listMode = false;
+ lines.forEach(function(l) {
+ if (l == '') {
+ if (out[out.length - 1] == '<br>') {
+ out[out.length - 1] = '<p>';
+ }
+ if (out[out.length - 1] == '</li>') {
+ out.push('</ul>');
+ out.push('<p>');
+ listMode = false;
+ }
+ return;
+ }
+
+ // Put quoted material into a special paragraph
+ if (l[0] == '>') {
+ var pi = out.lastIndexOf('<p>');
+ if (pi != -1) {
+ out[pi] = '<p class="quote">';
+ l = l.replace(/^>\s*/, '');
+ }
+ }
+
+ // Sanitize HTML input
+ l = l.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+
+ // Turn HTTP URLs into links
+ l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
+
+ // Turn markdown links into links
+ l = blerg.Util.formatMarkdownLinks(l);
+
+ // Turn *foo* into italics and **foo** into bold
+ l = l.replace(/([^\w\\]|^)\*\*(\w[^*]*)\*\*(\W|$)/g, '$1<b>$2</b>$3');
+ l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1<i>$2</i>$3');
+
+ // Turn refs and tags into links
+ l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return blerg.Util.qlink()">#$2</a>');
+ l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)(\/\d+)?/g, '$1<a href="#$2$3" class="ref" onclick="return blerg.Util.qlink()">@$2</a>');
+
+ // Create lists when lines begin with *
+ if (l[0] == '*') {
+ if (!listMode) {
+ var pi = out.lastIndexOf('<p>');
+ out[pi] = '<ul>';
+ listMode = true;
+ }
+ l = l.replace(/^\*\s*/, '');
+ out.push('<li>');
+ endpush = '</li>';
+ }
+
+ // Create headers when lines begin with = or #
+ if (l[0] == '=' || l[0] == '#') {
+ var m = l.match(/^([=#]+)/);
+ var depth = m[1].length;
+ if (depth <= 5) {
+ l = l.replace(/^[=#]+\s*/, '').replace(/\s*[=#]+$/, '');
+ out.push('<h' + depth + '>');
+ endpush = '</h' + depth + '>';
+ }
+ }
+
+ // Remove backslashes from escaped metachars
+ l = l.replace(/\\([*\[\]@#])/g, '$1');
+
+ out.push(l);
+ if (endpush) {
+ out.push(endpush);
+ endpush = null;
+ } else {
+ out.push('<br>');
+ }
+ });
+ while (out[out.length - 1] == '<br>' || out[out.length - 1] == '<p>')
+ out.pop();
+ if (listMode)
+ out.push('</ul>');
+
+ return out.join('');
+}
enyo.depends(
'$lib/layout',
'$lib/onyx',
+ 'Util.js',
'Blerg.css',
- 'Blerg.js'
+ 'Blerg.js',
+ 'Record.js',
+ 'Navigator.js',
+ 'Listing.js'
);