From d333a60aa4ec9a451c65e7cec0ae101b3606f07c Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 13 Oct 2015 12:29:22 +1030 Subject: [PATCH] Update for composer branch --- extensions/embed/.gitignore | 2 + extensions/embed/bootstrap.php | 16 ++- extensions/embed/composer.json | 28 ++++ extensions/embed/flarum.json | 21 --- extensions/embed/js/.gitignore | 3 - extensions/embed/js/admin/Gulpfile.js | 7 - extensions/embed/js/admin/package.json | 7 - extensions/embed/js/admin/src/main.js | 5 - extensions/embed/js/forum/Gulpfile.js | 2 +- extensions/embed/js/forum/dist/extension.js | 136 ++++++++++++++++++ extensions/embed/js/forum/src/main.js | 2 +- extensions/embed/locale/en.yml | 2 - extensions/embed/scripts/build.sh | 44 ------ extensions/embed/scripts/compile.sh | 30 ++-- ...entAction.php => DiscussionController.php} | 16 +-- extensions/embed/src/Extension.php | 12 -- .../embed/src/Listener/AddEmbedRoute.php | 33 +++++ .../embed/src/Listeners/AddClientAssets.php | 31 ---- 18 files changed, 244 insertions(+), 153 deletions(-) delete mode 100644 extensions/embed/flarum.json delete mode 100644 extensions/embed/js/.gitignore delete mode 100644 extensions/embed/js/admin/Gulpfile.js delete mode 100644 extensions/embed/js/admin/package.json delete mode 100644 extensions/embed/js/admin/src/main.js create mode 100644 extensions/embed/js/forum/dist/extension.js delete mode 100644 extensions/embed/locale/en.yml delete mode 100755 extensions/embed/scripts/build.sh rename extensions/embed/src/{ClientAction.php => DiscussionController.php} (64%) delete mode 100644 extensions/embed/src/Extension.php create mode 100644 extensions/embed/src/Listener/AddEmbedRoute.php delete mode 100644 extensions/embed/src/Listeners/AddClientAssets.php diff --git a/extensions/embed/.gitignore b/extensions/embed/.gitignore index a4f3b125e..0f98a63d8 100644 --- a/extensions/embed/.gitignore +++ b/extensions/embed/.gitignore @@ -2,3 +2,5 @@ composer.phar .DS_Store Thumbs.db +bower_components +node_modules diff --git a/extensions/embed/bootstrap.php b/extensions/embed/bootstrap.php index b3a3fa84b..481d20d97 100644 --- a/extensions/embed/bootstrap.php +++ b/extensions/embed/bootstrap.php @@ -1,5 +1,17 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ -return 'Flarum\Embed\Extension'; +use Flarum\Embed\Listener; +use Illuminate\Contracts\Events\Dispatcher; + +return function (Dispatcher $events) { + $events->subscribe(Listener\AddEmbedRoute::class); +}; \ No newline at end of file diff --git a/extensions/embed/composer.json b/extensions/embed/composer.json index d27a4b32d..94e3b8f09 100644 --- a/extensions/embed/composer.json +++ b/extensions/embed/composer.json @@ -1,7 +1,35 @@ { + "name": "flarum/embed", + "description": "Embed Flarum discussions as comments for your blog.", + "type": "flarum-extension", + "keywords": ["discussion"], + "license": "MIT", + "authors": [ + { + "name": "Toby Zerner", + "email": "toby.zerner@gmail.com" + } + ], + "support": { + "issues": "https://github.com/flarum/core/issues", + "source": "https://github.com/flarum/embed" + }, + "require": { + "flarum/core": "^0.1.0-beta.3" + }, "autoload": { "psr-4": { "Flarum\\Embed\\": "src/" } + }, + "extra": { + "flarum-extension": { + "title": "Embed", + "icon": { + "name": "code", + "backgroundColor": "#B9D233", + "color": "#fff" + } + } } } diff --git a/extensions/embed/flarum.json b/extensions/embed/flarum.json deleted file mode 100644 index 52b54047e..000000000 --- a/extensions/embed/flarum.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "embed", - "title": "Embed", - "description": "Embed Flarum discussions as comments for your blog.", - "keywords": [], - "version": "0.1.0-beta.2", - "author": { - "name": "Toby Zerner", - "email": "toby@flarum.org", - "homepage": "http://tobyzerner.com" - }, - "license": "MIT", - "require": { - "flarum": ">0.1.0-beta.2" - }, - "icon": { - "name": "code", - "backgroundColor": "#D0E800", - "color": "#fff" - } -} diff --git a/extensions/embed/js/.gitignore b/extensions/embed/js/.gitignore deleted file mode 100644 index 372e20a51..000000000 --- a/extensions/embed/js/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -bower_components -node_modules -dist diff --git a/extensions/embed/js/admin/Gulpfile.js b/extensions/embed/js/admin/Gulpfile.js deleted file mode 100644 index 64fa9ad7b..000000000 --- a/extensions/embed/js/admin/Gulpfile.js +++ /dev/null @@ -1,7 +0,0 @@ -var gulp = require('flarum-gulp'); - -gulp({ - modules: { - 'embed': 'src/**/*.js' - } -}); diff --git a/extensions/embed/js/admin/package.json b/extensions/embed/js/admin/package.json deleted file mode 100644 index 62ea6c691..000000000 --- a/extensions/embed/js/admin/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "private": true, - "devDependencies": { - "gulp": "^3.8.11", - "flarum-gulp": "^0.1.0" - } -} diff --git a/extensions/embed/js/admin/src/main.js b/extensions/embed/js/admin/src/main.js deleted file mode 100644 index 9f10bfdb7..000000000 --- a/extensions/embed/js/admin/src/main.js +++ /dev/null @@ -1,5 +0,0 @@ -import app from 'flarum/app'; - -app.initializers.add('embed', () => { - -}); diff --git a/extensions/embed/js/forum/Gulpfile.js b/extensions/embed/js/forum/Gulpfile.js index 26bc2b062..28e9aa959 100644 --- a/extensions/embed/js/forum/Gulpfile.js +++ b/extensions/embed/js/forum/Gulpfile.js @@ -5,6 +5,6 @@ gulp({ 'bower_components/iframe-resizer/js/iframeResizer.contentWindow.min.js' ], modules: { - 'embed': 'src/**/*.js' + 'flarum/embed': 'src/**/*.js' } }); diff --git a/extensions/embed/js/forum/dist/extension.js b/extensions/embed/js/forum/dist/extension.js new file mode 100644 index 000000000..f8b245915 --- /dev/null +++ b/extensions/embed/js/forum/dist/extension.js @@ -0,0 +1,136 @@ +/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v3.2.0 - 2015-09-04 + * Desc: Include this file in any page being loaded into an iframe + * to force the iframe to resize to the content size. + * Requires: iframeResizer.min.js on host page. + * Copyright: (c) 2015 David J. Bradshaw - dave@bradshaw.net + * License: MIT + */ + +!function(a){"use strict";function b(b,c,d){"addEventListener"in a?b.addEventListener(c,d,!1):"attachEvent"in a&&b.attachEvent("on"+c,d)}function c(b,c,d){"removeEventListener"in a?b.removeEventListener(c,d,!1):"detachEvent"in a&&b.detachEvent("on"+c,d)}function d(a){return a.charAt(0).toUpperCase()+a.slice(1)}function e(a){var b,c,d,e=null,f=0,g=function(){f=Ba(),e=null,d=a.apply(b,c),e||(b=c=null)};return function(){var h=Ba();f||(f=h);var i=va-(h-f);return b=this,c=arguments,0>=i||i>va?(e&&(clearTimeout(e),e=null),f=h,d=a.apply(b,c),e||(b=c=null)):e||(e=setTimeout(g,i)),d}}function f(a){return ka+"["+ma+"] "+a}function g(b){ja&&"object"==typeof a.console&&console.log(f(b))}function h(b){"object"==typeof a.console&&console.warn(f(b))}function i(){j(),g("Initialising iFrame ("+location.href+")"),k(),n(),m("background",V),m("padding",Z),z(),s(),t(),o(),B(),u(),ha=A(),M("init","Init message from host page"),Aa()}function j(){function a(a){return"true"===a?!0:!1}var b=ga.substr(la).split(":");ma=b[0],W=void 0!==b[1]?Number(b[1]):W,$=void 0!==b[2]?a(b[2]):$,ja=void 0!==b[3]?a(b[3]):ja,ia=void 0!==b[4]?Number(b[4]):ia,T=void 0!==b[6]?a(b[6]):T,X=b[7],ea=void 0!==b[8]?b[8]:ea,V=b[9],Z=b[10],sa=void 0!==b[11]?Number(b[11]):sa,ha.enable=void 0!==b[12]?a(b[12]):!1,oa=void 0!==b[13]?b[13]:oa,ya=void 0!==b[14]?b[14]:ya}function k(){function b(){var b=a.iFrameResizer;g("Reading data from page: "+JSON.stringify(b)),za=void 0!==b.messageCallback?b.messageCallback:za,Aa=void 0!==b.readyCallback?b.readyCallback:Aa,ra=void 0!==b.targetOrigin?b.targetOrigin:ra,ea=void 0!==b.heightCalculationMethod?b.heightCalculationMethod:ea,ya=void 0!==b.widthCalculationMethod?b.widthCalculationMethod:ya}"iFrameResizer"in a&&Object===a.iFrameResizer.constructor&&b()}function l(a,b){return-1!==b.indexOf("-")&&(h("Negative CSS value ignored for "+a),b=""),b}function m(a,b){void 0!==b&&""!==b&&"null"!==b&&(document.body.style[a]=b,g("Body "+a+' set to "'+b+'"'))}function n(){void 0===X&&(X=W+"px"),l("margin",X),m("margin",X)}function o(){document.documentElement.style.height="",document.body.style.height="",g('HTML & body height set to "auto"')}function p(e){function f(){M(e.eventName,e.eventType)}var h={add:function(c){b(a,c,f)},remove:function(b){c(a,b,f)}};e.eventNames&&Array.prototype.map?(e.eventName=e.eventNames[0],e.eventNames.map(h[e.method])):h[e.method](e.eventName),g(d(e.method)+" event listener: "+e.eventType)}function q(a){p({method:a,eventType:"Animation Start",eventNames:["animationstart","webkitAnimationStart"]}),p({method:a,eventType:"Animation Iteration",eventNames:["animationiteration","webkitAnimationIteration"]}),p({method:a,eventType:"Animation End",eventNames:["animationend","webkitAnimationEnd"]}),p({method:a,eventType:"Orientation Change",eventName:"orientationchange"}),p({method:a,eventType:"Input",eventName:"input"}),p({method:a,eventType:"Print",eventName:["afterprint","beforeprint"]}),p({method:a,eventType:"Transition End",eventNames:["transitionend","webkitTransitionEnd","MSTransitionEnd","oTransitionEnd","otransitionend"]}),p({method:a,eventType:"Mouse Up",eventName:"mouseup"}),p({method:a,eventType:"Mouse Down",eventName:"mousedown"}),"child"===oa&&p({method:a,eventType:"IFrame Resized",eventName:"resize"})}function r(a,b,c,d){b!==a&&(a in c||(h(a+" is not a valid option for "+d+"CalculationMethod."),a=b),g(d+' calculation method set to "'+a+'"'))}function s(){r(ea,da,Ca,"height")}function t(){r(ya,xa,Da,"width")}function u(){!0===T?(q("add"),E()):g("Auto Resize disabled")}function v(){g("Disable outgoing messages"),pa=!1}function w(){g("Remove event listener: Message"),c(a,"message",R)}function x(){null!==Y&&Y.disconnect()}function y(){v(),w(),q("remove"),x()}function z(){var a=document.createElement("div");a.style.clear="both",a.style.display="block",document.body.appendChild(a)}function A(){function c(){return{x:void 0!==a.pageXOffset?a.pageXOffset:document.documentElement.scrollLeft,y:void 0!==a.pageYOffset?a.pageYOffset:document.documentElement.scrollTop}}function d(a){var b=a.getBoundingClientRect(),d=c();return{x:parseInt(b.left,10)+parseInt(d.x,10),y:parseInt(b.top,10)+parseInt(d.y,10)}}function e(a){function b(a){var b=d(a);g("Moving to in page link (#"+c+") at x: "+b.x+" y: "+b.y),Q(b.y,b.x,"scrollToOffset")}var c=a.split("#")[1]||a,e=decodeURIComponent(c),f=document.getElementById(e)||document.getElementsByName(e)[0];void 0!==f?b(f):(g("In page link (#"+c+") not found in iFrame, so sending to parent"),Q(0,0,"inPageLink","#"+c))}function f(){""!==location.hash&&"#"!==location.hash&&e(location.href)}function i(){function a(a){function c(a){a.preventDefault(),e(this.getAttribute("href"))}"#"!==a.getAttribute("href")&&b(a,"click",c)}Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'),a)}function j(){b(a,"hashchange",f)}function k(){setTimeout(f,aa)}function l(){Array.prototype.forEach&&document.querySelectorAll?(g("Setting up location.hash handlers"),i(),j(),k()):h("In page linking not fully supported in this browser! (See README.md for IE8 workaround)")}return ha.enable?l():g("In page linking not enabled"),{findTarget:e}}function B(){g("Enable public methods"),a.parentIFrame={close:function(){Q(0,0,"close"),y()},getId:function(){return ma},moveToAnchor:function(a){ha.findTarget(a)},reset:function(){P("parentIFrame.reset")},scrollTo:function(a,b){Q(b,a,"scrollTo")},scrollToOffset:function(a,b){Q(b,a,"scrollToOffset")},sendMessage:function(a,b){Q(0,0,"message",JSON.stringify(a),b)},setHeightCalculationMethod:function(a){ea=a,s()},setWidthCalculationMethod:function(a){ya=a,t()},setTargetOrigin:function(a){g("Set targetOrigin: "+a),ra=a},size:function(a,b){var c=""+(a?a:"")+(b?","+b:"");N(),M("size","parentIFrame.size("+c+")",a,b)}}}function C(){0!==ia&&(g("setInterval: "+ia+"ms"),setInterval(function(){M("interval","setInterval: "+ia)},Math.abs(ia)))}function D(){function b(a){function b(a){!1===a.complete&&(g("Attach listeners to "+a.src),a.addEventListener("load",f,!1),a.addEventListener("error",h,!1),k.push(a))}"attributes"===a.type&&"src"===a.attributeName?b(a.target):"childList"===a.type&&Array.prototype.forEach.call(a.target.querySelectorAll("img"),b)}function c(a){k.splice(k.indexOf(a),1)}function d(a){g("Remove listeners from "+a.src),a.removeEventListener("load",f,!1),a.removeEventListener("error",h,!1),c(a)}function e(a,b,c){d(a.target),M(b,c+": "+a.target.src,void 0,void 0)}function f(a){e(a,"imageLoad","Image loaded")}function h(a){e(a,"imageLoadFailed","Image load failed")}function i(a){M("mutationObserver","mutationObserver: "+a[0].target+" "+a[0].type),a.forEach(b)}function j(){var a=document.querySelector("body"),b={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0};return m=new l(i),g("Enable MutationObserver"),m.observe(a,b),m}var k=[],l=a.MutationObserver||a.WebKitMutationObserver,m=j();return{disconnect:function(){"disconnect"in m&&(g("Disconnect MutationObserver"),m.disconnect(),k.forEach(d))}}}function E(){var b=0>ia;a.MutationObserver||a.WebKitMutationObserver?b?C():Y=D():(g("MutationObserver not supported in this browser!"),C())}function F(a){function b(a){var b=/^\d+(px)?$/i;if(b.test(a))return parseInt(a,U);var d=c.style.left,e=c.runtimeStyle.left;return c.runtimeStyle.left=c.currentStyle.left,c.style.left=a||0,a=c.style.pixelLeft,c.style.left=d,c.runtimeStyle.left=e,a}var c=document.body,d=0;return"defaultView"in document&&"getComputedStyle"in document.defaultView?(d=document.defaultView.getComputedStyle(c,null),d=null!==d?d[a]:0):d=b(c.currentStyle[a]),parseInt(d,U)}function G(a){a>va/2&&(va=2*a,g("Event throttle increased to "+va+"ms"))}function H(a,b){for(var c=b.length,e=0,f=0,h=d(a),i=Ba(),j=0;c>j;j++)e=b[j].getBoundingClientRect()[a]+F("margin"+h),e>f&&(f=e);return i=Ba()-i,g("Parsed "+c+" HTML elements"),g("Element position calculated in "+i+"ms"),G(i),f}function I(a){return[a.bodyOffset(),a.bodyScroll(),a.documentElementOffset(),a.documentElementScroll()]}function J(a,b){function c(){return h("No tagged elements ("+b+") found on page"),ca}var d=document.querySelectorAll("["+b+"]");return 0===d.length?c():H(a,d)}function K(){return document.querySelectorAll("body *")}function L(a,b,c,d){function e(){ca=l,wa=m,Q(ca,wa,a)}function f(){function a(a,b){var c=Math.abs(a-b)<=sa;return!c}return l=void 0!==c?c:Ca[ea](),m=void 0!==d?d:Da[ya](),a(ca,l)||$&&a(wa,m)}function h(){return!(a in{init:1,interval:1,size:1})}function i(){return ea in na||$&&ya in na}function j(){g("No change in size detected")}function k(){h()&&i()?P(b):a in{interval:1}||j()}var l,m;f()||"init"===a?(N(),e()):k()}function M(a,b,c,d){function e(){a in{reset:1,resetPage:1,init:1}||g("Trigger event: "+b)}function f(){return ta&&a in _}f()?g("Trigger event cancelled: "+a):(e(),Ea(a,b,c,d))}function N(){ta||(ta=!0,g("Trigger event lock on")),clearTimeout(ua),ua=setTimeout(function(){ta=!1,g("Trigger event lock off"),g("--")},aa)}function O(a){ca=Ca[ea](),wa=Da[ya](),Q(ca,wa,a)}function P(a){var b=ea;ea=da,g("Reset trigger event: "+a),N(),O("reset"),ea=b}function Q(a,b,c,d,e){function f(){void 0===e?e=ra:g("Message targetOrigin: "+e)}function h(){var f=a+":"+b,h=ma+":"+f+":"+c+(void 0!==d?":"+d:"");g("Sending message to host page ("+h+")"),qa.postMessage(ka+h,e)}!0===pa&&(f(),h())}function R(b){function c(){return ka===(""+b.data).substr(0,la)}function d(){ga=b.data,qa=b.source,i(),ba=!1,setTimeout(function(){fa=!1},aa)}function e(){fa?g("Page reset ignored by init"):(g("Page size reset by host page"),O("resetPage"))}function f(){M("resizeParent","Parent window requested size check")}function h(){var a=k();ha.findTarget(a)}function j(){return b.data.split("]")[1].split(":")[0]}function k(){return b.data.substr(b.data.indexOf(":")+1)}function l(){return"iFrameResize"in a}function m(){var a=k();g("MessageCallback called from parent: "+a),za(JSON.parse(a)),g(" --")}function n(){return b.data.split(":")[2]in{"true":1,"false":1}}function o(){switch(j()){case"reset":e();break;case"resize":f();break;case"moveToAnchor":h();break;case"message":m();break;default:!l()&&!n()}}function p(){!1===ba?o():n()?d():g('Ignored message of type "'+j()+'". Received before initialization.')}c()&&p()}function S(){"loading"!==document.readyState&&a.parent.postMessage("[iFrameResizerChild]Ready","*")}var T=!0,U=10,V="",W=0,X="",Y=null,Z="",$=!1,_={resize:1,click:1},aa=128,ba=!0,ca=1,da="bodyOffset",ea=da,fa=!0,ga="",ha={},ia=32,ja=!1,ka="[iFrameSizer]",la=ka.length,ma="",na={max:1,min:1,bodyScroll:1,documentElementScroll:1},oa="child",pa=!0,qa=a.parent,ra="*",sa=0,ta=!1,ua=null,va=0,wa=1,xa="scroll",ya=xa,za=function(){h("MessageCallback function not defined")},Aa=function(){},Ba=Date.now||function(){return(new Date).getTime()},Ca={bodyOffset:function(){return document.body.offsetHeight+F("marginTop")+F("marginBottom")},offset:function(){return Ca.bodyOffset()},bodyScroll:function(){return document.body.scrollHeight},documentElementOffset:function(){return document.documentElement.offsetHeight},documentElementScroll:function(){return document.documentElement.scrollHeight},max:function(){return Math.max.apply(null,I(Ca))},min:function(){return Math.min.apply(null,I(Ca))},grow:function(){return Ca.max()},lowestElement:function(){return Math.max(Ca.bodyOffset(),H("bottom",K()))},taggedElement:function(){return J("bottom","data-iframe-height")}},Da={bodyScroll:function(){return document.body.scrollWidth},bodyOffset:function(){return document.body.offsetWidth},documentElementScroll:function(){return document.documentElement.scrollWidth},documentElementOffset:function(){return document.documentElement.offsetWidth},scroll:function(){return Math.max(Da.bodyScroll(),Da.documentElementScroll())},max:function(){return Math.max.apply(null,I(Da))},min:function(){return Math.min.apply(null,I(Da))},leftMostElement:function(){return H("left",K())},taggedElement:function(){return J("left","data-iframe-width")}},Ea=e(L);b(a,"message",R),S()}(window||{}); +//# sourceMappingURL=iframeResizer.contentWindow.map +System.register('flarum/embed/main', ['flarum/extend', 'flarum/app', 'flarum/components/Composer', 'flarum/components/ModalManager', 'flarum/components/AlertManager', 'flarum/embed/components/DiscussionPage'], function (_export) { + 'use strict'; + + var override, app, Composer, ModalManager, AlertManager, DiscussionPage; + return { + setters: [function (_flarumExtend) { + override = _flarumExtend.override; + }, function (_flarumApp) { + app = _flarumApp['default']; + }, function (_flarumComponentsComposer) { + Composer = _flarumComponentsComposer['default']; + }, function (_flarumComponentsModalManager) { + ModalManager = _flarumComponentsModalManager['default']; + }, function (_flarumComponentsAlertManager) { + AlertManager = _flarumComponentsAlertManager['default']; + }, function (_flarumEmbedComponentsDiscussionPage) { + DiscussionPage = _flarumEmbedComponentsDiscussionPage['default']; + }], + execute: function () { + + app.initializers.add('boot', function () { + override(m, 'route', function (original, root, arg1, arg2, vdom) { + if (root.addEventListener || root.attachEvent) { + root.href = vdom.attrs.href; + root.target = '_blank'; + + // TODO: If href leads to a post within this discussion that we have + // already loaded, then scroll to it? + return; + } + + original.apply(this, arguments); + }); + + app.composer = m.mount(document.getElementById('composer'), Composer.component()); + app.modal = m.mount(document.getElementById('modal'), ModalManager.component()); + app.alerts = m.mount(document.getElementById('alerts'), AlertManager.component()); + + m.mount(document.getElementById('content'), DiscussionPage.component()); + }); + } + }; +}); +System.register('flarum/embed/components/DiscussionPage', ['flarum/Component', 'flarum/components/PostStream'], function (_export) { + 'use strict'; + + var Component, PostStream, DiscussionPage; + + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + + var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + + function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + + return { + setters: [function (_flarumComponent) { + Component = _flarumComponent['default']; + }, function (_flarumComponentsPostStream) { + PostStream = _flarumComponentsPostStream['default']; + }], + execute: function () { + DiscussionPage = (function (_Component) { + _inherits(DiscussionPage, _Component); + + function DiscussionPage() { + _classCallCheck(this, DiscussionPage); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + _get(Object.getPrototypeOf(DiscussionPage.prototype), 'constructor', this).apply(this, args); + + /** + * The discussion that is being viewed. + * + * @type {Discussion} + */ + var discussion = this.discussion = app.preloadedDocument(); + + var includedPosts = []; + if (discussion.payload && discussion.payload.included) { + includedPosts = discussion.payload.included.filter(function (record) { + return record.type === 'posts' && record.relationships && record.relationships.discussion; + }).map(function (record) { + return app.store.getById('posts', record.id); + }).sort(function (a, b) { + return a.id() - b.id(); + }).slice(0, 20); + } + + this.stream = new PostStream({ discussion: discussion, includedPosts: includedPosts }); + } + + _createClass(DiscussionPage, [{ + key: 'view', + value: function view() { + return m( + 'div', + { className: 'DiscussionPage' }, + m( + 'div', + { 'class': 'container' }, + m( + 'div', + { className: 'DiscussionPage-discussion' }, + m( + 'div', + { className: 'DiscussionPage-stream' }, + this.stream.render() + ) + ) + ) + ); + } + }]); + + return DiscussionPage; + })(Component); + + _export('default', DiscussionPage); + } + }; +}); \ No newline at end of file diff --git a/extensions/embed/js/forum/src/main.js b/extensions/embed/js/forum/src/main.js index 0db77bb7b..89707803f 100644 --- a/extensions/embed/js/forum/src/main.js +++ b/extensions/embed/js/forum/src/main.js @@ -4,7 +4,7 @@ import Composer from 'flarum/components/Composer'; import ModalManager from 'flarum/components/ModalManager'; import AlertManager from 'flarum/components/AlertManager'; -import DiscussionPage from 'embed/components/DiscussionPage'; +import DiscussionPage from 'flarum/embed/components/DiscussionPage'; app.initializers.add('boot', () => { override(m, 'route', function(original, root, arg1, arg2, vdom) { diff --git a/extensions/embed/locale/en.yml b/extensions/embed/locale/en.yml deleted file mode 100644 index af6a379f8..000000000 --- a/extensions/embed/locale/en.yml +++ /dev/null @@ -1,2 +0,0 @@ -embed: - # hello_world: "Hello, world!" diff --git a/extensions/embed/scripts/build.sh b/extensions/embed/scripts/build.sh deleted file mode 100755 index 6f86e3b4e..000000000 --- a/extensions/embed/scripts/build.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -cd $(dirname $0) -base="${PWD}/.." - -cd $base - -if [ ! -f flarum.json ]; then -echo "Could not find flarum.json file!" -exit 1 -fi - -extension=$(php < ${release}/release.zip - -cd ${release} -unzip release.zip -d ./ -rm release.zip - -bash "${base}/scripts/compile.sh" -wait - -# Delete files -rm -rf ${release}/scripts -rm -rf `find . -type d -name node_modules` -rm -rf `find . -type d -name bower_components` - -# Finally, create the release archive -cd ${release} -find . -type d -exec chmod 0750 {} + -find . -type f -exec chmod 0644 {} + -chmod 0775 . -zip -r ${extension}.zip ./ -mv ${extension}.zip ${base}/${extension}.zip diff --git a/extensions/embed/scripts/compile.sh b/extensions/embed/scripts/compile.sh index c8716eca2..b0d8e8bd3 100755 --- a/extensions/embed/scripts/compile.sh +++ b/extensions/embed/scripts/compile.sh @@ -1,13 +1,27 @@ #!/usr/bin/env bash + +# This script compiles the extension so that it can be used in a Flarum +# installation. It should be run from the root directory of the extension. + base=$PWD -cd $base -composer install --prefer-dist --optimize-autoloader --ignore-platform-reqs --no-dev +cd "${base}/js" -cd "${base}/js/forum" -npm install -gulp --production +if [ -f bower.json ]; then + bower install +fi -cd "${base}/js/admin" -npm install -gulp --production +for app in forum admin; do + cd "${base}/js" + + if [ -d $app ]; then + cd $app + + if [ -f bower.json ]; then + bower install + fi + + npm install + gulp --production + fi +done diff --git a/extensions/embed/src/ClientAction.php b/extensions/embed/src/DiscussionController.php similarity index 64% rename from extensions/embed/src/ClientAction.php rename to extensions/embed/src/DiscussionController.php index f3742b7b2..15e3228fc 100644 --- a/extensions/embed/src/ClientAction.php +++ b/extensions/embed/src/DiscussionController.php @@ -10,28 +10,26 @@ namespace Flarum\Embed; -use Flarum\Forum\Actions\DiscussionAction as DiscussionAction; -use Psr\Http\Message\ServerRequestInterface as Request; +use Flarum\Forum\Controller\DiscussionController as BaseDiscussionController; +use Psr\Http\Message\ServerRequestInterface; -class ClientAction extends DiscussionAction +class DiscussionController extends BaseDiscussionController { /** * {@inheritdoc} - * - * @return ClientView */ - public function render(Request $request, array $routeParams = []) + public function render(ServerRequestInterface $request) { - $view = parent::render($request, $routeParams); + $view = parent::render($request); - $view->addBootstrapper('embed/main'); + $view->addBootstrapper('flarum/embed/main'); $view->setLayout(__DIR__.'/../views/embed.blade.php'); return $view; } /** - * @inheritdoc + * {@inheritdoc} */ protected function getAssets() { diff --git a/extensions/embed/src/Extension.php b/extensions/embed/src/Extension.php deleted file mode 100644 index 1cb3a0451..000000000 --- a/extensions/embed/src/Extension.php +++ /dev/null @@ -1,12 +0,0 @@ -subscribe('Flarum\Embed\Listeners\AddClientAssets'); - } -} diff --git a/extensions/embed/src/Listener/AddEmbedRoute.php b/extensions/embed/src/Listener/AddEmbedRoute.php new file mode 100644 index 000000000..83da778cd --- /dev/null +++ b/extensions/embed/src/Listener/AddEmbedRoute.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Embed\Listener; + +use Flarum\Event\ConfigureForumRoutes; +use Illuminate\Contracts\Events\Dispatcher; + +class AddEmbedRoute +{ + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen(ConfigureForumRoutes::class, [$this, 'addEmbedRoute']); + } + + /** + * @param ConfigureForumRoutes $event + */ + public function addEmbedRoute(ConfigureForumRoutes $event) + { + $event->get('/embed/{id:\d+}', 'embed.discussion', 'Flarum\Embed\DiscussionController'); + } +} diff --git a/extensions/embed/src/Listeners/AddClientAssets.php b/extensions/embed/src/Listeners/AddClientAssets.php deleted file mode 100644 index 59921afef..000000000 --- a/extensions/embed/src/Listeners/AddClientAssets.php +++ /dev/null @@ -1,31 +0,0 @@ -listen(RegisterLocales::class, [$this, 'addLocale']); - $events->listen(BuildClientView::class, [$this, 'addAssets']); - $events->listen(RegisterForumRoutes::class, [$this, 'addEmbedRoute']); - } - - public function addLocale(RegisterLocales $event) - { - $event->addTranslations('en', __DIR__.'/../../locale/en.yml'); - } - - public function addAssets(BuildClientView $event) - { - - } - - public function addEmbedRoute(RegisterForumRoutes $event) - { - $event->get('/embed/{id:\d+}', 'embed.discussion', 'Flarum\Embed\ClientAction'); - } -}