problem with using gutenberg blocks in wordpress customizer - php

to create a guteberg block in wordpress i created a plugin and i used this code to register the block :
add_action('init', [$this, 'myInit']); and then callback the myInit :
function myInit()
{
wp_enqueue_script('pluginsscriptwidgets', plugin_dir_url(__FILE__) . 'build/index.js', array('wp-blocks', 'wp-element', 'wp-editor', 'wp-dom-ready'));
register_block_type('widgetsplugin/info-top-header-widget', array(
'render_callback' => array($this, 'TopHeaderInfoWidget_HTML')
));
}
function TopHeaderInfoWidget_HTML($attributes)
{
return TopHeaderInfo_HTML($attributes);
}
and then i created TopHeaderInfo_HTML($attributes) in seperated file and i call the file using this code :
require_once plugin_dir_path(__FILE__) . 'inc/TopHeaderInfoWidget.php';
inside the file TopHeaderInfoWidget.php :
<?php
function TopHeaderInfo_HTML($data)
{
ob_start();
?>
<div class="col-lg-9 pd-right_zero">
<div class="topbar-left topbar-widgets text-left">
<div id="cargo-office-location-widget-2" class="widget cargo-office-location-widget">
<div class="office-location clearfix">
<div id="tab-1" class="tab-content">
<ul class="topbar-office ">
<li><i class="flaticon-telephone" aria-hidden="true"></i>Phone <?php echo $data['PhoneNumber'] ?></li>
<li><i class="flaticon-web" aria-hidden="true"></i><?php echo $data['EmailAdress'] ?></li>
<li><i class="flaticon-pin" aria-hidden="true"></i><?php echo $data['OfficeAdress'] ?></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
in the index.js i did this code :
import { TextControl, Flex, FlexBlock, BaseControl } from "#wordpress/components";
wp.blocks.registerBlockType("widgetsplugin/info-top-header-widget", {
title: "header info website ",
description: "plugin for widgets",
icon: "info-outline",
category: "common",
attributes: {
PhoneNumber: { type: "string" },
EmailAdress: { type: "string" },
OfficeAdress: { type: "string" }
},
edit: editHeaderInfos,
save: function () {
return null
}
})
function editHeaderInfos(props) {
return (
<div className="our-widgets-container">
<BaseControl label="Informations">
<Flex>
<FlexBlock>
<TextControl label="Phone:" placeholder="+212655667788" value={props.attributes.PhoneNumber} onChange={(value) => { props.setAttributes({ PhoneNumber: value }) }} required />
</FlexBlock>
<FlexBlock>
<TextControl label="Email:" placeholder="example#email.com" value={props.attributes.EmailAdress} onChange={(value) => { props.setAttributes({ EmailAdress: value }) }} required />
</FlexBlock>
<FlexBlock>
<TextControl label="Adress:" placeholder="rue 23 n 156, oulfa" value={props.attributes.OfficeAdress} onChange={(value) => { props.setAttributes({ OfficeAdress: value }) }} required />
</FlexBlock>
</Flex>
</BaseControl>
</div>
)
}
the block is working perfectly in my admin dashboard, i created this block essentially to use it as a widget, in the widgets areas everything is good working just fine no problems no bugs, but when i go the the website customizer and click widgets and try to edit the widget within the customizer i found this error :
Your site doesn’t include support for the "widgetsplugin/info-top-header-widget" block. You can leave this block intact or remove it entirely.

Related

How to use Codeigniter View in Semantic UI tab?

I used Semantic UI tabs components in one of my Codeigniter project. Here's the setup.
main_view.php
<div class="ui pointing secondary menu">
<a class="active item" data-tab="tab1">Tab 1</a>
<a class="item" data-tab="tab2">Tab 2</a>
<a class="item" data-tab="tab3">Tab 3</a>
</div>
<div class="ui container">
<div class="ui bottom attached active tab" data-tab="tab1"></div>
<div class="ui bottom attached tab" data-tab="tab2"></div>
<div class="ui bottom attached tab" data-tab="tab3"></div>
</div>
<script type="text/javascript">
$(function() {
$('.ui.menu > .item').tab({
context: 'parent',
auto: true,
history: true,
parseScripts: false,
ignoreFirstLoad: false,
cache: false,
path: baseURL
});
});
</script>
tab1.php / tab2.php / tab3.php
<div class="container">
<?= $data; ?>
</div>
Main_View.php(Controller)
public function index_get(){
$this->load->view('setting');
}
public function tab1_get(){
$data = 'tab 1';
$this->load->view('tab1', $data);
}
public function tab2_get(){
$data = 'tab 2';
$this->load->view('tab2', $data);
}
public function tab3_get(){
$data = 'tab 3';
$this->load->view('tab3', $data);
}
routes.php
$route['main'] = 'main_view';
$route['main/tab1'] = 'main_view/tab1';
$route['main/tab2'] = 'main_view/tab2';
$route['main/tab3'] = 'main_view/tab3';
Everything works fine with URLs like this
http://localhost/main#/tab1
http://localhost/main#/tab2
http://localhost/main#/tab3
But it just show me the tab content(without the tab bar) when I try to remove the hash in the URL. I also tried using historyType: 'state' in the tab js config but still broken. How can I prevent or redirect users to access the child pages only?

Can i use jQuery .load while still changing URL?

What i want to achieve
I want to be able to shift seamlessly through the different posts in the sidebar on this website, while having using a custom post template for my posts. And by seamlessly i mean that the screen doesn't go white for a second every time you navigate it.
My problem
single.php or single-{slug}.php does not work, since the URL doesn't change while navigating the sidebar
Plugins i am using
Custom Post Type UI
Ajax Content Renderer
jQuery script for my sidebar
$(document).ready(function() {
$("#sidebar li:has(a)").click(function() {
var page = $("a:first",this).attr("href");
$("#content").load(page);
return false;
});
});
HTML & PHP for sidebar and content area
<div class="row"> <!-- Main content row -->
<div class="col-md-4" id="sidebar">
<?php
if (is_page('gulvservice')){
wp_nav_menu(array('menu'=>'gulvservice' ));
} elseif (is_page('malerservice')) {
wp_nav_menu(array('menu'=>'malerservice' ));
} elseif (is_page('industrilakering')) {
wp_nav_menu(array('menu'=>'industrilakering' ));
}
?>
</div>
<div class="col-md-8" id="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="title"><h1>
<?php the_title(); ?>
</h1></div>
<div class="div">
<?php
if( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
</div>
<?php endwhile; endif; ?>
</div>
</div>
</div> <!-- Main Content -->
Need to prevent the event on the <a>. So it would be better to move the selector to those elements
Try:
$(document).ready(function() {
$("#sidebar li a").click(function() {
var page = $(this).attr("href");
$("#content").load(page);
return false;
});
});

How to use javascript and PHP to import data Fuel UX datagrid

Fuel UX is here:
http://exacttarget.github.com/fuelux/
Specifically i'm trying to use the Datagrid.
Here's an example:
http://code.exacttarget.com/code-examples/datagrid.html
I've attempted to recreated this:
https://raw.github.com/ExactTarget/fuelux/master/sample/data.js
And just output it through the PHP file. I was able to get PHP to correctly output the correct data and just dumped it into the main file so the data.js file is now output in the main PHP/HTML file with all my information in the header using these tags:
<script></script>
And used the sample markup from the GitHub website.
I can't seem to get it to work correctly, is there another way to import data from PHP to the datagrid? Should some of the code for the data.js be changed since it is now being output in the main php/html file?
Basically attempting to pull data from MySQL using PHP and then dump it into a data grid. I can't seem to find much documentation and I guess my real question would be what is the best way to import data from my php application into the Fuel UX Datagrid?
With php / mysql write to data.js, use sample/data.js as an example. (or rename your .php to data.js and parse as php (Parse js/css as a PHP file using htaccess)).
setting fuelux datagrid source from backbone collection gives the right direction.
Presume you got a data databases table with the fields: id, title and city and you want to show this in the datagrid.
Create php file which return json format from your mysql (example):
data.php:
<?
error_reporting(E_ALL);
ini_set('report_errors','on');
$mysqli = new mysqli('localhost', 'root', '*******', 'cities');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$data = array();
if ($result = $mysqli->query('SELECT `id`,`title`,`city` FROM `poi`'))
{
//$data['testdata'] = mysqli_fetch_all($result,MYSQLI_ASSOC);
while(($row=$result->fetch_assoc())){$data[]=$row;}
$result->close();
}
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($data);
exit;
create a static datasource testdatasource.js:
/*
* Fuel UX Data components - static data source
* https://github.com/ExactTarget/fuelux-data
*
* Copyright (c) 2012 ExactTarget
* Licensed under the MIT license.
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['underscore'], factory);
} else {
root.TestDataSource = factory();
}
}(this, function () {
var TestDataSource = function (options) {
this._formatter = options.formatter;
this._columns = options.columns;
this._delay = options.delay || 0;
};
TestDataSource.prototype = {
columns: function () {
return this._columns;
},
data: function (options, callback) {
var self = this;
setTimeout(function () {
var data;
$.ajax({
url: '/data.php',
dataType: 'json',
async: false,
success: function(result) {
data = result;
}
});
// SEARCHING
if (options.search) {
data = _.filter(data, function (item) {
var match = false;
_.each(item, function (prop) {
if (_.isString(prop) || _.isFinite(prop)) {
if (prop.toString().toLowerCase().indexOf(options.search.toLowerCase()) !== -1) match = true;
}
});
return match;
});
}
var count = data.length;
// SORTING
if (options.sortProperty) {
data = _.sortBy(data, options.sortProperty);
if (options.sortDirection === 'desc') data.reverse();
}
// PAGING
var startIndex = options.pageIndex * options.pageSize;
var endIndex = startIndex + options.pageSize;
var end = (endIndex > count) ? count : endIndex;
var pages = Math.ceil(count / options.pageSize);
var page = options.pageIndex + 1;
var start = startIndex + 1;
data = data.slice(startIndex, endIndex);
if (self._formatter) self._formatter(data);
callback({ data: data, start: start, end: end, count: count, pages: pages, page: page });
}, this._delay)
}
};
return TestDataSource;
}));
This builds a data set from data.php $.ajax({
url: '/data.php',
dataType: 'json',
async: false,
success: function(result) {
data = result;
}
});
In your html call your data set and create the columns:
var dataSource = new TestDataSource({
columns: [
{
property: 'id',
label: 'ID',
sortable: true
},
{
property: 'title',
label: 'Title',
sortable: true
},
{
property: 'city',
label: 'City',
sortable: true
}
],
delay: 250
});
Initialize the grid grid with this data source:
$('#MyGrid').datagrid({
dataSource: dataSource
});
Get the datagrid working:
download the source (zip) from and extract to /fuelux-master/
create /index.html
index.html:
<!DOCTYPE html>
<html lang="en" class="fuelux">
<head>
<meta charset="utf-8">
<title>Fuel UX 2</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./fuelux-master/dist/css/fuelux.css" rel="stylesheet">
<script src="./fuelux-master/lib/require.js"></script>
<style type="text/css">
body {
padding-bottom: 200px;
}
</style>
<script>
requirejs.config({
paths: {
'jquery': './fuelux-master/lib/jquery',
'underscore': 'http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min',
'bootstrap': './fuelux-master/lib/bootstrap/js',
'fuelux': './fuelux-master/src',
'sample': './fuelux-master/sample'
}
});
require(['jquery', 'sample/data', 'sample/datasource', 'sample/datasourceTree', 'fuelux/all'],
function ($, sampleData, StaticDataSource,datasourceTree) {
// DATAGRID
var dataSource = new StaticDataSource({
columns: [
{
property: 'toponymName',
label: 'Name',
sortable: true
},
{
property: 'countrycode',
label: 'Country',
sortable: true
},
{
property: 'population',
label: 'Population',
sortable: true
},
{
property: 'fcodeName',
label: 'Type',
sortable: true
}
],
data: sampleData.geonames,
delay: 250
});
$('#MyGrid').datagrid({
dataSource: dataSource
});
});
</script>
</head>
<body>
<div class="container">
<!-- DATAGRID -->
<table id="MyGrid" class="table table-bordered datagrid">
<thead>
<tr>
<th>
<span class="datagrid-header-title">Geographic Data Sample</span>
<div class="datagrid-header-left">
<div class="input-append search datagrid-search">
<input type="text" class="input-medium" placeholder="Search">
<button class="btn"><i class="icon-search"></i></button>
</div>
</div>
<div class="datagrid-header-right">
<div class="select filter" data-resize="auto">
<button data-toggle="dropdown" class="btn dropdown-toggle">
<span class="dropdown-label"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li data-value="all" data-selected="true">All</li>
<li data-value="lt5m">Population < 5M</li>
<li data-value="gte5m">Population >= 5M</li>
</ul>
</div>
</div>
</th>
</tr>
</thead>
<tfoot>
<tr>
<th>
<div class="datagrid-footer-left" style="display:none;">
<div class="grid-controls">
<span>
<span class="grid-start"></span> -
<span class="grid-end"></span> of
<span class="grid-count"></span>
</span>
<div class="select grid-pagesize" data-resize="auto">
<button data-toggle="dropdown" class="btn dropdown-toggle">
<span class="dropdown-label"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li data-value="5" data-selected="true">5</li>
<li data-value="10">10</li>
<li data-value="20">20</li>
<li data-value="50">50</li>
<li data-value="100">100</li>
</ul>
</div>
<span>Per Page</span>
</div>
</div>
<div class="datagrid-footer-right" style="display:none;">
<div class="grid-pager">
<button type="button" class="btn grid-prevpage"><i class="icon-chevron-left"></i></button>
<span>Page</span>
<div class="input-append dropdown combobox">
<input class="span1" type="text">
<button class="btn" data-toggle="dropdown"><i class="caret"></i></button>
<ul class="dropdown-menu"></ul>
</div>
<span>of <span class="grid-pages"></span></span>
<button type="button" class="btn grid-nextpage"><i class="icon-chevron-right"></i></button>
</div>
</div>
</th>
</tr>
</tfoot>
</table>
</div>
</body>
</html>
see ./fuelux-master/ in the paths of the requirejs config. Also see the initializations of var dataSource to define your columns. At least you needto write the full html of the table with id="MyGrid".
Some refactoring and use of CDNs example: http://plnkr.co/hZRjry5vG8ZcOG4VbjNq
use bootstrap and jQuery via CDN with requirejs, see Loading Bootstrap from CDN with Require.js
replace the include of all.js with datagrid.js (note the datagrid won't work without select.js and util.js is required for select.js)
remove sample/datasourceTree cause we don't need it

Big task - problems with page refresh and ajax

I have a navigation which load dynamically content via ajax. But if I refresh the page or visit another url and go back the current content is away and I see the old content under the first menu tab.
Now I have to solve this problem.
The index.php include the elements header_registrated.inc.php, navigation.inc.php and main_container.inc.php
index.php:
<?php include("inc/incfiles/header_registrated.inc.php"); ?>
<?php
if (!isset($_SESSION["userLogin"])) {
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/project\">";
}
else {
echo "";
}
?>
<?php include("inc/incfiles/navigation.inc.php"); ?>
<?php include("inc/incfiles/main_container.inc.php"); ?>
<?php include("inc/incfiles/footer.inc.php"); ?>
header_registrated.inc.php:
<?php
include ("inc/scripts/mysql_connect.inc.php");
session_start();
$user = $_SESSION["userLogin"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>title</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="js/framework/jquery.js"></script>
<script language="JavaScript" src="js/dropdown/window.js"></script>
<script language="JavaScript" src="js/navigation/navigation.js"></script>
</head>
<body>
</body>
navigation.inc.php:
<div class="navigation">
<ul>
<li id="1">
<div id="menuImage1" class="menuImage"></div>
<div class="menuText"><p>Punkt 1</p></div>
<div class="navigationDart"></div>
</li>
<li id="2">
<div id="menuImage2" class="menuImage"></div>
<div class="menuText"><p>Punkt 2</p></div>
</li>
<li id="3">
<div id="menuImage3" class="menuImage"></div>
<div class="menuText"><p>Punkt 3</p></div>
</li>
<li id="4">
<div id="menuImage4" class="menuImage"></div>
<div class="menuText"><p>Punkt 4</p></div>
</li>
<li id="5">
<div id="menuImage5" class="menuImage"></div>
<div class="menuText"><p>Punkt 5</p></div>
</li>
<li id="6">
<div id="menuImage6" class="menuImage"></div>
<div class="menuText"><p>Punkt 6</p></div>
</li>
</ul>
</div>
main_container.inc.php:
<div class="mainContainer">
<div class="containerHeader">
<div class="contentHeader">
</div>
</div>
<div class="contentContainer">
<div class="content">
</div>
<div class="advertisement">
</div>
</div>
</div>
Now the divs content, cnotentHeader and advertisement (in file main_content.inc.php) is filled via ajax. Also the navigation has some jquery effects which also have to be the same after page refresh.
navigation.js:
$(document).ready(function() {
$.get('inc/incfiles/content_container/header/1.php', function(data) {
$('.contentHeader').html(data);
});
$.get('inc/incfiles/content_container/content/1.php', function(data) {
$('.content').html(data);
});
$.get('inc/incfiles/content_container/advertisement/1.php', function(data) {
$('.advertisement').html(data);
});
var current = '1.php';
$(".navigation li").click(function() {
var quelle = $(this).attr('id') + ".php";
// the current content doesn't load again
if(current === quelle) {
return;
}
current = quelle;
// content
$(".content").fadeOut(function() {
$(this).load("inc/incfiles/content_container/content/" + quelle).fadeIn('normal');
})
// advertisement
$(".advertisement").fadeOut(function() {
$(this).load("inc/incfiles/content_container/advertisement/" + quelle).fadeIn('normal');
})
// header
$(".contentHeader").fadeOut(function() {
$(this).load("inc/incfiles/content_container/header/" + quelle).fadeIn('normal');
})
});
$(".navigation li").click(function() {
$(".menuImage").removeClass("menuImageActive1");
$(".menuImage").removeClass("menuImageActive2");
$(".menuImage").removeClass("menuImageActive3");
$(".menuImage").removeClass("menuImageActive4");
$(".menuImage").removeClass("menuImageActive5");
$(".menuImage").removeClass("menuImageActive6");
});
$("#1").mousedown(function() {
$("#menuImage1").addClass("menuImageClick1"); // new class on mouse button press
});
$("#1").mouseup(function() {
$("#menuImage1").removeClass("menuImageClick1"); //remove class after mouse button release
});
$("#1").click(function() {
$("#menuImage1").addClass("menuImageActive1");
});
$("#2").mousedown(function() {
$("#menuImage2").addClass("menuImageClick2"); // new class on mouse button press
});
$("#2").mouseup(function() {
$("#menuImage2").removeClass("menuImageClick2"); //remove class after mouse button release
});
$("#2").click(function() {
$("#menuImage2").addClass("menuImageActive2");
});
$("#3").mousedown(function() {
$("#menuImage3").addClass("menuImageClick3"); // new class on mouse button press
});
$("#3").mouseup(function() {
$("#menuImage3").removeClass("menuImageClick3"); //remove class after mouse button release
});
$("#3").click(function() {
$("#menuImage3").addClass("menuImageActive3");
});
$("#4").mousedown(function() {
$("#menuImage4").addClass("menuImageClick4"); // new class on mouse button press
});
$("#4").mouseup(function() {
$("#menuImage4").removeClass("menuImageClick4"); //remove class after mouse button release
});
$("#4").click(function() {
$("#menuImage4").addClass("menuImageActive4");
});
$("#5").mousedown(function() {
$("#menuImage5").addClass("menuImageClick5"); // new class on mouse button press
});
$("#5").mouseup(function() {
$("#menuImage5").removeClass("menuImageClick5"); //remove class after mouse button release
});
$("#5").click(function() {
$("#menuImage5").addClass("menuImageActive5");
});
$("#6").mousedown(function() {
$("#menuImage6").addClass("menuImageClick6"); // new class on mouse button press
});
$("#6").mouseup(function() {
$("#menuImage6").removeClass("menuImageClick6"); //remove class after mouse button release
});
$("#6").click(function() {
$("#menuImage6").addClass("menuImageActive6");
});
$("#1").click(function(){
$(".navigationDart").animate({
top: "16px"
}, 500 );
});
$("#2").click(function(){
$(".navigationDart").animate({
top: "88px"
}, 500 );
});
$("#3").click(function(){
$(".navigationDart").animate({
top: "160px"
}, 500 );
});
$("#4").click(function(){
$(".navigationDart").animate({
top: "232px"
}, 500 );
});
$("#5").click(function(){
$(".navigationDart").animate({
top: "304px"
}, 500 );
});
$("#6").click(function(){
$(".navigationDart").animate({
top: "376px"
}, 500 );
});
});
My idea was it to work with if(isset($_SESSION['ajaxresponse'])) but I don't no how to do this.
Please help me. I have the feeling that I've searched the whole web to find an answer.
I recomend using a library that ties PHP to jQuery through AJAX and can ease your problems a lot. the library is phery http://phery-php-ajax.net
just some optimization for your navigation.js file:
You'll need to centralize (or not) the AJAX in one file, to make it easier.
It can go on the top of your index.php
function load($data){
$r = new PheryResponse;
if (!isset($_SESSION["userLogin"])) {
return $r->redirect('http://localhost/project');
}
$path = 'inc/incfiles/content_container/';
if (isset($data['id'])){
$id = $data['id']. '.php';
} else {
if (!empty($_SESSION['id'])){
$id = $_SESSION['id'];
} else {
$id = '1.php';
}
}
$_SESSION['id'] = $id; // save the current ID and will load next time the person refreshes the page
ob_start();
include $path.'content/'.$id;
$content = ob_get_clean();
ob_start();
include $path.'advertisement/'.$id;
$ads = ob_get_clean();
ob_start();
include $path.'header/'.$id;
$header = ob_get_clean();
$r
->jquery('.advertisement')->html($ads)
->jquery('.contentHeader')->html($header)
->jquery('.content')->html($content)
;
// etc
return $r->this()->find('.menuImage')->addClass('menuImageActive'); // set the current menuImage of the LI element to menuImageActive
}
session_start();
Phery::instance()->set(array(
'load' => 'load'
))->process();
Since your JS it non-performant right now, I've redone it:
$(function() {
phery.remote('load');
var menu_image = $(".menuImage");
$(document)
.on('click', '.navigation li', function(event){
menu_image.removeClass("menuImageActive");
var top;
switch (event.currentTarget.id){
case '1':
top = "16px";
break;
case '2':
top = "88px";
break;
case '3':
top = "160px";
break;
case '4':
top = "232px";
break;
case '5':
top = "304px";
break;
case '6':
top = "376px";
break;
}
$(event.currentTarget)
.find(".navigationDart").animate({ top: top }, 500);
})
.on('mousedown', '.navigation li', function(event){
$(event.currentTarget).addClass('menuImageClick');
})
.on('mouseup', '.navigation li', function(event){
$(event.currentTarget).removeClass('menuImageClick');
});
});
and your navigation.inc.php will have to be:
<div class="navigation">
<ul>
<li id="1" data-remote="load" data-args="{'id':1}">
<div id="menuImage1" class="menuImage"></div>
<div class="menuText"><p>Punkt 1</p></div>
<div class="navigationDart"></div>
</li>
<li id="2" data-remote="load" data-args="{'id':2}">
<div id="menuImage2" class="menuImage"></div>
<div class="menuText"><p>Punkt 2</p></div>
</li>
<li id="3" data-remote="load" data-args="{'id':3}">
<div id="menuImage3" class="menuImage"></div>
<div class="menuText"><p>Punkt 3</p></div>
</li>
<li id="4" data-remote="load" data-args="{'id':4}">
<div id="menuImage4" class="menuImage"></div>
<div class="menuText"><p>Punkt 4</p></div>
</li>
<li id="5" data-remote="load" data-args="{'id':5}">
<div id="menuImage5" class="menuImage"></div>
<div class="menuText"><p>Punkt 5</p></div>
</li>
<li id="6" data-remote="load" data-args="{'id':6}">
<div id="menuImage6" class="menuImage"></div>
<div class="menuText"><p>Punkt 6</p></div>
</li>
</ul>
</div>
it seems your CSS is convoluted for the simplicity of your HTML. And you shouldn't be using a number for an ID, IDs needs to be You should be reusing css classes in this case, like
.menuImageActive {
/* common styles */
}
.menuImageClick {
/* common styles */
}
/* apply per ID */
#menuImage1.menuImageActive {
}
#menuImage1.menuImageClick {
}
#menuImage2.menuImageActive {
}
#menuImage2.menuImageClick {
}
#menuImage3.menuImageActive {
}
#menuImage3.menuImageClick {
}
#menuImage4.menuImageActive {
}
#menuImage4.menuImageClick {
}
#menuImage5.menuImageActive {
}
#menuImage5.menuImageClick {
}
#menuImage6.menuImageActive {
}
#menuImage6.menuImageClick {
}
Try out jQuery UI tabs if you need dynamically loaded tabs, it has built in AJAX support.
If you want back/forward support for AJAX events try out the jQuery address plugin.
There is a good answer on how to use jQuery UI tabs with back/forward history here:

