PageRenderTime 99ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/shortcodes.php

https://github.com/UCF/TechTransfer-Theme
PHP | 641 lines | 537 code | 54 blank | 50 comment | 77 complexity | 8a86112c5a73219819d9e8b27d2a8724 MD5 | raw file
  1. <?php
  2. /**
  3. * Create a javascript slideshow of each top level element in the
  4. * shortcode. All attributes are optional, but may default to less than ideal
  5. * values. Available attributes:
  6. *
  7. * height => css height of the outputted slideshow, ex. height="100px"
  8. * width => css width of the outputted slideshow, ex. width="100%"
  9. * transition => length of transition in milliseconds, ex. transition="1000"
  10. * cycle => length of each cycle in milliseconds, ex cycle="5000"
  11. * animation => The animation type, one of: 'slide' or 'fade'
  12. *
  13. * Example:
  14. * [slideshow height="500px" transition="500" cycle="2000"]
  15. * <img src="http://some.image.com" .../>
  16. * <div class="robots">Robots are coming!</div>
  17. * <p>I'm a slide!</p>
  18. * [/slideshow]
  19. **/
  20. function sc_slideshow($attr, $content=null){
  21. $content = cleanup(str_replace('<br />', '', $content));
  22. $content = DOMDocument::loadHTML($content);
  23. $html = $content->childNodes->item(1);
  24. $body = $html->childNodes->item(0);
  25. $content = $body->childNodes;
  26. # Find top level elements and add appropriate class
  27. $items = array();
  28. foreach($content as $item){
  29. if ($item->nodeName != '#text'){
  30. $classes = explode(' ', $item->getAttribute('class'));
  31. $classes[] = 'slide';
  32. $item->setAttribute('class', implode(' ', $classes));
  33. $items[] = $item->ownerDocument->saveXML($item);
  34. }
  35. }
  36. $animation = ($attr['animation']) ? $attr['animation'] : 'slide';
  37. $height = ($attr['height']) ? $attr['height'] : '100px';
  38. $width = ($attr['width']) ? $attr['width'] : '100%';
  39. $tran_len = ($attr['transition']) ? $attr['transition'] : 1000;
  40. $cycle_len = ($attr['cycle']) ? $attr['cycle'] : 5000;
  41. ob_start();
  42. ?>
  43. <div
  44. class="slideshow <?=$animation?>"
  45. data-tranlen="<?=$tran_len?>"
  46. data-cyclelen="<?=$cycle_len?>"
  47. style="height: <?=$height?>; width: <?=$width?>;"
  48. >
  49. <?php foreach($items as $item):?>
  50. <?=$item?>
  51. <?php endforeach;?>
  52. </div>
  53. <?php
  54. $html = ob_get_clean();
  55. return $html;
  56. }
  57. add_shortcode('slideshow', 'sc_slideshow');
  58. function sc_search_form() {
  59. ob_start();
  60. ?>
  61. <div class="search">
  62. <?get_search_form()?>
  63. </div>
  64. <?
  65. return ob_get_clean();
  66. }
  67. add_shortcode('search_form', 'sc_search_form');
  68. /**
  69. * Include the defined publication, referenced by pub title:
  70. *
  71. * [publication name="Where are the robots Magazine"]
  72. **/
  73. function sc_publication($attr, $content=null){
  74. $pub = @$attr['pub'];
  75. $pub_name = @$attr['name'];
  76. $pub_id = @$attr['id'];
  77. if (!$pub and is_numeric($pub_id)){
  78. $pub = get_post($pub);
  79. }
  80. if (!$pub and $pub_name){
  81. $pub = get_page_by_title($pub_name, OBJECT, 'publication');
  82. }
  83. $pub->url = get_post_meta($pub->ID, "publication_url", True);
  84. $pub->thumb = get_the_post_thumbnail($pub->ID, 'publication-thumb');
  85. ob_start(); ?>
  86. <div class="pub">
  87. <a class="track pub-track" title="<?=$pub->post_title?>" data-toggle="modal" href="#pub-modal-<?=$pub->ID?>">
  88. <?=$pub->thumb?>
  89. <span><?=$pub->post_title?></span>
  90. </a>
  91. <p class="pub-desc"><?=$pub->post_content?></p>
  92. <div class="modal hide fade" id="pub-modal-<?=$pub->ID?>" role="dialog" aria-labelledby="<?=$pub->post_title?>" aria-hidden="true">
  93. <iframe src="<?=$pub->url?>" width="100%" height="100%" scrolling="no"></iframe>
  94. <a href="#" class="btn" data-dismiss="modal">Close</a>
  95. </div>
  96. </div>
  97. <?php
  98. return ob_get_clean();
  99. }
  100. add_shortcode('publication', 'sc_publication');
  101. function sc_person_picture_list($atts) {
  102. $atts['type'] = ($atts['type']) ? $atts['type'] : null;
  103. $row_size = ($atts['row_size']) ? (intval($atts['row_size'])) : 5;
  104. $categories = ($atts['categories']) ? $atts['categories'] : null;
  105. $org_groups = ($atts['org_groups']) ? $atts['org_groups'] : null;
  106. $limit = ($atts['limit']) ? (intval($atts['limit'])) : -1;
  107. $join = ($atts['join']) ? $atts['join'] : 'or';
  108. $people = sc_object_list(
  109. array(
  110. 'type' => 'person',
  111. 'limit' => $limit,
  112. 'join' => $join,
  113. 'categories' => $categories,
  114. 'org_groups' => $org_groups
  115. ),
  116. array(
  117. 'objects_only' => True,
  118. ));
  119. ob_start();
  120. ?><div class="person-picture-list"><?
  121. $count = 0;
  122. foreach($people as $person) {
  123. $image_url = get_featured_image_url($person->ID);
  124. $link = ($person->post_content != '') ? True : False;
  125. if( ($count % $row_size) == 0) {
  126. if($count > 0) {
  127. ?></div><?
  128. }
  129. ?><div class="row"><?
  130. }
  131. ?>
  132. <div class="span2 person-picture-wrap">
  133. <? if($link) {?><a href="<?=get_permalink($person->ID)?>"><? } ?>
  134. <img src="<?=$image_url ? $image_url : get_bloginfo('stylesheet_directory').'/static/img/no-photo.jpg'?>" />
  135. <div class="name"><?=Person::get_name($person)?></div>
  136. <div class="title"><?=get_post_meta($person->ID, 'person_jobtitle', True)?></div>
  137. <? if($link) {?></a><?}?>
  138. </div>
  139. <?
  140. $count++;
  141. }
  142. ?> </div>
  143. </div>
  144. <?
  145. return ob_get_clean();
  146. }
  147. add_shortcode('person-picture-list', 'sc_person_picture_list');
  148. /**
  149. * Post search
  150. *
  151. * @return string
  152. * @author Chris Conover
  153. **/
  154. function sc_post_type_search($params=array(), $content='') {
  155. $defaults = array(
  156. 'post_type_name' => 'post',
  157. 'taxonomy' => 'category',
  158. 'show_empty_sections' => false,
  159. 'non_alpha_section_name' => 'Other',
  160. 'column_width' => 'span4',
  161. 'column_count' => '3',
  162. 'order_by' => 'title',
  163. 'order' => 'ASC',
  164. 'show_sorting' => True,
  165. 'default_sorting' => 'term',
  166. 'show_sorting' => True,
  167. 'meta_key' => '',
  168. 'meta_value' => '',
  169. );
  170. $params = ($params === '') ? $defaults : array_merge($defaults, $params);
  171. $params['show_empty_sections'] = (bool)$params['show_empty_sections'];
  172. $params['column_count'] = is_numeric($params['column_count']) ? (int)$params['column_count'] : $defaults['column_count'];
  173. $params['show_sorting'] = (bool)$params['show_sorting'];
  174. if(!in_array($params['default_sorting'], array('term', 'alpha'))) {
  175. $params['default_sorting'] = $defaults['default_sorting'];
  176. }
  177. // Resolve the post type class
  178. if(is_null($post_type_class = get_custom_post_type($params['post_type_name']))) {
  179. return '<p>Invalid post type.</p>';
  180. }
  181. $post_type = new $post_type_class;
  182. // Set default search text if the user didn't
  183. if(!isset($params['default_search_text'])) {
  184. $params['default_search_text'] = 'Find a '.$post_type->singular_name;
  185. }
  186. // Register if the search data with the JS PostTypeSearchDataManager
  187. // Format is array(post->ID=>terms) where terms include the post title
  188. // as well as all associated tag names
  189. $search_data = array();
  190. foreach(get_posts(array('numberposts' => -1, 'post_type' => $params['post_type_name'], 'meta_key' => $params['meta_key'], 'meta_value' => $params['meta_value'])) as $post) {
  191. $search_data[$post->ID] = array($post->post_title);
  192. foreach(wp_get_object_terms($post->ID, 'post_tag') as $term) {
  193. $search_data[$post->ID][] = $term->name;
  194. }
  195. }
  196. ?>
  197. <script type="text/javascript">
  198. if(typeof PostTypeSearchDataManager != 'undefined') {
  199. PostTypeSearchDataManager.register(new PostTypeSearchData(
  200. <?=json_encode($params['column_count'])?>,
  201. <?=json_encode($params['column_width'])?>,
  202. <?=json_encode($search_data)?>
  203. ));
  204. }
  205. </script>
  206. <?
  207. // Split up this post type's posts by term
  208. $by_term = array();
  209. foreach(get_terms($params['taxonomy']) as $term) {
  210. $posts = get_posts(array(
  211. 'numberposts' => -1,
  212. 'post_type' => $params['post_type_name'],
  213. 'tax_query' => array(
  214. array(
  215. 'taxonomy' => $params['taxonomy'],
  216. 'field' => 'id',
  217. 'terms' => $term->term_id
  218. )
  219. ),
  220. 'meta_key' => $params['meta_key'],
  221. 'meta_value' => $params['meta_value'],
  222. 'orderby' => $params['order_by'],
  223. 'order' => $params['order']
  224. ));
  225. if(count($posts) == 0 && $params['show_empty_sections']) {
  226. $by_term[$term->name] = array();
  227. } else {
  228. $by_term[$term->name] = $posts;
  229. }
  230. }
  231. // Split up this post type's posts by the first alpha character
  232. $by_alpha = array();
  233. $by_alpha_posts = get_posts(array(
  234. 'numberposts' => -1,
  235. 'post_type' => $params['post_type_name'],
  236. 'orderby' => 'title',
  237. 'order' => 'alpha',
  238. 'meta_key' => $params['meta_key'],
  239. 'meta_value' => $params['meta_value'],
  240. ));
  241. foreach($by_alpha_posts as $post) {
  242. if(preg_match('/([a-zA-Z])/', $post->post_title, $matches) == 1) {
  243. $by_alpha[strtoupper($matches[1])][] = $post;
  244. } else {
  245. $by_alpha[$params['non_alpha_section_name']][] = $post;
  246. }
  247. }
  248. ksort($by_alpha);
  249. if($params['show_empty_sections']) {
  250. foreach(range('a', 'z') as $letter) {
  251. if(!isset($by_alpha[strtoupper($letter)])) {
  252. $by_alpha[strtoupper($letter)] = array();
  253. }
  254. }
  255. }
  256. $sections = array(
  257. 'post-type-search-term' => $by_term,
  258. 'post-type-search-alpha' => $by_alpha,
  259. );
  260. ob_start();
  261. ?>
  262. <div class="post-type-search">
  263. <div class="post-type-search-header">
  264. <form class="post-type-search-form" action="." method="get">
  265. <label style="display:none;">Search</label>
  266. <input type="text" class="span3" placeholder="<?=$params['default_search_text']?>" />
  267. </form>
  268. </div>
  269. <div class="post-type-search-results "></div>
  270. <? if($params['show_sorting']) { ?>
  271. <div class="btn-group post-type-search-sorting">
  272. <button class="btn<?if($params['default_sorting'] == 'term') echo ' active';?>"><i class="icon-list-alt"></i></button>
  273. <button class="btn<?if($params['default_sorting'] == 'alpha') echo ' active';?>"><i class="icon-font"></i></button>
  274. </div>
  275. <? } ?>
  276. <?
  277. if (is_null($post_type_class = get_custom_post_type('document'))) {
  278. return '<p>Invalid post type.</p>';
  279. }
  280. $post_type = new $post_type_class;
  281. foreach($sections as $id => $section) {
  282. $hide = false;
  283. switch($id) {
  284. case 'post-type-search-alpha':
  285. if($params['default_sorting'] == 'term') {
  286. $hide = True;
  287. }
  288. break;
  289. case 'post-type-search-term':
  290. if($params['default_sorting'] == 'alpha') {
  291. $hide = True;
  292. }
  293. break;
  294. }
  295. ?>
  296. <div class="<?=$id?>"<? if($hide) echo ' style="display:none;"'; ?>>
  297. <? foreach($section as $section_title => $section_posts) { ?>
  298. <? if(count($section_posts) > 0 || $params['show_empty_sections']) { ?>
  299. <div>
  300. <h3><?=esc_html($section_title)?></h3>
  301. <div class="row tt-search-docs">
  302. <? if(count($section_posts) > 0) { ?>
  303. <? $posts_per_column = ceil(count($section_posts) / $params['column_count']); ?>
  304. <? foreach(range(0, $params['column_count'] - 1) as $column_index) { ?>
  305. <? $start = $column_index * $posts_per_column; ?>
  306. <? $end = $posts_per_column; ?>
  307. <? if(count($section_posts) > $start) { ?>
  308. <div class="<?=$params['column_width']?> document-list">
  309. <ul>
  310. <? foreach(array_slice($section_posts, $start, $end) as $post) { ?>
  311. <li class="<?=$post_type->get_document_application($post); ?>" data-post-id="<?=$post->ID?>"><?=$post_type->toHTML($post)?></li>
  312. <? } ?>
  313. </ul>
  314. </div>
  315. <? } ?>
  316. <? } ?>
  317. <? } ?>
  318. </div>
  319. </div>
  320. <? } ?>
  321. <? } ?>
  322. </div>
  323. <?
  324. }
  325. ?> </div> <?
  326. return ob_get_clean();
  327. }
  328. add_shortcode('post-type-search', 'sc_post_type_search');
  329. /**
  330. * License Post search
  331. *
  332. * @return string
  333. * @author Brandon Goves
  334. **/
  335. function sc_license_post_type_search($params=array(), $content='') {
  336. $defaults = array(
  337. 'post_type_name' => 'post',
  338. 'taxonomy' => 'category',
  339. 'show_empty_sections' => false,
  340. 'non_alpha_section_name' => 'Other',
  341. 'column_width' => 'span4',
  342. 'column_count' => '3',
  343. 'order_by' => 'title',
  344. 'order' => 'ASC',
  345. 'show_sorting' => True,
  346. 'default_sorting' => 'term',
  347. 'show_sorting' => False,
  348. 'meta_key' => '',
  349. 'meta_value' => '',
  350. );
  351. $params = ($params === '') ? $defaults : array_merge($defaults, $params);
  352. $params['show_empty_sections'] = (bool)$params['show_empty_sections'];
  353. $params['column_count'] = is_numeric($params['column_count']) ? (int)$params['column_count'] : $defaults['column_count'];
  354. $params['show_sorting'] = (bool)$params['show_sorting'];
  355. if(!in_array($params['default_sorting'], array('term', 'alpha'))) {
  356. $params['default_sorting'] = $defaults['default_sorting'];
  357. }
  358. // Resolve the post type class
  359. if(is_null($post_type_class = get_custom_post_type($params['post_type_name']))) {
  360. return '<p>Invalid post type.</p>';
  361. }
  362. $post_type = new $post_type_class;
  363. // Set default search text if the user didn't
  364. if(!isset($params['default_search_text'])) {
  365. $params['default_search_text'] = 'Find a '.$post_type->singular_name;
  366. }
  367. // Register if the search data with the JS PostTypeSearchDataManager
  368. // Format is array(post->ID=>terms) where terms include the post title
  369. // as well as all associated tag names
  370. $search_data = array();
  371. foreach(get_posts(array('numberposts' => -1, 'post_type' => $params['post_type_name'], 'meta_key' => $params['meta_key'], 'meta_value' => $params['meta_value'])) as $post) {
  372. $search_data[$post->ID] = array($post->post_title);
  373. foreach(wp_get_object_terms($post->ID, 'post_tag') as $term) {
  374. $search_data[$post->ID][] = $term->name;
  375. }
  376. }
  377. ?>
  378. <script type="text/javascript">
  379. if(typeof PostTypeSearchDataManager != 'undefined') {
  380. PostTypeSearchDataManager.register(new PostTypeSearchData(
  381. <?=json_encode($params['column_count'])?>,
  382. <?=json_encode($params['column_width'])?>,
  383. <?=json_encode($search_data)?>
  384. ));
  385. }
  386. </script>
  387. <?
  388. // Split up this post type's posts by term
  389. $by_term = array();
  390. foreach(get_terms($params['taxonomy'], array('parent' => 0)) as $term) {
  391. foreach(get_term_children($term->term_id, $params['taxonomy']) as $child_term_id) {
  392. $posts = get_posts(array(
  393. 'numberposts' => -1,
  394. 'post_type' => $params['post_type_name'],
  395. 'tax_query' => array(
  396. array(
  397. 'taxonomy' => $params['taxonomy'],
  398. 'field' => 'id',
  399. 'terms' => $child_term_id
  400. )
  401. ),
  402. 'meta_key' => $params['meta_key'],
  403. 'meta_value' => $params['meta_value'],
  404. 'orderby' => $params['order_by'],
  405. 'order' => $params['order']
  406. ));
  407. $child_term = get_term_by('id', $child_term_id, $params['taxonomy']);
  408. if(count($posts) == 0 && $params['show_empty_sections']) {
  409. $by_term[$term->name][$child_term->name] = array();
  410. } else if (count($posts)) {
  411. $by_term[$term->name][$child_term->name] = $posts;
  412. ksort($by_term[$term->name]);
  413. }
  414. }
  415. }
  416. // Split up this post type's posts by the first alpha character
  417. $by_alpha = array();
  418. $by_alpha_posts = get_posts(array(
  419. 'numberposts' => -1,
  420. 'post_type' => $params['post_type_name'],
  421. 'orderby' => 'title',
  422. 'order' => 'alpha',
  423. 'meta_key' => $params['meta_key'],
  424. 'meta_value' => $params['meta_value'],
  425. ));
  426. foreach($by_alpha_posts as $post) {
  427. if(preg_match('/([a-zA-Z])/', $post->post_title, $matches) == 1) {
  428. $by_alpha[strtoupper($matches[1])][] = $post;
  429. } else {
  430. $by_alpha[$params['non_alpha_section_name']][] = $post;
  431. }
  432. }
  433. ksort($by_alpha);
  434. if($params['show_empty_sections']) {
  435. foreach(range('a', 'z') as $letter) {
  436. if(!isset($by_alpha[strtoupper($letter)])) {
  437. $by_alpha[strtoupper($letter)] = array();
  438. }
  439. }
  440. }
  441. $sections = array(
  442. 'post-type-search-term' => $by_term,
  443. 'post-type-search-alpha' => $by_alpha,
  444. );
  445. ob_start();
  446. ?>
  447. <div class="post-type-search">
  448. <div class="post-type-search-header">
  449. <form class="post-type-search-form" action="." method="get">
  450. <label style="display:none;">Search</label>
  451. <input type="text" class="span3" placeholder="<?=$params['default_search_text']?>" />
  452. </form>
  453. </div>
  454. <div class="post-type-search-results "></div>
  455. <? if($params['show_sorting']) { ?>
  456. <div class="btn-group post-type-search-sorting">
  457. <button class="btn<?if($params['default_sorting'] == 'term') echo ' active';?>"><i class="icon-list-alt"></i></button>
  458. <button class="btn<?if($params['default_sorting'] == 'alpha') echo ' active';?>"><i class="icon-font"></i></button>
  459. </div>
  460. <? } ?>
  461. <?
  462. if (is_null($post_type_class = get_custom_post_type('document'))) {
  463. return '<p>Invalid post type.</p>';
  464. }
  465. $post_type = new $post_type_class;
  466. foreach($sections as $id => $section) {
  467. $hide = false;
  468. switch($id) {
  469. case 'post-type-search-alpha':
  470. if($params['default_sorting'] == 'term') {
  471. $hide = True;
  472. }
  473. break;
  474. case 'post-type-search-term':
  475. if($params['default_sorting'] == 'alpha') {
  476. $hide = True;
  477. }
  478. break;
  479. }
  480. ?>
  481. <? if($id == 'post-type-search-term') { ?>
  482. <div class="tt-search-header-index">
  483. <?php foreach($section as $section_title => $sub_section) { ?>
  484. <h3 name="<?=sanitize_title($section_title); ?>" id="<?=sanitize_title($section_title); ?>" class="tt-search-header"><?=esc_html($section_title)?></h3>
  485. <? foreach($sub_section as $sub_section_title => $sub_section_posts) { ?>
  486. <? if(count($sub_section_posts) > 0 || $params['show_empty_sections']) { ?>
  487. <? $subheader_tag = esc_html(str_replace(' ', '', $sub_section_title)); ?>
  488. <a href="#<?=sanitize_title($subheader_tag); ?>"><h4 class="tt-search-subheader btn btn-default btn-flat"><?=esc_html($sub_section_title); ?></h4></a>
  489. <?php } ?>
  490. <?php } ?>
  491. <?php } ?>
  492. </div>
  493. <div class="<?=$id?>"<? if($hide) echo ' style="display:none;"'; ?>>
  494. <? foreach($section as $section_title => $sub_section) { ?>
  495. <div>
  496. <h3 name="<?=sanitize_title($section_title); ?>" id="<?=sanitize_title($section_title); ?>" class="tt-search-header"><?=esc_html($section_title)?></h3>
  497. <div class="row"><div class="span12 tt-search-divider"></div></div>
  498. <? foreach($sub_section as $sub_section_title => $sub_section_posts) { ?>
  499. <? if(count($sub_section_posts) > 0 || $params['show_empty_sections']) { ?>
  500. <? $subheader_tag = esc_html(str_replace(' ', '', $sub_section_title)); ?>
  501. <a href="#<?=sanitize_title($subheader_tag); ?>"><h4 id="<?=sanitize_title($subheader_tag); ?>" class="tt-search-subheader"><?=strtoupper(esc_html($sub_section_title)); ?></h4></a>
  502. <div class="row tt-search-docs">
  503. <? if(count($sub_section_posts) > 0) { ?>
  504. <? $posts_per_column = ceil(count($sub_section_posts) / $params['column_count']); ?>
  505. <? foreach(range(0, $params['column_count'] - 1) as $column_index) { ?>
  506. <? $start = $column_index * $posts_per_column; ?>
  507. <? $end = $posts_per_column; ?>
  508. <? if(count($sub_section_posts) > $start) { ?>
  509. <div class="<?=$params['column_width']?> document-list">
  510. <ul>
  511. <? foreach(array_slice($sub_section_posts, $start, $end) as $post) { ?>
  512. <li class="<?=$post_type->get_document_application($post); ?>"
  513. data-post-id="<?=$post->ID?>"><?=$post_type->toHTML($post)?></li>
  514. <? } ?>
  515. </ul>
  516. </div>
  517. <? } ?>
  518. <? } ?>
  519. <? } ?>
  520. </div>
  521. <? } ?>
  522. <? } ?>
  523. </div>
  524. <? } ?>
  525. </div>
  526. <? } else { ?>
  527. <div class="<?=$id?>"<? if($hide) echo ' style="display:none;"'; ?>>
  528. <? foreach($section as $section_title => $section_posts) { ?>
  529. <? if(count($section_posts) > 0 || $params['show_empty_sections']) { ?>
  530. <div>
  531. <h3><?=esc_html($section_title)?></h3>
  532. <div class="row tt-search-docs">
  533. <? if(count($section_posts) > 0) { ?>
  534. <? $posts_per_column = ceil(count($section_posts) / $params['column_count']); ?>
  535. <? foreach(range(0, $params['column_count'] - 1) as $column_index) { ?>
  536. <? $start = $column_index * $posts_per_column; ?>
  537. <? $end = $posts_per_column; ?>
  538. <? if(count($section_posts) > $start) { ?>
  539. <div class="<?=$params['column_width']?> document-list">
  540. <ul>
  541. <? foreach(array_slice($section_posts, $start, $end) as $post) { ?>
  542. <li class="<?=$post_type->get_document_application($post); ?>" data-post-id="<?=$post->ID?>"><?=$post_type->toHTML($post)?></li>
  543. <? } ?>
  544. </ul>
  545. </div>
  546. <? } ?>
  547. <? } ?>
  548. <? } ?>
  549. </div>
  550. </div>
  551. <? } ?>
  552. <? } ?>
  553. </div>
  554. <? } ?>
  555. <?
  556. }
  557. ?> </div>
  558. <script>
  559. jQuery(document).ready(function() {
  560. var offset = 220;
  561. var duration = 500;
  562. jQuery(window).scroll(function() {
  563. if (jQuery(this).scrollTop() > offset) {
  564. jQuery('.back-to-top').fadeIn(duration);
  565. } else {
  566. jQuery('.back-to-top').fadeOut(duration);
  567. }
  568. });
  569. jQuery('.back-to-top').click(function(event) {
  570. event.preventDefault();
  571. jQuery('html, body').animate({scrollTop: 0}, duration);
  572. return false;
  573. });
  574. jQuery('.btn-flat').click(function(event) {
  575. event.preventDefault();
  576. var scrollToElem = this.parentElement.hash;
  577. jQuery('html, body').animate({scrollTop: $(scrollToElem).offset().top}, duration);
  578. return false;
  579. });
  580. });
  581. </script>
  582. <a href="#" class="back-to-top">Back to Top</a>
  583. <?php
  584. return ob_get_clean();
  585. }
  586. add_shortcode('license-post-type-search', 'sc_license_post_type_search');
  587. ?>