Skip to content

Commit

Permalink
comments and renaming and add option for placeholder and i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Bearded Avenger committed Jun 11, 2015
1 parent b6c218d commit b91c4a2
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 100 deletions.
9 changes: 0 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ module.exports = function(grunt) {
options: { livereload: true },
files: ['public/assets/**/*', '**/*.html', '**/*.php', 'public/assets/img/**/*.{png,jpg,jpeg,gif,webp,svg}']
}
},
concat: {
dist: {
src: [
'public/assets/js/source/util--wp-api.js',
'public/assets/js/source/wp-search.js'
],
dest: 'public/assets/js/wp-search.js'
}
},
compass: {
dist: {
Expand Down
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== WP Live Search ===
Contributors: nphaskins
Author URI: http://nickhaskins.com
Plugin URI: http://nickhaskins.com/wp-search
Plugin URI: http://nickhaskins.com/wpls
Tags: search, live search
Requires at least: 3.5.1
Tested up to: 4.2.1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "wp-search",
"name": "wpls",
"version": "0.0.1",
"dependencies": {
"load-grunt-tasks": "~0.2.1"
Expand Down
2 changes: 1 addition & 1 deletion public/assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

jQuery('document').ready( function( $ ){

var backboneTemplate = $('#wp-search--tmpl')
var backboneTemplate = $('#wpls--tmpl')
, itemTemplate = _.template( backboneTemplate.html() )
, posts = new wp.api.collections.Posts()
, postList = '#wp-search--post-list'
, results = '#wp-search--results'
, loader = '#wp-search--loading'
, input = '#wp-search--input'
, helper = '#wp-search--helper'
, postList = '#wpls--post-list'
, results = '#wpls--results'
, loader = '#wpls--loading'
, input = '#wpls--input'
, helper = '#wpls--helper'
, helperText = wp_search_vars.helperText
, helperSpan = '<span id="wp-search--helper">'+helperText+'</span>'
, helperSpan = '<span id="wpls--helper">'+helperText+'</span>'
, api = WP_API_Settings.root
, timer

Expand Down
18 changes: 9 additions & 9 deletions public/assets/sass/source/_base.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Results wrap
.wp-search--results-wrap {
.wpls--results-wrap {
opacity:0;
}

// Input Wrap
#wp-search--input-wrap {
#wpls--input-wrap {
position:relative;
}

// The Input
#wp-search--input {
#wpls--input {
height:$input--height;
}

// List of posts
#wp-search--post-list {
#wpls--post-list {
list-style:none;
margin:0;
padding:0;
Expand All @@ -33,13 +33,13 @@
padding:$spacing--sm;
}

.wp-search--item-title {
.wpls--item-title {
margin:5px auto;
}
}

// Item Link
.wp-search--link {
.wpls--link {
@include clearfix();

&:hover {
Expand All @@ -48,21 +48,21 @@
}

// Item image
.wp-search--item-image {
.wpls--item-image {
float:left;
max-width:$spacing--lg;
margin-right:$spacing--sm;
}

// Item title
.wp-search--item-title {
.wpls--item-title {
display:inline-block;
overflow:hidden;
width:auto;
}

// Character helper
#wp-search--helper {
#wpls--helper {
position:absolute;
right:7px;
top:7px;
Expand Down
4 changes: 2 additions & 2 deletions public/assets/sass/source/_loader.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

.wp-search--loading {
.wpls--loading {
height:20px;
width:20px;
position:absolute;
Expand All @@ -9,7 +9,7 @@
}


.wp-search--loader {
.wpls--loader {
height:20px;
width:20px;
margin:10px auto;
Expand Down
46 changes: 4 additions & 42 deletions public/class-wp-search.php → public/class-wp-live-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* WP Search
*
* @package WP_Search
* @package WP_Live_Search
* @author Nick Haskins <email@nickhaskins.com>
* @license GPL-2.0+
* @link http://example.com
Expand All @@ -11,33 +11,10 @@

/**
*
* @package WP_Search
* @package WP_Live_Search
* @author Nick Haskins <email@nickhaskins.com>
*/
class WP_Search {

/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 0.0.1
*
* @var string
*/
const VERSION = '0.0.1';

/**
* Unique identifier
*
*
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* plugin file.
*
* @since 0.0.1
*
* @var string
*/
protected $plugin_slug = 'wp-search';
class WP_Live_Search {

/**
* Instance of this class.
Expand All @@ -64,16 +41,6 @@ private function __construct() {
require WP_SEARCH_DIR.'/public/includes/class.assets.php';
}

/**
* Return the plugin slug.
*
* @since 0.0.1
*
* @return Plugin slug variable.
*/
public function get_plugin_slug() {
return $this->plugin_slug;
}

/**
* Return an instance of this class.
Expand Down Expand Up @@ -227,9 +194,4 @@ private static function single_deactivate() {
// @TODO: Define deactivation functionality here
}

}





}
6 changes: 3 additions & 3 deletions public/includes/class.assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function scripts(){
wp_localize_script( 'wp-api-js', 'WP_API_Settings', $settings );

// wp search script
wp_enqueue_script('wp-search', WP_SEARCH_URL.'/public/assets/js/wp-search.js', array('jquery'), WP_SEARCH_VERSION, true);
wp_localize_script('wp-search','wp_search_vars', array('helperText' => __('one more character','wp-search')));
wp_enqueue_script('wpls-script', WP_SEARCH_URL.'/public/assets/js/wp-live-search.js', array('jquery'), WP_SEARCH_VERSION, true);
wp_localize_script('wpls-script','wp_search_vars', array('helperText' => __('one more character','wp-live-search')));

// wp seatch style
wp_enqueue_style('wp-search-style', WP_SEARCH_URL.'/public/assets/css/style.css', WP_SEARCH_VERSION );
wp_enqueue_style('wpls-style', WP_SEARCH_URL.'/public/assets/css/style.css', WP_SEARCH_VERSION );
}

}
Expand Down
21 changes: 11 additions & 10 deletions public/includes/class.shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ class wpSearchShortcode{

public function __construct(){

add_shortcode('wp_search', array($this,'shortcode'));
add_shortcode('wp_live_search', array($this,'shortcode'));
}

public function shortcode( $atts, $content = null ) {

$defaults = array(
'type' => 'posts',
'results' => __('entries found','wp-search')
'type' => 'posts',
'placeholder' => __('Search...','wp-live-search'),
'results' => __('entries found','wp-live-search')
);
$atts = shortcode_atts( $defaults, $atts );

Expand All @@ -20,19 +21,19 @@ public function shortcode( $atts, $content = null ) {
ob_start();

?>
<div id="wp-search" class="wp-search">
<div id="wpls" class="wpls">

<div class="wp-search--results-wrap">
<span id="wp-search--results"></span>
<div class="wpls--results-wrap">
<span id="wpls--results"></span>
<span><?php echo esc_html( $results_text );?></span>
</div>

<div id="wp-search--input-wrap">
<input type="text" id="wp-search--input" placeholder="Search...">
<div id="wp-search--loading" class="wp-search--loading"><div class="wp-search--loader"></div></div>
<div id="wpls--input-wrap">
<input type="text" id="wpls--input" placeholder="<?php echo esc_attr( $atts['placeholder'] );?>">
<div id="wpls--loading" class="wpls--loading"><div class="wpls--loader"></div></div>
</div>

<ul id="wp-search--post-list"></ul>
<ul id="wpls--post-list"></ul>

</div>

Expand Down
19 changes: 10 additions & 9 deletions public/includes/underscore-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@
* This function is pluggable
* @since 0.1
*/
if ( !function_exists( 'wp_search_backbone_templates' ) ):
if ( !function_exists( 'wpls_backbone_templates' ) ):

add_action('wp_footer', 'wp_search_backbone_templates');
function wp_search_backbone_templates(){
add_action('wp_footer', 'wpls_backbone_templates');
function wpls_backbone_templates(){

?>
<script type="text/html" id="wp-search--tmpl">
<li id="wp-search--item-<%= post.ID %>" class="wp-search--item">
<a href="<%= post.link %>" class="wp-search--link">
<!-- WP Live Search -->
<script type="text/html" id="wpls--tmpl">
<li id="wpls--item-<%= post.ID %>" class="wpls--item">
<a href="<%= post.link %>" class="wpls--link">
<% if ( post.featured_image ) { %>
<% if ( post.featured_image.attachment_meta ) { %>
<img class="wp-search--item-image" src="<%= post.featured_image.attachment_meta.sizes.thumbnail.url %>" alt="<% if ( post.featured_image.title ) { %><%=post.featured_image.title%><% } %> ">
<img class="wpls--item-image" src="<%= post.featured_image.attachment_meta.sizes.thumbnail.url %>" alt="<% if ( post.featured_image.title ) { %><%=post.featured_image.title%><% } %> ">
<% } else { %>
<img class="wp-search--item-image" src="<%= post.featured_image.source %>" alt="<% if ( post.featured_image.title ) { %><%=post.featured_image.title%><% } %> ">
<img class="wpls--item-image" src="<%= post.featured_image.source %>" alt="<% if ( post.featured_image.title ) { %><%=post.featured_image.title%><% } %> ">
<% } %>
<% } %>
<h4 class="wp-search--item-title"><%= post.title %></h4>
<h4 class="wpls--item-title"><%= post.title %></h4>
</a>
</li>
</script>
Expand Down
2 changes: 1 addition & 1 deletion uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Fired when the plugin is uninstalled.
*
* @package WP_Search
* @package WP_Live_Search
* @author Nick Haskins <email@nickhaskins.com>
* @license GPL-2.0+
* @link http://example.com
Expand Down
10 changes: 5 additions & 5 deletions wp-search.php → wp-live-search.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
*
* @package WP_Search
* @package WP_Live_Search
* @author Nick Haskins <email@nickhaskins.com>
* @license GPL-2.0+
* @link http://example.com
Expand All @@ -24,9 +24,9 @@
define('WP_SEARCH_DIR', plugin_dir_path( __FILE__ ));
define('WP_SEARCH_URL', plugins_url( '', __FILE__ ));

require_once( plugin_dir_path( __FILE__ ) . 'public/class-wp-search.php' );
require_once( plugin_dir_path( __FILE__ ) . 'public/class-wp-live-search.php' );

register_activation_hook( __FILE__, array( 'WP_Search', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'WP_Search', 'deactivate' ) );
register_activation_hook( __FILE__, array( 'WP_Live_Search', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'WP_Live_Search', 'deactivate' ) );

add_action( 'plugins_loaded', array( 'WP_Search', 'get_instance' ) );
add_action( 'plugins_loaded', array( 'WP_Live_Search', 'get_instance' ) );

0 comments on commit b91c4a2

Please sign in to comment.