PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-ui/inc/widgets.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 603 lines | 492 code | 100 blank | 11 comment | 69 complexity | 736b4c5c49e27b6a2a0f194ceca7e909 MD5 | raw file
  1. <?php
  2. // Widget with Rich text editing support. Pre 3.3
  3. class wpui_core_widget extends WP_Widget {
  4. private $rich_editing, $wpui_opts;
  5. function wpui_core_Widget() {
  6. $widget_ops = array( 'classname' => 'wpui_core', 'description' => __( 'Display your content in Tabs/Accordions/spoilers', 'wp-ui' ) );
  7. $control_ops = array( 'width' => 600, 'height' => 250, 'id_base' => 'wpui_core' );
  8. $this->WP_Widget( 'wpui_core', 'WP UI Widget', $widget_ops, $control_ops );
  9. $this->wpui_opts = get_option( 'wpUI_options' );
  10. $this->rich_editing = (isset( $this->wpui_opts ) && isset( $this->wpui_opts['widget_rich_text'])) ? true : 'false';
  11. add_action( 'admin_print_scripts-widgets.php' , array( &$this, 'add_tabs' ));
  12. // add_action( 'admin_footer-widgets.php' , array( &$this, 'mod_tinymce' ));
  13. }
  14. function add_tabs() {
  15. wp_enqueue_script( 'jquery-ui-core' );
  16. wp_enqueue_script( 'jquery-ui-tabs' );
  17. }
  18. function widget( $args, $instance ) {
  19. extract( $args );
  20. echo $before_widget;
  21. $title = apply_filters('widget_title', $instance['title'] );
  22. if ( $title ) {
  23. echo $before_title . $title . $after_title;
  24. }
  25. $itemz = $instance[ 'item' ];
  26. $typez = isset( $instance[ 'type'] ) ? $instance[ 'type' ] : 'tabs';
  27. if ( isset( $instance[ 'style' ] ) && $instance['style'] != 'default' )
  28. $stylez = $instance[ 'style' ];
  29. if ( $typez == 'tabs' || $typez == 'accordion' ) {
  30. echo '<div class="wp-' . $typez . ' ' . $stylez . '">';
  31. foreach( $itemz as $item ) {
  32. if ( $item['title'] == '' ) continue;
  33. echo '<h3 class="wp-tab-title">' . do_shortcode( $item[ 'title' ] ) . '</h3>';
  34. echo '<div class="wp-tab-content">' . do_shortcode( $item[ 'panel' ] ) . '</div>';
  35. }
  36. echo '</div>';
  37. } else {
  38. foreach( $itemz as $item ) {
  39. if ( $item['title'] == '' ) continue;
  40. echo '<div class="wp-spoiler ' . $stylez . '">';
  41. echo '<h3 class="ui-collapsible-header"><span class="ui-icon"></span>' . do_shortcode( $item[ 'title' ] ) . '</h3>';
  42. echo '<div class="ui-collapsible-content">' . do_shortcode( $item[ 'panel' ] ) . '</div>';
  43. echo '<div><!-- end .wp-spoiler -->';
  44. }
  45. }
  46. echo $after_widget;
  47. }
  48. function update( $new_instance, $old_instance ) {
  49. $instance = $old_instance;
  50. $instance = $new_instance;
  51. return $instance;
  52. }
  53. function form( $instance ) {
  54. $defaults = array(
  55. 'title' => '',
  56. 'type' => 'tabs',
  57. 'number' => '4',
  58. 'style' => 'wpui-light',
  59. 'item' => array()
  60. );
  61. static $wpui_widget_inst = 0;
  62. $wpui_widget_inst++;
  63. // prevent undefined index notice.
  64. for ( $i = 0; $i <= 4; $i++ ) {
  65. $defaults['item'][$i] = array('title' => '', 'panel' => '' );
  66. }
  67. if ( !isset( $instance[ 'number' ] ) )
  68. $instance[ 'number' ] = $defaults[ 'number' ];
  69. for ( $i = 0; $i <= $instance[ 'number' ]; $i++ ) {
  70. if ( ! isset( $instance[ 'item' ][$i]) )
  71. $instance['item'][$i] = array('title' => '', 'panel' => '' );
  72. }
  73. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  74. <div class="wpui-widget-left-block">
  75. <p>
  76. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e("Title"); ?>:</label>
  77. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  78. </p>
  79. <p>
  80. <label>Type and number of panels</label>
  81. <select id="<?php echo $this->get_field_id( 'type' ) ?>" name="<?php echo $this->get_field_name( 'type' ); ?>">
  82. <option value="tabs" <?php selected( $instance['type'], 'tabs') ?>>Tabs</option>
  83. <option value="accordion" <?php selected( $instance['type'], 'accordion') ?> >Accordion</option>
  84. <option value="spoiler" <?php selected( $instance['type'], 'spoiler') ?> >Spoilers</option>
  85. </select>
  86. <select id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ) ?>">
  87. <?php for( $a=2; $a < 10; $a++ ) { ?>
  88. <option value="<?php echo $a ?>" <?php selected( $instance[ 'number' ], $a ) ?>><?php echo $a ?></option>
  89. <?php } ?>
  90. </select>
  91. </p>
  92. <p>
  93. <?php $skins_list = wpui_get_skins_list(); ?>
  94. <select id="<?php echo $this->get_field_id( 'style' ) ?>" name="<?php echo $this->get_field_name( 'style' ) ?>">
  95. <option value="default">Default</option>
  96. <?php
  97. foreach( $skins_list as $skin=>$name ) {
  98. if ( stristr( $skin, 'startoptgroup' ) ) {
  99. echo '<optgroup label="' . $name . '">';
  100. } else if ( stristr( $skin, 'endoptgroup') ) {
  101. echo '</optgroup>';
  102. } else {
  103. $sel = ( $instance[ 'style' ] == $skin ) ? ' selected="selected"' : '';
  104. echo '<option value="' . $skin . '"' . $sel . '>' . $name . '</option>';
  105. }
  106. }
  107. ?>
  108. </select>
  109. </p>
  110. <h4>Notes</h4>
  111. <ul style="list-style : disc inside none;">
  112. <li>Please save the widget once, right after adding it.</li>
  113. <li>Please do so when increasing the number of panels.</li>
  114. <li>Shortcodes can be used inside the content.</li>
  115. <li>Panels with empty content are not shown.</li>
  116. </ul>
  117. </div>
  118. <div class="wpui-accordion">
  119. <?php for( $k=1; $k <= $instance['number' ]; $k++ ) { ?>
  120. <h3 class="wpui-hide-handle">Panel <?php echo $k ?></h3>
  121. <div class="wp-tab-content" style="position : relative;">
  122. <p>
  123. <label for="<?php echo $this->get_field_id( 'item-' . $k . '-title' ) ?>">Title</label>
  124. <input class="widefat" id="<?php echo $this->get_field_id( 'item' . $k . '-title' ) ?>" name="<?php echo $this->get_field_name( 'item][' . $k . '][title]' ) ?>" value="<?php echo htmlspecialchars($instance[ 'item' ][ $k ][ 'title' ]); ?>">
  125. <label for="<?php echo $this->get_field_id('item-' . $k . '-panel') ?>" >Contents of Panel <?php echo $k ?> ( Shortcodes allowed. )</label>
  126. <textarea cols="5" rows="15" class="widefat wpui-edit" id="<?php echo $this->get_field_id( 'item-' . $k . '-panel' ); ?>" name="<?php echo $this->get_field_name( 'item][' . $k . '][panel]' ); ?>"><?php echo $instance[ 'item'][$k]['panel'] ?></textarea>
  127. </p>
  128. </div>
  129. <?php } ?>
  130. </div><!-- end .wpui-accordion -->
  131. <?php
  132. if ( $wpui_widget_inst <= 1 ) {
  133. ?>
  134. <script type="text/javascript">
  135. function array_diff( arr1, arr2 ) {
  136. var same = [],diff = [];
  137. for ( var i =0; i < arr2.length; i++ ) {
  138. same[ arr2[i] ] = true;
  139. }
  140. for( var k =0; k < arr1.length; k++ ) {
  141. if ( ! same[ arr1[k] ] )
  142. diff.push( arr1[k]);
  143. }
  144. return diff;
  145. }
  146. // All ready.
  147. jQuery( function() {
  148. jQuery( 'h3.wpui-hide-handle' ).each(function() {
  149. jQuery( this ).appendTo( jQuery( this ).next() ).hide();
  150. });
  151. jQuery( '.wpui-accordion' ).each(function() {
  152. numPanel = jQuery( this ).children( 'div.wp-tab-content' ).length;
  153. if ( jQuery( this ).find( 'ul.ui-tabs-nav' ).length == 0 )
  154. jQuery( this ).prepend( '<ul class="ui-tabs-nav wpui-widget-ul" />' );
  155. liStr = '';
  156. for ( i = 1; i <= numPanel; i++ ) {
  157. thisID = "panel-" + i;
  158. liStr += ( '<li><a href="#' + thisID + '">' + "Panel <span class='panel-num'>" + i + '</span></a></li>' );
  159. jQuery( this )
  160. .children( '.wp-tab-content' )
  161. .eq( i - 1 )
  162. .attr( "id" , thisID );
  163. }
  164. // jQuery( this ).find( 'h3.wpui-hide-handle' ).remove();
  165. jQuery( this )
  166. .children( 'ul.ui-tabs-nav' )
  167. .html( liStr );
  168. });
  169. $tabs = jQuery( '.wpui-accordion' ).tabs({
  170. fx : { opacity : 'toggle' }
  171. });
  172. $tabs.tabs( "option", "disabled", true );
  173. $tabs.tabs();
  174. jQuery( 'a.widget-action' )
  175. .live('click', function( e ) {
  176. e.stopPropagation();
  177. jQuery( this )
  178. .closest( 'div.widget' )
  179. .find( 'ul.ui-tabs-nav' )
  180. .find( 'li a' ).eq(0 ).click();
  181. return false;
  182. });
  183. }); // document.ready
  184. </script>
  185. <style type="text/css">
  186. .wpui-hide-handle {
  187. background-color: whiteSmoke;
  188. background-image: -ms-linear-gradient(top,#f9f9f9,#f5f5f5);
  189. background-image: -moz-linear-gradient(top,#f9f9f9,#f5f5f5);
  190. background-image: -o-linear-gradient(top,#f9f9f9,#f5f5f5);
  191. background-image: -webkit-gradient(linear,left top,left bottom,from(#f9f9f9),to(#f5f5f5));
  192. background-image: -webkit-linear-gradient(top,#f9f9f9,#f5f5f5);
  193. background-image: linear-gradient(top,#f9f9f9,#f5f5f5);
  194. -moz-box-shadow: inset 0 1px 0 #fff;
  195. -webkit-box-shadow: inset 0 1px 0 #fff;
  196. box-shadow: inset 0 1px 0 #fff;
  197. -moz-border-radius: 3px;
  198. -khtml-border-radius: 3px;
  199. -webkit-border-radius: 3px;
  200. border-radius: 3px;
  201. border: 1px solid #DFDFDF;
  202. -moz-border-radius: 3px;
  203. -khtml-border-radius: 3px;
  204. -webkit-border-radius: 3px;
  205. border-radius: 3px;
  206. padding: 5px;margin-bottom :0px;
  207. }
  208. .wp-tab-content {
  209. padding: 10px;
  210. background : #F4F2F4;
  211. border: 1px solid #DEDEDE;
  212. -moz-border-radius : 4px;
  213. -webkit-border-radius : 4px;
  214. -o-border-radius : 4px;
  215. border-radius : 4px;
  216. -moz-box-shadow : 1px 1px 0 #FFF inset, -1px -1px 0 #FFF inset, 0 2px 4px rgba( 0, 0, 0, 0.1 );
  217. -webkit-box-shadow : 1px 1px 0 #FFF inset, -1px -1px 0 #FFF inset, 0 2px 4px rgba( 0, 0, 0, 0.1 );
  218. -o-box-shadow : 1px 1px 0 #FFF inset, -1px -1px 0 #FFF inset, 0 2px 4px rgba( 0, 0, 0, 0.1 );
  219. box-shadow : 1px 1px 0 #FFF inset, -1px -1px 0 #FFF inset, 0 2px 4px rgba( 0, 0, 0, 0.1 );
  220. }
  221. div.wpui-widget-left-block {/* background :red;*/
  222. width:180px;display :inline-block;vertical-align :top;
  223. }
  224. div.wpui-accordion {display :inline-block;width :400px;margin-left :20px;
  225. }
  226. div.ui-tabs-hide {display :none;
  227. }
  228. .wpui-widget-ul {/* background :red;*/
  229. /* padding:5px 0;*/
  230. text-align :center;
  231. word-spacing : -1em;
  232. position : relative;
  233. z-index : 1000;
  234. bottom : -1px;
  235. }
  236. .wpui-widget-ul *{
  237. word-spacing : normal;
  238. }
  239. .wpui-widget-ul li {/* background :black;*/
  240. color :#FFF;
  241. margin: 5px; display :inline-block;
  242. margin-bottom : 0px;
  243. padding : 0.5em;
  244. }
  245. /* .wpui-widget-ul li:hover {background :#DFDFDF;-moz-border-radius :3px;-webkit-border-radius :3px;-o-border-radius :3px;border-radius :3px;color :#FFF;text-shadow :0 1px 0 #FFF;
  246. }*/
  247. .wpui-widget-ul li a {color :#333;text-decoration :none;
  248. padding : 0.5em;
  249. }
  250. .wpui-widget-ul li.ui-tabs-selected {
  251. background : #F4F2F4;
  252. background: -moz-linear-gradient(top,#FAFAFA, #F4F2F4 );
  253. background: -webkit-linear-gradient(top,#FAFAFA,#F4F2F4);
  254. background: -o-linear-gradient(top,#FAFAFA,#F4F2F4);
  255. background: -ms-linear-gradient(top,#FAFAFA,#F4F2F4);
  256. border: 1px solid #DEDEDE;
  257. border-bottom-width : 0px;
  258. position : relative;
  259. bottom : -1px;
  260. color: #333;
  261. text-shadow: 0 1px 0 white;
  262. -moz-border-radius : 3px 3px 0 0;
  263. -webkit-border-radius : 3px 3px 0 0;
  264. -o-border-radius : 3px 3px 0 0;
  265. border-radius : 3px 3px 0 0;
  266. }
  267. .wpui-widget-ul li.ui-tabs-selected .panel-num {
  268. background: #D00;box-shadow :0 2px 0 rgba( 0,0,0,0.3 ) inset;
  269. color: white;
  270. text-shadow: 0 1px 0 black;
  271. padding: 3px 7px;
  272. border-radius: 15px;
  273. }
  274. </style>
  275. <?php
  276. } // end wpui_widget_inst if conditional
  277. } // end form method
  278. } // END class wpui_core_Widget
  279. function wpui_core_widget_func() {
  280. register_widget( 'wpui_core_widget' );
  281. }
  282. add_action( 'widgets_init', 'wpui_core_widget_func' );
  283. class wpui_posts_Widget extends WP_Widget {
  284. function wpui_posts_Widget() {
  285. $widget_ops = array( 'classname' => 'wpui-posts', 'description' => 'Implement your posts automatically as tabs, sliders, accordions or spoilers.' );
  286. $control_ops = array( 'width' => 500, 'height' => 250, 'id_base' => 'wpui-posts' );
  287. $this->WP_Widget( 'wpui-posts', 'WP UI Posts', $widget_ops, $control_ops );
  288. }
  289. function widget( $args, $instance ) {
  290. extract( $args );
  291. echo $before_widget;
  292. $title = apply_filters('widget_title', $instance['title'] );
  293. if ( $title ) {
  294. echo $before_title . $title . $after_title;
  295. }
  296. if ( ! isset( $instance[ 'type' ] ) ) return;
  297. $inst_args = '';
  298. if ( $instance['type' ] == 'cat' || $instance['type'] == 'tag' ) {
  299. $inst_args .= ' ' . $instance[ 'type' ] . '="' . $instance[ 'selected' ] . '"';
  300. } else {
  301. $inst_args .= ' get="' . $instance[ 'type' ] . '"';
  302. }
  303. if ( $instance[ 'wid_type' ] != 'tabs' ) {
  304. $inst_args .= ' type="accordion"';
  305. }
  306. if ( $instance[ 'template' ] != '' ) {
  307. $inst_args .= ' template="' . $instance[ 'template' ] . '"';
  308. }
  309. if ( isset( $instance[ 'style' ] ) && $instance[ 'style' ] != 'default' ) {
  310. $inst_args .= ' style="' . $instance[ 'style' ] . '"';
  311. }
  312. if ( isset( $instance[ 'names' ] ) && $instance['names'] != '' ) {
  313. $inst_args .= ' tab_names="' . $instance[ 'names' ] . '"';
  314. }
  315. if ( isset( $instance[ 'number' ] ) && $instance['number'] != '' ) {
  316. $inst_args .= ' number="' . $instance[ 'number' ] . '"';
  317. }
  318. echo do_shortcode( '[wptabposts' . $inst_args . ']' );
  319. echo $after_widget;
  320. }
  321. function update( $new_instance, $old_instance ) {
  322. $instance = $old_instance;
  323. $instance = $new_instance;
  324. // foreach ( array('title') as $val ) {
  325. // $instance[$val] = strip_tags( $new_instance[$val] );
  326. // }
  327. return $instance;
  328. }
  329. function form( $instance ) {
  330. $defaults = array(
  331. 'title' => '',
  332. 'type' => 'cat',
  333. 'wid_type' => 'tabs',
  334. 'selected' => '',
  335. 'names' => '',
  336. 'template' => 1,
  337. 'number' => 5,
  338. 'style' => 'default'
  339. );
  340. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  341. <div class="wpui-left-block">
  342. <p>
  343. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e("Title"); ?>:</label>
  344. <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
  345. </p>
  346. <p>
  347. <label for="<?php echo $this->get_field_id( 'wid_type' ) ?>" title="Type of widget">Type</label>
  348. <select id="<?php echo $this->get_field_id( 'wid_type' ) ?>" name="<?php echo $this->get_field_name( 'wid_type' ); ?>">
  349. <option value="tabs" <?php selected( $instance['wid_type'], 'tabs') ?>>Tabs</option>
  350. <option value="accordion"<?php selected( $instance['wid_type'], 'accordion') ?>>Accordion</option>
  351. </select>
  352. </p>
  353. <p>
  354. <label for="<?php echo $this->get_field_name( 'style' ) ?>" title="Styling for this widget. Default is the one selected on the options page.">Style</label>
  355. <?php $skins_list = wpui_get_skins_list(); ?>
  356. <select id="<?php echo $this->get_field_name( 'style' ) ?>" name="<?php echo $this->get_field_id( 'style' ) ?>">
  357. <option value="default">Default</option>
  358. <?php
  359. foreach( $skins_list as $skin=>$name ) {
  360. if ( stristr( $skin, 'startoptgroup' ) ) {
  361. echo '<optgroup label="' . $name . '">';
  362. } else if ( stristr( $skin, 'endoptgroup') ) {
  363. echo '</optgroup>';
  364. } else {
  365. if ( $instance[ 'style' ] == $skin ) $sel = ' selected="selected"';
  366. echo '<option value="' . $skin . '"' . $sel . '>' . $name . '</option>';
  367. }
  368. }
  369. ?>
  370. </select>
  371. </p>
  372. <p>
  373. <label title="Found on Options page -> Posts -> Template no." for="<?php echo $this->get_field_name( 'template' ); ?>">Template no.</label>
  374. <input type="text" class="widefat" id="<?php echo $this->get_field_id('template') ?>" name="<?php echo $this->get_field_name( 'template' ) ?>" value="<?php echo $instance['template'] ?>"/>
  375. </p>
  376. <p>
  377. <label title="Please don't alter this, unless you are sure. This will be the selected Taxonomy items separated with commas." for="<?php echo $this->get_field_name( 'selected' ); ?>">Currently Selected</label>
  378. <input type="text" class="widefat wpui-selected" id="<?php echo $this->get_field_id( 'selected' ); ?>" name="<?php echo $this->get_field_name('selected'); ?>" value="<?php echo $instance['selected'] ?>"/>
  379. </p>
  380. <!-- <h3>Usage</h3>
  381. <ol>
  382. <li>Select the taxonomy - Category / tag ,or by type - Recent/Popular/Random posts.</li>
  383. <li>Click search and the categories or tags will be displayed in the list.</li>
  384. <li>Click on any of the list item to toggle selection.</li>
  385. <li>Optional : Enter the title of tabs or accordions, separated with commas ( but no spaces ) in the last box.</li>
  386. <li>Click save, and check the frontpage.</li>
  387. </ol> -->
  388. </div>
  389. <div class="wpui-search-posts wpui-right-block">
  390. <label>Search term, type and number to display</label>
  391. <input type="text" length="10" id="wpui-search-field" name="wpui-search-field" value="" class="widefat" />
  392. <select class="wpui-search-type" id="<?php echo $this->get_field_id( 'type' ) ?>" name="<?php echo $this->get_field_name('type') ?>" value="<?php echo $instance['type'] ?>">
  393. <option value="cat" <?php selected( $instance['type'], 'cat'); ?>>Categories</option>
  394. <option value="tag" <?php selected( $instance['type'], 'tag'); ?>>Tag</option>
  395. <option value="recent" <?php selected( $instance['type'], 'recent'); ?>>Recent</option>
  396. <option value="popular" <?php selected( $instance['type'], 'popular'); ?>>Popular</option>
  397. <option value="random" <?php selected( $instance['type'], 'random'); ?>>Random</option>
  398. </select>
  399. <!-- <input type="text" id="wpui-search-number" class="widefat" name="wpui-search-number" style="width : 30px;" value="5" /> -->
  400. <input type="text" id="<?php echo $this->get_field_id( 'number' ); ?>" class="widefat" name="<?php echo $this->get_field_name( 'number' ) ?>" style="width : 30px;" value="<?php echo $instance[ 'number' ]; ?>" />
  401. <?php $wpuiTNonce = wp_create_nonce( 'wpui-editor-tax-nonce' ); ?>
  402. <input type="hidden" id="wpui-editor-tax-nonce" value="<?php echo $wpuiTNonce; ?>">
  403. <input type="button" id="wpui-fake-submit" value="Search" class="button-secondary" style="width : 280px; border-radius : 3px; margin:5px 0;" />
  404. <div class="wpui-search-results">
  405. <ul class="wpui-search-results-list"><li>Type your query and search.</li></ul>
  406. </div>
  407. <label for="<?php echo $this->get_field_name('names') ?>">Names for the tabs, separated by commas. This should match the number of posts selected. </label>
  408. <input type="text" class="widefat" id="<?php echo $this->get_field_id('names') ?>" name="<?php echo $this->get_field_name( 'names' ) ?>" value="<?php echo $instance['names'] ?>" />
  409. </div>
  410. <div style="clear : both;"></div>
  411. <style type="text/css">
  412. div.wpui-left-block {float: left;width : 150px;padding : 10px;}
  413. div.wpui-right-block { float: right; width : 310px; padding : 10px; clear : right;}
  414. #wpui-search-field { width : 170px; }
  415. .wpui-search-results { background : #FFF; border : 1px solid #DFDFDF; height : 185px; margin : 0 5px 5px; overflow : auto; position : relative; overflow : auto;}
  416. .wpui-search-results ul.wpui-search-results-list { list-style : none;}
  417. .wpui-search-results ul.wpui-search-results-list li { border-bottom: 1px solid #F1F1F1; padding : 4px 6px; position : relative; cursor : pointer; margin-bottom : 0;}
  418. .wpui-search-results ul.wpui-search-results-list li.selected { background : #DDD; font-weight : bold !important; }
  419. .wpui-search-results ul.wpui-search-results-list li a { text-decoration : none; color : #777; text-shadow: 0 1px 0 #FFF; display : block; width : 300px; overflow : hide;}
  420. span.info { position : absolute; top : 0; right : 0; height: 100%; padding : 4px; }
  421. </style>
  422. <script type="text/javascript">
  423. jQuery.fn.wpuiGetPosts = function( ) {
  424. var base = this;
  425. return base.each(function() {
  426. var $base = jQuery( this ),
  427. searchTerm = $base.closest( '#wpui-search-field' ),
  428. searchType = $base.siblings( 'select.wpui-search-type' ),
  429. searchNum = $base.closest( '#<?php echo $this->get_field_id( "number" ); ?>' ),
  430. searchSel = $base.parent().prev().find( '.wpui-selected' ),
  431. prevSels, wpuiQuery, ajaxFunc ;
  432. searchNum = searchNum || 5;
  433. if ( searchTerm == '' || searchType == '' ) return false;
  434. function ajaxFunc( ) {
  435. wpuiQuery = {
  436. action : 'wpui_query_meta',
  437. search : searchTerm.val(),
  438. type : searchType.val(),
  439. number : searchNum.val(),
  440. _ajax_tax_nonce : jQuery( '#wpui-editor-tax-nonce' ).val()
  441. };
  442. jQuery.post( ajaxurl, wpuiQuery, function( data ) {
  443. $base.next('div.wpui-search-results')
  444. .find( 'ul' ).html(data);
  445. if ( searchSel.val() != '' ) {
  446. prevSels = searchSel.val().split(',');
  447. for ( i=0; i < prevSels.length; i++ ) {
  448. $base.next('div.wpui-search-results')
  449. .find( 'ul li a[rel=' + searchType.val() + '-' + prevSels[i] + ']' )
  450. .parent()
  451. .addClass('selected');
  452. }
  453. }
  454. thisVal = '';
  455. $base.next('div.wpui-search-results')
  456. .find( 'ul li' )
  457. .unbind( 'click' )
  458. .bind( 'click', function() {
  459. if ( jQuery( this ).hasClass( 'no-select') ) return false;
  460. thisVal = jQuery(this).find('a').attr('rel').replace( /(post|cat|tag)\-/, '');
  461. jQuery( this ).toggleClass( 'selected' );
  462. thisVal += ',';
  463. alSel = searchSel.val();
  464. if ( alSel.match( thisVal ) )
  465. alSel = alSel.replace( thisVal, '' );
  466. else
  467. alSel += thisVal;
  468. searchSel.val( alSel );
  469. return false;
  470. });
  471. });
  472. };
  473. ajaxFunc( this );
  474. $base.bind( 'click', function( e ) {
  475. ajaxFunc();
  476. return false;
  477. });
  478. $base.siblings( 'select.wpui-search-type' ).bind('change', function() {
  479. searchSel.val('');
  480. ajaxFunc();
  481. });
  482. });
  483. };
  484. jQuery( function() {
  485. jQuery( '#widgets-right #wpui-fake-submit' ).wpuiGetPosts();
  486. });
  487. </script><?php
  488. }
  489. }
  490. function wpui_posts_widget_func() {
  491. register_widget( 'wpui_posts_Widget' );
  492. }
  493. add_action( 'widgets_init', 'wpui_posts_widget_func' );
  494. ?>