function get_block_js() { //get the js for this block - do not load it in inline mode in visual composer if (td_util::vc_is_inline()) { return ''; } extract(shortcode_atts(array('limit' => 5, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'show_child_cat' => '', 'sub_cat_ajax' => '', 'ajax_pagination' => '', 'header_color' => '', 'ajax_pagination_infinite_stop' => ''), $this->atts)); if (!empty($this->atts['custom_title'])) { $this->atts['custom_title'] = htmlspecialchars($this->atts['custom_title'], ENT_QUOTES); } if (!empty($this->atts['custom_url'])) { $this->atts['custom_url'] = htmlspecialchars($this->atts['custom_url'], ENT_QUOTES); } $td_column_number = td_util::vc_get_column_number(); // get the column width of the block so we can sent it to the server $block_item = 'block_' . $this->block_uid; $buffy = ''; $buffy .= '<script>'; $buffy .= 'var ' . $block_item . ' = new td_block();' . "\n"; $buffy .= $block_item . '.id = "' . $this->block_uid . '";' . "\n"; $buffy .= $block_item . ".atts = '" . json_encode($this->atts) . "';" . "\n"; $buffy .= $block_item . '.td_column_number = "' . $td_column_number . '";' . "\n"; $buffy .= $block_item . '.block_type = "' . $this->block_id . '";' . "\n"; //wordpress wp query parms $buffy .= $block_item . '.post_count = "' . $this->td_query->post_count . '";' . "\n"; $buffy .= $block_item . '.found_posts = "' . $this->td_query->found_posts . '";' . "\n"; $buffy .= $block_item . '.max_num_pages = "' . $this->td_query->max_num_pages . '";' . "\n"; $buffy .= $block_item . '.header_color = "' . $header_color . '";' . "\n"; $buffy .= $block_item . '.ajax_pagination_infinite_stop = "' . $ajax_pagination_infinite_stop . '";' . "\n"; $buffy .= 'td_blocks.push(' . $block_item . ');' . "\n"; $buffy .= '</script>'; return $buffy; }
function get_block_js() { //get the js for this block - do not load it in inline mode in visual composer if (td_util::vc_is_inline()) { return ''; } extract(shortcode_atts(array('limit' => 5, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'show_child_cat' => '', 'sub_cat_ajax' => '', 'ajax_pagination' => '', 'header_color' => '', 'ajax_pagination_infinite_stop' => '', 'td_column_number' => ''), $this->atts)); if (!empty($this->atts['custom_title'])) { $this->atts['custom_title'] = htmlspecialchars($this->atts['custom_title'], ENT_QUOTES); } if (!empty($this->atts['custom_url'])) { $this->atts['custom_url'] = htmlspecialchars($this->atts['custom_url'], ENT_QUOTES); } if (empty($td_column_number)) { $td_column_number = td_util::vc_get_column_number(); // get the column width of the block so we can sent it to the server. If the shortcode already has a user defined column number, we use that } $block_item = 'block_' . $this->block_uid; $buffy = ''; $buffy .= '<script>'; $buffy .= 'var ' . $block_item . ' = new tdBlock();' . "\n"; $buffy .= $block_item . '.id = "' . $this->block_uid . '";' . "\n"; $buffy .= $block_item . ".atts = '" . json_encode($this->atts) . "';" . "\n"; $buffy .= $block_item . '.td_column_number = "' . $td_column_number . '";' . "\n"; $buffy .= $block_item . '.block_type = "' . $this->block_id . '";' . "\n"; //wordpress wp query parms $buffy .= $block_item . '.post_count = "' . $this->td_query->post_count . '";' . "\n"; $buffy .= $block_item . '.found_posts = "' . $this->td_query->found_posts . '";' . "\n"; $buffy .= $block_item . '.header_color = "' . $header_color . '";' . "\n"; $buffy .= $block_item . '.ajax_pagination_infinite_stop = "' . $ajax_pagination_infinite_stop . '";' . "\n"; // The max_num_pages is computed so it considers the offset and the limit atts settings // There were necessary these changes because on the user interface there are js scripts that use the max_num_pages js variable to show/hide some ui components if (!empty($this->atts['offset'])) { if ($this->atts['limit'] != 0) { $buffy .= $block_item . '.max_num_pages = "' . ceil(($this->td_query->found_posts - $this->atts['offset']) / $this->atts['limit']) . '";' . "\n"; } else { if (get_option('posts_per_page') != 0) { $buffy .= $block_item . '.max_num_pages = "' . ceil(($this->td_query->found_posts - $this->atts['offset']) / get_option('posts_per_page')) . '";' . "\n"; } } } else { $buffy .= $block_item . '.max_num_pages = "' . $this->td_query->max_num_pages . '";' . "\n"; } $buffy .= 'tdBlocksArray.push(' . $block_item . ');' . "\n"; $buffy .= '</script>'; //print_r($this->td_block_template_data); // ajax subcategories preloader // @todo preloading "all" filter content should happen regardless of the setting if (!empty($this->td_block_template_data['td_pull_down_items']) and !empty($this->atts['td_ajax_preloading'])) { /* ------------------------------------------------------------------------------------- add 'ALL' item to the cache */ // pagination - we need to compute the pagination for each cache entry $td_hide_next = false; if (!empty($this->atts['offset']) && !empty($this->atts['limit']) && $this->atts['limit'] != 0) { if (1 >= ceil(($this->td_query->found_posts - $this->atts['offset']) / $this->atts['limit'])) { $td_hide_next = true; //hide link on last page } } else { if (1 >= $this->td_query->max_num_pages) { $td_hide_next = true; //hide link on last page } } // this will be send to JS bellow $buffyArray = array('td_data' => $this->inner($this->td_query->posts, $td_column_number), 'td_block_id' => $this->block_uid, 'td_hide_prev' => true, 'td_hide_next' => $td_hide_next); /* ------------------------------------------------------------------------------------- add the rest of the items to the local cache */ ob_start(); // we need to clone the object to set is_ajax_running to true // first we set an object for the all filter ?> <script> var tmpObj = JSON.parse(JSON.stringify(<?php echo $block_item; ?> )); tmpObj.is_ajax_running = true; var currentBlockObjSignature = JSON.stringify(tmpObj); tdLocalCache.set(currentBlockObjSignature, JSON.stringify(<?php echo json_encode($buffyArray); ?> )); <?php foreach ($this->td_block_template_data['td_pull_down_items'] as $count => $item) { if (empty($item['id'])) { continue; } // preload only 6 or 20 items depending on the setting if ($this->atts['td_ajax_preloading'] == 'preload_all' and $count > 20) { break; } else { if ($this->atts['td_ajax_preloading'] == 'preload' and $count > 6) { break; } } $ajax_parameters = array('td_atts' => $this->atts, 'td_column_number' => $td_column_number, 'td_current_page' => 1, 'td_block_id' => $this->block_uid, 'block_type' => get_class($this), 'td_filter_value' => $item['id']); ?> tmpObj = JSON.parse(JSON.stringify(<?php echo $block_item; ?> )); tmpObj.is_ajax_running = true; tmpObj.td_current_page = 1; tmpObj.td_filter_value = <?php echo $item['id']; ?> ; var currentBlockObjSignature = JSON.stringify(tmpObj); tdLocalCache.set(currentBlockObjSignature, JSON.stringify(<?php echo td_ajax_block($ajax_parameters); ?> )); <?php } ?> </script> <?php //ob_clean(); $buffy .= ob_get_clean(); } // end preloader if return $buffy; }
function get_block_js() { //get the js for this block - do not load it in inline mode in visual composer if (td_util::vc_is_inline()) { return ''; } extract(shortcode_atts(array('limit' => 5, 'sort' => '', 'category_id' => '', 'category_ids' => '', 'custom_title' => '', 'custom_url' => '', 'show_child_cat' => '', 'sub_cat_ajax' => '', 'ajax_pagination' => '', 'header_color' => '', 'ajax_pagination_infinite_stop' => '', 'td_column_number' => ''), $this->atts)); if (!empty($this->atts['custom_title'])) { $this->atts['custom_title'] = htmlspecialchars($this->atts['custom_title'], ENT_QUOTES); } if (!empty($this->atts['custom_url'])) { $this->atts['custom_url'] = htmlspecialchars($this->atts['custom_url'], ENT_QUOTES); } if (empty($td_column_number)) { $td_column_number = td_util::vc_get_column_number(); // get the column width of the block so we can sent it to the server. If the shortcode already has a user defined column number, we use that } $block_item = 'block_' . $this->block_uid; $buffy = ''; $buffy .= '<script>'; $buffy .= 'var ' . $block_item . ' = new td_block();' . "\n"; $buffy .= $block_item . '.id = "' . $this->block_uid . '";' . "\n"; $buffy .= $block_item . ".atts = '" . json_encode($this->atts) . "';" . "\n"; $buffy .= $block_item . '.td_column_number = "' . $td_column_number . '";' . "\n"; $buffy .= $block_item . '.block_type = "' . $this->block_id . '";' . "\n"; //wordpress wp query parms $buffy .= $block_item . '.post_count = "' . $this->td_query->post_count . '";' . "\n"; $buffy .= $block_item . '.found_posts = "' . $this->td_query->found_posts . '";' . "\n"; $buffy .= $block_item . '.header_color = "' . $header_color . '";' . "\n"; $buffy .= $block_item . '.ajax_pagination_infinite_stop = "' . $ajax_pagination_infinite_stop . '";' . "\n"; // The max_num_pages is computed so it considers the offset and the limit atts settings // There were necessary these changes because on the user interface there are js scripts that use the max_num_pages js variable to show/hide some ui components if (!empty($this->atts['offset'])) { if ($this->atts['limit'] != 0) { $buffy .= $block_item . '.max_num_pages = "' . ceil(($this->td_query->found_posts - $this->atts['offset']) / $this->atts['limit']) . '";' . "\n"; } else { if (get_option('posts_per_page') != 0) { $buffy .= $block_item . '.max_num_pages = "' . ceil(($this->td_query->found_posts - $this->atts['offset']) / get_option('posts_per_page')) . '";' . "\n"; } } } else { $buffy .= $block_item . '.max_num_pages = "' . $this->td_query->max_num_pages . '";' . "\n"; } $buffy .= 'td_blocks.push(' . $block_item . ');' . "\n"; $buffy .= '</script>'; return $buffy; }