Permalink
Browse files

First Push

Wordpress Theme
  • Loading branch information...
Roy Sivan Roy Sivan
Roy Sivan authored and Roy Sivan committed Apr 13, 2013
0 parents commit ce33d30985c47f44cbb58194af6fedddc1f10915
Showing with 297 additions and 0 deletions.
  1. BIN .DS_Store
  2. +7 −0 footer.php
  3. +21 −0 front-page.php
  4. +101 −0 functions.php
  5. +17 −0 header.php
  6. +33 −0 index.php
  7. BIN js/.DS_Store
  8. +48 −0 js/angular-app.js
  9. +9 −0 js/less-1.3.1.min.js
  10. +28 −0 js/modernizr-1.5.min.js
  11. 0 more-style.less
  12. +4 −0 page-json.php
  13. +7 −0 page.php
  14. +22 −0 style.css
BIN +6 KB .DS_Store
Binary file not shown.
@@ -0,0 +1,7 @@
<footer>
</footer>
<!-- WP FOOTER -->
<?php wp_footer(); ?>
</body>
</html>
@@ -0,0 +1,21 @@
<?php
get_header();
?>
<form ng-show="openItem" id="save" ng-submit="save()">
<input type="text" ng-model="openItem.post_title"/> <Br/>
<textarea ng-model="openItem.post_content" cols="100" rows="30"></textarea><Br/>
<input type="submit" value="SAVE" />
<button ng-click="clear()">CLEAR</button>
</form>
<p ng-repeat="person in items.people">
Post {{person.ID}} is titled {{person.post_title}}<br/>
<button ng-click="delete($index, person)">Delete</button>
<button ng-click="edit(person)">Edit</button>
</p>
<p>
<button ng-click="add()">add</button>
</p>
<?php
get_footer();
?>
@@ -0,0 +1,101 @@
<?php
/* THEME SUPPORT */
function add_awesome_theme_support(){
add_theme_support( 'post-thumbnails' );
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'after_setup_theme', 'add_awesome_theme_support' );
function enqueue_less_styles($tag, $handle) {
global $wp_styles;
$match_pattern = '/\.less$/U';
if ( preg_match( $match_pattern, $wp_styles->registered[$handle]->src ) ) {
$handle = $wp_styles->registered[$handle]->handle;
$media = $wp_styles->registered[$handle]->args;
$href = $wp_styles->registered[$handle]->src . '?ver=' . $wp_styles->registered[$handle]->ver;
$rel = isset($wp_styles->registered[$handle]->extra['alt']) && $wp_styles->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = isset($wp_styles->registered[$handle]->extra['title']) ? "title='" . esc_attr( $wp_styles->registered[$handle]->extra['title'] ) . "'" : '';
$tag = "<link rel='stylesheet' id='$handle' $title href='$href' type='text/less' media='$media' />";
}
return $tag;
}
add_filter( 'style_loader_tag', 'enqueue_less_styles', 5, 2);
function MyScripts() {
$query = new WP_Query();
$JSON = $query->get_posts();
//MODERNIZR
wp_register_script('modernizr', get_bloginfo('template_directory').'/js/modernizr-1.5.min.js', array('jquery'), null, false);
wp_enqueue_script('modernizr');
//LESS CSS
wp_register_script('less', get_bloginfo('template_directory').'/js/less-1.3.1.min.js', array('jquery'), null, false);
wp_enqueue_script('less');
// LESS CSS
wp_register_style('less-css', get_bloginfo('template_directory').'/more-style.less', false, '1.0', 'all');
wp_enqueue_style('less-css');
wp_register_style('less-css-css', get_bloginfo('template_directory').'/more-style.css', false, '1.0', 'all');
// INCLUDE WHEN READY: wp_enqueue_style('less-css-css');
//ANGULAR
wp_register_script('angular-core', 'http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js', array('jquery'), null, false);
wp_register_script('angular-app', get_bloginfo('template_directory').'/js/angular-app.js', array('angular-core'), null, false);
wp_enqueue_script('angular-core');
wp_enqueue_script('angular-app');
//LOCALIZE
wp_localize_script( 'angular-core', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
wp_localize_script( 'angular-core', 'PostData', array( 'data' => $JSON) );
}
add_action('wp_enqueue_scripts', 'MyScripts');
//NEW ITEM
add_action("wp_ajax_new_item", "TestFunc");
add_action("wp_ajax_nopriv_new_item", "TestFunc");
function TestFunc(){
$json = str_replace(array('[', ']', '\\'), '', $_GET['data']);
$data = json_decode($json, true);
$post_id = $data['ID'];
if($post_id){
$my_post = array();
$my_post['ID'] = $post_id;
$my_post['post_content'] = $data['post_content'];
$my_post['post_title'] = $data['post_title'];
wp_update_post( $my_post );
} else {
$NewPost = array(
'post_content' => $data['post_content'],
'post_title' => $data['post_title'],
'post_author' => 1,
'post_status' => 'publish',
'post_type' => 'post'
);
wp_insert_post($NewPost);
}
echo 'SUCCESS!';
}
//DELETE ITEM
add_action("wp_ajax_delete_item", "DeletePost");
add_action("wp_ajax_nopriv_delete_item", "DeletePost");
function DeletePost(){
$json = str_replace(array('[', ']', '\\'), '', $_GET['data']);
$data = json_decode($json, true);
$post_id = $data;
wp_delete_post($post_id);
echo 'SUCCESS!';
}
?>
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <?php language_attributes(); ?> ng-app="guava">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
<meta name="author" content="Ciplex">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/favicon.png">
<?php wp_head(); ?>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
</head>
<body <?php body_class(); ?> ng-controller="MainCtrl">
@@ -0,0 +1,33 @@
<?php
get_header();
?>
<form ng-show="openItem" id="save" ng-submit="save()">
<input type="text" ng-model="openItem.post_title"/> <Br/>
<textarea ng-model="openItem.post_content" cols="100" rows="30"></textarea><Br/>
<input type="submit" value="SAVE" />
<button ng-click="clear()">CLEAR</button>
</form>
<button ng-click="add()">add</button>
<p ng-repeat="person in items.people">
Post {{person.ID}} is titled {{person.post_title}}<br/>
<button ng-click="delete($index)">Delete</button>
<button ng-click="edit(person)">Edit</button>
</p>
<p ng-repeat="item in items">
{{item.action}} <br/>
<button ng-click="delete($index)">Delete</button>
<button ng-click="edit(people)">Edit</button>
</p>
<pre>
{{items.people|json}}
</pre>
<?php
get_footer();
?>
BIN +6 KB js/.DS_Store
Binary file not shown.
@@ -0,0 +1,48 @@
var app = angular.module('guava', []);
function MainCtrl($scope, $http) {
$scope.items = [];
$scope.items.people = PostData.data;
$scope.openItem = false;
$scope.data = {};
// SAVE POST FUNCTION
$scope.save = function(){
$http.post(MyAjax.ajaxurl, $scope.data, {
params: {
data: $scope.openItem,
action: 'new_item'
}
}).then(function(response){
console.log(response.data);
$scope.openItem = false;
});
}
// ADD NEW POST FUNCTION
$scope.add = function(){
$scope.items.people.push({'post_title' : 'New Post'});
}
// DELETE POST FUNCTION
$scope.delete = function(index, person){
$scope.items.people.splice(index,1);
confirm('Are you sure you want to delete '+person.post_title+' ?');
$http.post(MyAjax.ajaxurl, $scope.data, {
params: {
data: person.ID,
action: 'delete_item'
}
}).then(function(response){
console.log(response.data);
});
}
// EDIT POST (PUSH DATA TO FORM) FUNCTION
$scope.edit = function(person){
$scope.openItem=person;
}
// CLEAR FORM FUNCTION
$scope.clear = function(){
$scope.openItem = false;
}
}

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
No changes.
@@ -0,0 +1,4 @@
<?php
$array = BlogJson();
echo json_encode($array);
?>
@@ -0,0 +1,7 @@
<?php
get_header();
if(have_posts()) : while(have_posts()): the_post();
the_content();
endwhile; endif;
get_footer();
?>
@@ -0,0 +1,22 @@
/*
Theme Name: GuavaWorks Angular Theme
Theme URI: http://www.guavaworks.com
Description: Testing WP + Angular
Version: 2.0
Author: Guavaworks
Author URI: http://www.guavaworks.com
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/* HTML 5*/
header, article, footer, section, nav{
display:block;
}
.clear{
clear:both;
}
/******** ALL FURTHER STYLING SHOULD BE DONE IN THE more-style.less/css FILES *******/

0 comments on commit ce33d30

Please sign in to comment.