From 28b75b028dcb1633a9407a5a5c79e5d2423e18a5 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 6 Sep 2014 00:37:15 -0700 Subject: ajax work --- include/text.php | 14 ++++++++++ mod/directory.php | 2 +- mod/photos.php | 65 ++++++++++++++++++++++++++++++++++++---------- version.inc | 2 +- view/js/main.js | 2 +- view/js/mod_events.js | 37 ++++++++++++++++++++++++++ view/tpl/photos_recent.tpl | 3 +++ view/tpl/photosajax.tpl | 4 +++ 8 files changed, 113 insertions(+), 16 deletions(-) create mode 100644 view/js/mod_events.js create mode 100755 view/tpl/photosajax.tpl diff --git a/include/text.php b/include/text.php index 50c68b6b2..4fe9f9cde 100644 --- a/include/text.php +++ b/include/text.php @@ -2033,4 +2033,18 @@ function normalise_openid($s) { return trim(str_replace(array('http://','https://'),array('',''),$s),'/'); } +// used in ajax endless scroll request to find out all the args that the master page was viewing + +function extra_query_args() { + $s = ''; + if(count($_REQUEST)) { + foreach($_REQUEST as $k => $v) { + // these are request vars we don't want to duplicate + if(! in_array($k, array('q','f','zid','page','PHPSESSID'))) { + $s .= '&' . $k . '=' . $v; + } + } + } + return $s; +} \ No newline at end of file diff --git a/mod/directory.php b/mod/directory.php index 39eeb36ce..2c11e3247 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -216,7 +216,7 @@ function directory_content(&$a) { } else { - $o .= ""; + $o .= ""; $o .= replace_macros($tpl, array( '$search' => $search, '$desc' => t('Find'), diff --git a/mod/photos.php b/mod/photos.php index 428aff2a0..3bc105ba1 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -697,8 +697,10 @@ function photos_content(&$a) { $o .= ''; } + $ajaxout = ''; + $tpl = get_markup_template('photo_album.tpl'); - if(count($r)) + if(count($r)) { $twist = 'rotright'; foreach($r as $rr) { @@ -728,7 +730,9 @@ function photos_content(&$a) { $rel=("photo"); // } - $o .= replace_macros($tpl,array( + $o .= ""; + + $tmp = replace_macros($tpl,array( '$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2,4), '$photolink' => $imagelink, @@ -740,10 +744,24 @@ function photos_content(&$a) { '$ext' => $ext, '$hash'=> $rr['resource_id'], )); - + if($_REQUEST['aj']) + $ajaxout .= $tmp; + else + $o .= $tmp; + } + } + if($_REQUEST['aj']) { + if(! $r) + $ajaxout .= '
'; + echo $ajaxout; + killme(); } + + $o .= '
'; $o .= '
'; - $o .= paginate($a); + $o .= ''; + $o .= '
'; +// $o .= paginate($a); return $o; @@ -1192,16 +1210,37 @@ function photos_content(&$a) { } } - $tpl = get_markup_template('photos_recent.tpl'); - $o .= replace_macros($tpl, array( - '$title' => t('Recent Photos'), - '$can_post' => $can_post, - '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['channel']['channel_address'].'/upload'), - '$photos' => $photos, - )); + if($_REQUEST['aj']) { + if($photos) { + $o = replace_macros(get_markup_template('photosajax.tpl'),array( + '$photos' => $photos + )); + } + else { + $o = '
'; + } + echo $o; + killme(); + } + else { + $o .= ""; + $tpl = get_markup_template('photos_recent.tpl'); + $o .= replace_macros($tpl, array( + '$title' => t('Recent Photos'), + '$can_post' => $can_post, + '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['channel']['channel_address'].'/upload'), + '$photos' => $photos, + )); - - $o .= paginate($a); + } + + if((! $photos) && ($_REQUEST['aj'])) { + $o .= '
'; + echo $o; + killme(); + } + +// $o .= paginate($a); return $o; } diff --git a/version.inc b/version.inc index 047aea03d..edded63aa 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-09-05.789 +2014-09-06.790 diff --git a/view/js/main.js b/view/js/main.js index b5b77d473..c31e6231a 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -689,7 +689,7 @@ function updateConvItems(mode,data) { bParam_page = 1; } - update_url = baseurl + '/directory/?f=&aj=1&page=' + bParam_page; + update_url = baseurl + '/' + page_query + '/?f=&aj=1&page=' + bParam_page + extra_args ; $("#page-spinner").spin('small'); update_mode = 'append'; diff --git a/view/js/mod_events.js b/view/js/mod_events.js new file mode 100644 index 000000000..0ce128fcc --- /dev/null +++ b/view/js/mod_events.js @@ -0,0 +1,37 @@ + +$(document).ready( function() { showHideFinishDate(); }); + +function showHideFinishDate() { + if( $('#event-nofinish-checkbox').is(':checked')) + $('#event-finish-wrapper').hide(); + else + $('#event-finish-wrapper').show(); +} + + + + function eventGetStart() { + //reply = prompt("{{$expirewhen}}", $('#jot-expire').val()); + $('#startModal').modal(); + $('#start-modal-OKButton').on('click', function() { + reply=$('#start-date').val(); + if(reply && reply.length) { + $('#start-text').val(reply); + $('#startModal').modal('hide'); + } + }) + + + } + function eventGetFinish() { + //reply = prompt("{{$expirewhen}}", $('#jot-expire').val()); + $('#finishModal').modal(); + $('#finish-modal-OKButton').on('click', function() { + reply=$('#finish-date').val(); + if(reply && reply.length) { + $('#finish-text').val(reply); + $('#finishModal').modal('hide'); + } + }) + + } diff --git a/view/tpl/photos_recent.tpl b/view/tpl/photos_recent.tpl index 43a22a017..9be1b12a7 100755 --- a/view/tpl/photos_recent.tpl +++ b/view/tpl/photos_recent.tpl @@ -7,5 +7,8 @@ {{foreach $photos as $photo}} {{include file="photo_top.tpl"}} {{/foreach}} +
+ +
diff --git a/view/tpl/photosajax.tpl b/view/tpl/photosajax.tpl new file mode 100755 index 000000000..a88682e8b --- /dev/null +++ b/view/tpl/photosajax.tpl @@ -0,0 +1,4 @@ + +{{foreach $photos as $photo}} + {{include file="photo_top.tpl"}} +{{/foreach}} -- cgit v1.2.3