]> _ Git - physioassist.git/commitdiff
#simeox Add news page functionality with infinite scroll, change position of language...
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 4 May 2016 18:57:24 +0000 (18:57 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Wed, 4 May 2016 18:57:24 +0000 (18:57 +0000)
19 files changed:
framework/application/Bootstrap.php
framework/application/Simeox/News.php [new file with mode: 0644]
framework/application/controllers/AjaxController.php
framework/application/forms/CMS/News.php [new file with mode: 0644]
framework/application/forms/CMS/Sub/News.php [new file with mode: 0644]
framework/application/forms/Element/News.php [new file with mode: 0644]
framework/application/models/News.php [new file with mode: 0644]
framework/application/views/scripts/common/body.phtml [new file with mode: 0644]
framework/application/views/scripts/common/content.phtml
framework/application/views/scripts/common/footer.phtml
framework/application/views/scripts/common/header.phtml
framework/application/views/scripts/templates/home.phtml
framework/application/views/scripts/templates/news.phtml [new file with mode: 0644]
framework/application/views/scripts/templates/text.phtml
js/news.js [new file with mode: 0644]
less/common.less
less/home.less [new file with mode: 0644]
less/navigation.less
less/news.less [new file with mode: 0644]

index c8c9a6e06ab766730f6b96e9694d42c260738290..5c81d663e98c78706fdff5e59c4afa616eedc809 100644 (file)
@@ -16,6 +16,7 @@ class Bootstrap extends CubeIT_Bootstrap {
        public function getCMSTemplates() {
                $templates = parent::getCMSTemplates();
                $templates['text'] = 'Page de texte';
+               $templates['news'] = 'Actualités';
                return $templates;
        }
 
diff --git a/framework/application/Simeox/News.php b/framework/application/Simeox/News.php
new file mode 100644 (file)
index 0000000..5b54c57
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class Simeox_News {
+
+    protected static $imageSize = 163; // Images are cropped square
+
+    public static function getNews($page = 1, $perPage = 3) {
+
+        //###TEMPORARY! Produce endless stream of data for testing infinite scroll
+        //$page = ($page > 1) ? 1 : $page;
+        //fb('Fetching page #'. $page);
+
+
+        $db = Bootstrap::getInstance()->getDb();
+        $news_result = $db->select()->from('news')
+            ->order('date DESC')
+            ->limit($perPage, ($page - 1) * $perPage)
+            ->query()
+            ->fetchAll();
+
+        $news_result = CubeIT_Util_Cms::unserialize($news_result);
+
+        $news = array();
+
+        foreach ($news_result as $n) {
+
+            $date = new CubeIT_Date($n->date, CubeIT_Date::MYSQL);
+
+            $news[] = array(
+                'date' => $date->toString('dd/MM/YYYY'),
+                'headline' => $n->headline,
+                'content' => Bootstrap::getInstance()->getView()->markupDotclear($n->content, array(), array('class' => 'news-content')),
+                'image' => Bootstrap::getInstance()->getView()->imageProcess($n->image, $n->headline, self::$imageSize, self::$imageSize, array(), 'C', 'C', 'M', false, 'auto', 'transparent')
+            );
+        }
+
+        return CubeIT_Util_Cms::unserialize($news);
+    }
+}
\ No newline at end of file
index 7cef6709cf7a4393e0c9df20f2e5c8acc1f46b8c..df33fd3cef5d9c5fa112fb439661425e7a17c863 100644 (file)
@@ -2,7 +2,9 @@
 
 class AjaxController extends CubeIT_Controller_AjaxController {
 
-
+    public function news($page = 1, $perPage = 5) {
+        $this->_datas->addVariable('data', Simeox_News::getNews($page, $perPage));
+    }
 
 }
 
diff --git a/framework/application/forms/CMS/News.php b/framework/application/forms/CMS/News.php
new file mode 100644 (file)
index 0000000..3d99ca2
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+
+class Simeox_Form_CMS_News extends CubeIT_Form_CMS {
+    public function init() {
+        parent::init();
+
+        $title = new Zend_Form_Element_Text('title');
+        $title->setLabel(__('Titre'));
+        $this->addElement($title);
+
+        $news = new Simeox_Form_Element_News('news_items');
+        $news->setLabel(__('Gestion des actualités'));
+        $this->addElement($news);
+    }
+}
\ No newline at end of file
diff --git a/framework/application/forms/CMS/Sub/News.php b/framework/application/forms/CMS/Sub/News.php
new file mode 100644 (file)
index 0000000..969026f
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class Simeox_Form_CMS_Sub_News extends CubeIT_Form_List_Model {
+
+    public function init() {
+        parent::init();
+
+        $isCompactTrad = false;
+
+        $id = new CubeIT_Form_Element_Id();
+        $this->addElement($id);
+
+        $date = new CubeIT_Form_Element_Date('date');
+        $date->setPrecision(Zend_Date::DAY);
+        $date->setLabel(__('Date'));
+        $this->addElement($date);
+
+        $headline = new Zend_Form_Element_Text('headline');
+        $headline->setLabel(__('Titre'));
+        $this->addElementLocalized($headline, $isCompactTrad);
+
+        $content = new Simeox_Form_Element_Markitup('content');
+        $content->setLabel(__('Contents'));
+        $this->addElementLocalized($content, $isCompactTrad);
+
+        $image = new CubeIT_Form_Element_File_Image('image');
+        $image->setLabel(__('Image'));
+        $this->addElement($image);
+
+        $this->setListTitle(__('Actualités'));
+        $this->setNewTitle(__('Nouvelle actualité'));
+        $this->setEditTitle(__('Edition de l\'actualité « $headline »'));
+        $this->setModel('Simeox_Model_News');
+        $this->setTitleColumn('headline');
+        $this->setAdditionnalColumns(array('date'));
+
+    }
+
+}
diff --git a/framework/application/forms/Element/News.php b/framework/application/forms/Element/News.php
new file mode 100644 (file)
index 0000000..7d9b4ee
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+
+class Simeox_Form_Element_News extends CubeIT_Form_Element_List {
+
+    public function init() {
+        parent::init();
+
+        $this->setBaseForm(new Simeox_Form_CMS_Sub_News());
+        $this->clearDecorators();
+    }
+
+}
\ No newline at end of file
diff --git a/framework/application/models/News.php b/framework/application/models/News.php
new file mode 100644 (file)
index 0000000..f35e99b
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+class Simeox_Model_News extends CubeIT_Model_Data_Table {
+
+    protected static $_table = 'news';
+    protected $date;
+    protected $headline;
+    protected $content;
+    protected $image;
+
+    protected $_types = array('date' => 'date');
+
+    public static function getSchema($schema) {
+        $table = parent::getSchema($schema);
+        $table->addColumn('date', 'datetime');
+        $table->addColumn('headline', 'text');
+        $table->addColumn('content', 'text');
+        $table->addColumn('image', 'text');
+    }
+
+}
\ No newline at end of file
diff --git a/framework/application/views/scripts/common/body.phtml b/framework/application/views/scripts/common/body.phtml
new file mode 100644 (file)
index 0000000..ca65cad
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/* @var $this Zend_View */
+
+$bodyClass = $this->body_class . ' ' . $this->bodyClass;
+
+$class = isset($this->navigation()->view->currentPage) ? $this->navigation()->view->currentPage->getName() : ''; // Or should it be label?
+$class.=' '.$bodyClass;
+
+echo '<body class="' . trim($class) . '">' . "\n";
+echo $this->bannerCookies();
+echo $this->render('admin/mockup.phtml');
+echo $this->render('admin/nav.phtml');
+echo $this->render('common/content.phtml');
+echo $this->render('ajax/loader.phtml');
+echo "\n" . '</body>' . "\n";
\ No newline at end of file
index 122b2257b0eff03f515c639b611ad9ccf97b4369..8b6548c8ab00fadc6dc5ebce7a5911ba5ff4ad24 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 
-$c = $this->layout()->content;
+$content = $this->htmlElement($this->layout()->content, 'div', array('class' => 'content content-wrapper'));
 
 //$admin = $this->admin ? ' admin' : '';
 
 echo '<div id="top"></div>';
 echo $this->render('common/header.phtml');
-echo $this->htmlElement($c, 'main', array('class' => ''));
+echo $this->htmlElement($content, 'main', array('class' => ''));
 echo $this->render('common/footer.phtml');
\ No newline at end of file
index 2ffdc7a5ecff3f1a18fb00a147bac3e1bca3328d..cc06d6baaa0dfecdeb52b8749445ed58469960f2 100644 (file)
@@ -1,9 +1,5 @@
 <footer class="group">
        <div class="content">
-               <?php
-               echo $this->localeNavigation(true, CubeIT_View_Helper_LocaleNavigation::BIGRAMME);
-               ?>
-
                <?php echo $this->markupDotclear($this->option('footer')); ?>
        </div>
 </footer>
\ No newline at end of file
index 089767779a14fcfae31a6c421cc15455573d3914..facb0944a748c00e828f2cf444566258dd9eaf53 100644 (file)
@@ -3,7 +3,7 @@
 $this->headScript()->addScriptAndStyle('navigation');
 
 // Major nav sections
-$sections = array('simeox', 'clinic', 'about', 'contact');
+$sections = array('simeox', 'clinic', 'about', 'news', 'contact');
 
 $data = CubeIT_Util_Cms::getCMSDatasOfPage('home');
 
@@ -20,10 +20,22 @@ $data = CubeIT_Util_Cms::getCMSDatasOfPage('home');
                        <ul>
                                <?php
                                foreach ($sections as $i => $s) {
-                                       echo '<li data-i="' . $i . '"><a href="/#' . $s . '">' . $data[$s]['menu_title'] . '</a></li>';
+
+                                       if ($s == 'news') {
+                                               $title = __('Actualités');
+                                               $URL = CubeIT_View_Helper_Link::internal('news');
+                                       } else {
+                                               $title = $data[$s]['menu_title'];
+                                               $URL = "/#$s";
+                                       }
+
+                                       echo '<li data-i="'. $i .'"><a href="'. $URL .'">'. $title .'</a></li>';
                                }
                                ?>
                        </ul>
                </nav>
+
+               <?php echo $this->localeNavigation(true, CubeIT_View_Helper_LocaleNavigation::BIGRAMME); ?>
+               
        </div>
 </header>
\ No newline at end of file
index 00d88bd09cd1dfe1ddf68b63e2a8d3316dd605b1..92af6b6a9e817a164c8929eab013f265bbde868f 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+$this->headScript()->addScriptAndStyle('home');
+
 echo $this->render('home/hero.phtml');
 echo $this->render('home/simeox.phtml');
 echo $this->render('home/rdclinic.phtml');
diff --git a/framework/application/views/scripts/templates/news.phtml b/framework/application/views/scripts/templates/news.phtml
new file mode 100644 (file)
index 0000000..0f24290
--- /dev/null
@@ -0,0 +1,16 @@
+<?php\r
+\r
+$this->headScript()->addScriptAndStyle('news');\r
+\r
+?>\r
+\r
+<h1 class="page-heading"><?php echo $this->title ?></h1>\r
+\r
+<div id="newsFeed"\r
+     data-read-more-closed="<?php echo __('Lire la suite') ?>"\r
+     data-read-more-open="<?php echo __('Réduire') ?>">\r
+</div>\r
+\r
+<div class="loader-container">\r
+    <div class="loader">Loading...</div>\r
+</div>
\ No newline at end of file
index e48956c17fa6b54062c3ef7dd83af54b9690c06e..c61f059bef99e62e2b942d91c0ba0919b3f53f16 100644 (file)
@@ -1,5 +1,3 @@
 <?php\r
 $this->headScript()->addScriptAndStyle('text');\r
-echo '<div class="content">';\r
 echo $this->markupDotclear($this->text);\r
-echo '</div>';\r
diff --git a/js/news.js b/js/news.js
new file mode 100644 (file)
index 0000000..fb19d31
--- /dev/null
@@ -0,0 +1,122 @@
+registerLoader(load_newsfeed);
+
+var currentPage = 1,
+    scrollBufferTrigger = $(window).height() / 5, // How many pixels from bottom before next AJAX event is fired
+    isLoading = false,
+    allDataLoaded = false;
+
+//--- INIT ---//
+function load_newsfeed() {
+
+    $('.loader').hide();
+
+    // Initial load of data via AJAX
+    loadMoreContent(fillPage);
+
+
+    //-- Infinite Scroll: track scroll position and load more data when needed --//
+    $(window).scroll(function () {
+
+        var dh = $(document).height(),
+            wh = $(window).height(),
+            top = $(window).scrollTop();
+
+        // Trigger will be true {scrollBufferTrigger}px above bottom of page
+        var triggerPoint = (dh < wh) || (top >= dh - wh - scrollBufferTrigger);
+
+        if (!allDataLoaded && !isLoading && triggerPoint) {
+            loadMoreContent();
+        }
+    });
+
+
+    //-- Handle show/hide link clicks
+    $(document).on('click', 'a.read-more', function() {
+
+        var content = $(this).siblings('.news-content');
+
+        if (content.hasClass('open')) {
+            content.removeClass('open');
+            $(this).text($(this).data('closed'));
+        } else {
+            content.addClass('open');
+            $(this).text($(this).data('open'));
+        }
+
+        return false;
+    });
+}
+
+// Ensure we have loaded enough to be able to scroll
+function fillPage() {
+    // If we don't have a full window of content, the scroll
+    // trigger won't fire, so load more content until it can
+    if ($(document).height() <= $(window).height()) {
+        console.info('fillpage ' + currentPage);
+        loadMoreContent(fillPage);
+    }
+}
+
+//-----------------------//
+
+function loadMoreContent(callback) {
+
+    var $container = $('#newsFeed'),
+        readMoreClosed = $container.data('read-more-closed'),
+        readMoreOpen = $container.data('read-more-open');
+    
+    var dataURL = '/ajax/news/' + currentPage;
+
+    isLoading = true;
+    $('.loader').show();
+
+    $.getJSON(dataURL, function (result) {
+
+        if (result.vars.data.length == 0) { // No more data
+            fb('End of data.');
+            allDataLoaded = true;
+
+        } else {
+
+            var elems = [];
+
+            $.each(result.vars.data, function (key, data) {
+
+                fb('loaded page #' + currentPage);
+
+                var res, image;
+
+                res  = '<div class="news-image">' + data.image + '</div>';
+                res += '<div class="news-body">';
+                res += '<time class="news-date">' + data.date + '</time>';
+                res += '<h3 class="news-headline">' + data.headline + '</h3>';
+                res += data.content; // MarkupDotClear view helper already wraps content in a div
+
+                // Add the open/close link
+                res += '<a href="#" class="read-more" data-closed="'+ readMoreClosed +'" data-open="'+ readMoreOpen +'">'+ readMoreClosed +'</a>';
+
+                res += '</div>'; // .news-body
+
+                // Add items
+                var elem = document.createElement('article');
+                elem.innerHTML = res;
+                elem.className = 'news-item';
+                elems.push(elem);
+            });
+
+            // Add new items to container and update Masonry
+            $container.append(elems);
+
+            currentPage++;
+
+            if (typeof callback === "function") {
+                callback();
+            }
+        }
+
+        //fb('finished loading');
+        isLoading = false;
+        $('.loader').hide();
+
+    });
+}
\ No newline at end of file
index cf03d8b1e5d0de78781191c070788c53728b304c..4ee1b319206a7a7984f78f0e8a803d43a5a3e9ce 100644 (file)
@@ -50,6 +50,10 @@ p {
        line-height: 1.5;
 }
 
+.content-wrapper {
+       padding-bottom: 20px;
+}
+
 .content {
        width: 960px;
        margin: 0 auto;
diff --git a/less/home.less b/less/home.less
new file mode 100644 (file)
index 0000000..297aa09
--- /dev/null
@@ -0,0 +1,9 @@
+body.home {
+
+  .content-wrapper {
+    width: 100%;
+    margin: 0;
+    padding: 0;
+  }
+
+}
\ No newline at end of file
index d72877eb3ad8149dacc9ca291fe5ccb3a328aedb..4cd7aef038d0285559230f5e2268483533ec1be7 100644 (file)
@@ -26,8 +26,8 @@ nav.primary {
        }
 
        li {
-               margin-left: 68px;
-               &[data-i='0'] {
+               margin-left: 30px;
+               &:first-of-type {
                        margin-left: 0;
                }
        }
@@ -36,18 +36,29 @@ nav.primary {
 nav.locale {
        font-size: 11px;
        font-weight: 300;
-       float: right;
+       position: absolute;
+       right: 0;
+       top: 15px;
+       opacity: 1;
+       transition: opacity 0.1s ease-in;
+       backface-visibility: hidden;
+
+       .small & {
+               //display: none;
+               opacity: 0;
+               top: -100%;
+       }
 
        a {
                display: inline-block;
-               margin: 8px 0 0 5px;
+               margin-left: 5px;
                width: 28px;
                height: 28px;
                line-height: 28px;
                text-align: center;
                border-radius: 50%;
-               background-color: #444;
-               color: #999;
+               background-color: #ececec;
+               color: #818181;
                text-transform: uppercase;
 
                &:hover, &.active {
diff --git a/less/news.less b/less/news.less
new file mode 100644 (file)
index 0000000..bc4e5e6
--- /dev/null
@@ -0,0 +1,122 @@
+.page-heading {
+  margin-bottom: 110px;
+}
+
+.news-item {
+  overflow: hidden;
+  padding-bottom: 55px;
+  border-bottom: 1px solid #dadada;
+  margin-bottom: 55px;
+}
+
+.news-image {
+  float: left;
+  margin-right: 45px;
+  img {
+    border-radius: 100%;
+  }
+}
+
+.news-body {
+  overflow: hidden;
+}
+
+.news-date {
+  font-size: 12px;
+  font-weight: 300;
+}
+
+.news-headline {
+  font-size: 32px;
+  font-weight: 300;
+  margin: 15px 0 25px;
+}
+
+.news-content {
+  overflow: hidden;
+  max-height: 3em; // Line height is 1.5 so 3em = 2 lines visible
+
+  &.open {
+    max-height: none;
+  }
+
+  p {
+    &:first-of-type {
+      padding-top: 0;
+    }
+  }
+}
+
+.read-more {
+  font-size: 16px;
+  font-weight: 600;
+  color: #000;
+  display: block;
+  margin-top: 1em;
+}
+
+
+//--------- Loading Animation ---------//
+// Credit: http://projects.lukehaas.me/css-loaders/
+
+.loader-container {
+  opacity: 0.2;
+  overflow: hidden;
+}
+
+.loader:before,
+.loader:after,
+.loader {
+  border-radius: 50%;
+  width: 2.5em;
+  height: 2.5em;
+  -webkit-animation-fill-mode: both;
+  animation-fill-mode: both;
+  -webkit-animation: load7 1.8s infinite ease-in-out;
+  animation: load7 1.8s infinite ease-in-out;
+}
+.loader {
+  margin: 1em auto 6em auto;
+  font-size: 10px;
+  position: relative;
+  text-indent: -9999em;
+  -webkit-transform: translateZ(0);
+  -ms-transform: translateZ(0);
+  transform: translateZ(0);
+  -webkit-animation-delay: -0.16s;
+  animation-delay: -0.16s;
+}
+.loader:before {
+  left: -3.5em;
+  -webkit-animation-delay: -0.32s;
+  animation-delay: -0.32s;
+}
+.loader:after {
+  left: 3.5em;
+}
+.loader:before,
+.loader:after {
+  content: '';
+  position: absolute;
+  top: 0;
+}
+@-webkit-keyframes load7 {
+  0%,
+  80%,
+  100% {
+    box-shadow: 0 2.5em 0 -1.3em #000;
+  }
+  40% {
+    box-shadow: 0 2.5em 0 0 #000;
+  }
+}
+@keyframes load7 {
+  0%,
+  80%,
+  100% {
+    box-shadow: 0 2.5em 0 -1.3em #000;
+  }
+  40% {
+    box-shadow: 0 2.5em 0 0 #000;
+  }
+}
\ No newline at end of file