Browse Source

- Start implementing the Lazy lib for lazy page loading

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
cbf2f499f3
  1. 25
      app/assets/js/movim_lazy.js
  2. 26
      app/widgets/Avatar/avatar.js
  3. 4
      app/widgets/System/System.php
  4. 1
      app/widgets/System/system.tpl
  5. 3
      bootstrap.php
  6. 22
      lib/Lazy.php
  7. 3
      system/RPC.php
  8. 4
      system/Route.php
  9. 8
      system/Utils.php
  10. 1
      system/controllers/BaseController.php

25
app/assets/js/movim_lazy.js

@ -0,0 +1,25 @@
/*
* Movim Lazy
* Implement simple tools to do a lazy page loading by updating only parts of it
*/
function MovimLazy()
{
this.init = function()
{
var links = document.querySelectorAll('a:not([href^=http])');
for(var i = 0; i < links.length; i++) {
if(links[i].getAttribute('href') != null) {
var next = links[i].getAttribute('href').split('&')[0].substring(3);
var current =
links[i].onclick = function(event) {
event.preventDefault();
movim_ajaxSend('lazy', 'get', [CURRENT_PAGE, next]);
};
}
}
};
}
var lazy = new MovimLazy();
movim_add_onload(function() { lazy.init() });

26
app/widgets/Avatar/avatar.js

@ -74,20 +74,20 @@ function errorCallback(error){
function snapshot() {
if (localMediaStream) {
canvas = document.querySelector("canvas");
if (localMediaStream) {
canvas = document.querySelector("canvas");
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
ctx = canvas.getContext('2d');
video = document.getElementById("runningcam");
ctx.drawImage(video,0,0, canvas.width, canvas.height);
// "image/webp" works in Chrome 18. In other browsers, this will fall back to image/png.
var img = new Image();
img.src = canvas.toDataURL('image/png');
ctx = canvas.getContext('2d');
video = document.getElementById("runningcam");
img.onload = function() {
vCardImageResize(this);
}
}
ctx.drawImage(video,0,0, canvas.width, canvas.height);
// "image/webp" works in Chrome 18. In other browsers, this will fall back to image/png.
var img = new Image();
img.src = canvas.toDataURL('image/png');
img.onload = function() {
vCardImageResize(this);
}
}
}

4
app/widgets/System/System.php

@ -16,6 +16,10 @@ class System extends WidgetBase {
{
$this->view->assign('base_uri', BASE_URI);
$this->view->assign('error_uri', substr_replace(Route::urlize('disconnect', 'err'), '', -3));
$r = new Route;
$this->view->assign('current_page', $r->find());
if(!isset($_SERVER['HTTP_MOD_REWRITE']) || !$_SERVER['HTTP_MOD_REWRITE'])
$this->view->assign('page_key_uri', '?q=');
else

1
app/widgets/System/system.tpl

@ -3,5 +3,6 @@
var ERROR_URI = '{$error_uri}';
var PAGE_KEY_URI = '{$page_key_uri}';
var FAIL_SAFE = '{$fail_safe}';
var CURRENT_PAGE = '{$current_page}';
var SERVER_CONF = {$server_conf};
</script>

3
bootstrap.php

@ -171,6 +171,9 @@ class Bootstrap {
// SDPtoJingle and JingletoSDP lib :)
require_once(LIB_PATH . "SDPtoJingle.php");
require_once(LIB_PATH . "JingletoSDP.php");
// The Lazy page loader
require_once(LIB_PATH . "Lazy.php");
}
private function loadHelpers() {

22
lib/Lazy.php

@ -0,0 +1,22 @@
<?php
/**
* @file Lazy.php
* This file is part of Movim.
*
* @brief Refresh only parts of the new page
*
* @author Timothée jaussoin
*/
class Lazy {
private $_current;
private $_next;
public function __construct($current, $next) {
$this->_current = $current;
$this->_next = $next;
}
}

3
system/RPC.php

@ -95,9 +95,10 @@ class RPC
$json = file_get_contents('php://input');
$request = json_decode($json);
// We force the rid and id session number from the browser
if(isset($_GET['do']) && $_GET['do'] == 'poll') {
\Moxl\API::ping();
} elseif((string)$request->widget == 'lazy') {
$l = new Lazy($request->params[0], $request->params[1]);
} else {
// Loading the widget.
$widget_name = (string)$request->widget;

4
system/Route.php

@ -73,7 +73,7 @@ class Route extends \BaseController {
$tab = '#'.$tab;
//We construct a classic URL if the rewriting is disabled
if(!isset($_SERVER['HTTP_MOD_REWRITE']) || !$_SERVER['HTTP_MOD_REWRITE']) {
$uri = BASE_URI.'?q='.$page;
$uri = '?q='.$page;
if($params != false && is_array($params)) {
$i = 0;
@ -87,7 +87,7 @@ class Route extends \BaseController {
}
// Here we got a beautiful rewriten URL !
else {
$uri = BASE_URI.$page;
$uri = $page;
if($params != false && is_array($params))
foreach($params as $value)
$uri .= '/'.$value;

8
system/Utils.php

@ -25,10 +25,10 @@ use Monolog\Handler\StreamHandler;
*/
function getGender() {
return array('N' => t('None'),
'M' => t('Male'),
'F' => t('Female'),
'O' => t('Other')
);
'M' => t('Male'),
'F' => t('Female'),
'O' => t('Other')
);
}
/**

1
system/controllers/BaseController.php

@ -14,6 +14,7 @@ class BaseController {
$this->page->addScript('movim_base.js');
$this->page->addScript('movim_tpl.js');
$this->page->addScript('movim_rpc.js');
$this->page->addScript('movim_lazy.js');
}

Loading…
Cancel
Save