post in jquery do not update element

EDIT WITH NEW JAVASCRIPT
I am trying to make a "I like this" kinda function but I have a small problem.
I am using this small javascript
function coolIt(designid) {
$.post('cool.php', {designid:designid}, function(data) {
//alert(data);
$('#cool_'+designid).text(data);
});
}
And this HTML where the "Like" button is
<span class="like"><span id="cool_'.$row["id"].'">('. $row["cools"] .')</span></span>
The cool.php runs through this:
function UpdateCool($design_id) {
$fields_up = array("cools" => 'cools + 1');
$fields_down = array("cools" => 'cools - 1');
$sql = SQLHandling::updateSQL('tdic_designs', 'id = '. $design_id .'', $fields_up);
SQLHandling::SQLquery($sql);
}
and that works perfectly. It updates the cools field with one increasing value.
When I run alert(data) on the javascript it returns nothing and the #cool_1 span element disappears.
Any idea what I might do wrong?
HTML OUTPUT:
<script type="text/javascript">
function coolIt(designid) {
$.post('cool.php', {designid:designid}, function(data) {
alert(data);
$('#cool_'+designid).text(data);
});
}
</script>
</head>
<body>
<div id="allContainer">
<div id="topArea">
<div id="topNaviArea">
<ul id="navi">
<li class="home">Home</li>
<li class="categories">Categories</li>
<li class="about">About</li>
<li class="faq">FAQ</li>
<li class="submit">Submit</li>
<li class="contact">Contact</li>
</ul>
</div>
</div>
<div id="contentBox">
<div id="login">Login // Register</div> <div id="mainContent">
<h1>// Home // Categories // HTML / CSS</h1>
<div id="catMenu">
<ul>
<li>3D</li><li>Graphic</li><li>HTML / CSS</li><li>Paintings</li><li>Photography</li><li>Portals</li><li>Webshops</li>
</ul>
<h2>1 designs<br />in this category</h2>
</div>
<div id="rightContentBox">
<ul id="displays">
<li class="displayWindow"><div class="dpwImage"><figure><img src="/testen/designs/thatdesigniscool.jpg" width="280" height="175" alt="That Design Is Cool" target="_blank"></figure></div><div class="dpwBox"><div class="dpwLeft"><span class="title">That Design Is Cool</span><span class="comments">Comments (1)</span></div><div class="dpwRight"><span class="like"><span id="cool_1">(29)</span></span></div></div> </li>
</ul>
</div>
</div>
</div>
</div>
I guess you are replacing the whole contents of div with just the server response. Why don't you append?
$('.likeIt').livequery("click",function(e){
var designid = $(this).attr('id').replace('design_id-','');
$.post('cool.php?design_id='+designid, {}, function(response){
$('#cool_'+designid).html($('#cool_'+designid).html() + response); // See if this works!
});
});
See if this helps! :)
I got it solved by editing cool.php to the following:
<?php
session_start();
ini_set("display_errors", 1);
define("INCLUDE_DIR", "includes/classes");
/* Autoload classes when used */
function __autoload($class_name) { include(INCLUDE_DIR.'/class.'. strtolower($class_name) . '.php'); }
SQLHandling::SQLconnect();
if($_POST["designid"] != '') {
$alreadyExist = mysql_num_rows(mysql_query('SELECT id FROM tdic_voted WHERE designid="'.(int)$_POST['designid'].'" AND ip="'.$_SERVER['REMOTE_ADDR'].'"'));
if($alreadyExist == 0) {
mysql_query(' UPDATE tdic_designs SET cools = cools+1 WHERE id="'.(int)$_POST['designid'].'"');
$num = mysql_fetch_row(mysql_query(' SELECT cools FROM tdic_designs WHERE id="'.(int)$_POST['designid'].'" LIMIT 1'));
echo $num[0];
mysql_query(' INSERT INTO tdic_voted (designid, ip) VALUES ("'.(int)$_POST['designid'].'","'.$_SERVER['REMOTE_ADDR'].'")');
} else{
echo 'You already think this is a cool design!';
}
}
?>

Categories