wmaraci reklam
lidertakipci

Javascript takıldığım nokta. [YARDIM LÜTFEN]

3 Mesajlar 1.180 Okunma
advertseo
wmaraci reklam

Secret35 Secret35 WM Aracı Kullanıcı
  • Üyelik 22.12.2012
  • Yaş/Cinsiyet 31 / E
  • Meslek Serbest
  • Konum İzmir
  • Ad Soyad B** O**
  • Mesajlar 142
  • Beğeniler 29 / 11
  • Ticaret 14, (%100)
Merhaba arkadaşlar,,

Sitem için Mobil tema kurdum (Wordpress WP App Touch eklentisi ile). Tema index kısmı javascript ile yazılmış. Şöyle kodları vereyim.

Plugin getsingle.php kodları:

require( $_SERVER['DOCUMENT_ROOT'].'/wp-load.php' ); // TESTING PAGE DIRECTLY

//$post_id = intval($_GET['id']);
$post_id = $_GET['id'];

//If is not numeric get the id from url
if (!is_numeric($post_id)) {
$post_id = url_to_postid( $post_id );
}

$post = get_post($post_id);
// $the_post = get_page($my_id); // Get page content

// get Next & previous post ID
$prev_post = get_previous_post(true);
$next_post = get_next_post(true); // get_next_post( $in_same_cat, $excluded_categories ) //true or false - excluded empty
//END get Next & previous post ID

$posts = array();

$posts[] = array(
'category' => post_cat(get_the_category($post->ID)),
'id' => $post->ID,
'title' => $post->post_title,
//'excerpt' => wpautop($the_post->post_excerpt),
'content' => y_video(wpautop($post->post_content)),
'fimg' => featured_img($post->ID),
'permalink' => $tposthe_post->guid,
'date' => str_replace("-", "/", substr($post->post_date, 0, 11)),
'author_id' => $post->post_author,
'author' => get_userdata($post->post_author)->display_name,
'medias' => get_medias($post->post_content,$post->ID),
'nbcomments' => get_comments_number($post->ID),
'prev_post' => $prev_post->ID,
'next_post' => $next_post->ID
//'next_post' => the_next_post($the_post->ID)
//'next_post' => get_adjacent_post(false,'',false) //False = in category, empty no exclude, False = next or true = previous
);

echo(json_encode(array('posts' => $posts)));
//echo $_GET['jsoncallback'].'('.json_encode(array('posts' => $posts)).')';

function featured_img($id){

$thumb = get_post_meta($id,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];

if($thumb){
$fimg = '';
return $fimg;
}
}

function get_medias($content,$postID) {

$audio_att = media_attachments('audio',$postID); // check if audio attachments
$video_att = media_attachments('video',$postID); // check if video attachments

// Check if audio in post, attachment, audio link ect...
if($audio_att){
$medias = '';
}else{
if (preg_match('!(http(s)?:\/\/[^"].*?\.(mp3|aiff|m4a|wav|aac|3gp|ogg))!Ui', $content, $match)) { // Audio
$media = $match[0];
$medias = '';
}
}

// Check if audio in post, attachment, audio link ect...
$poster = 'http://www.podzic.com/wp-content/uploads/2011/12/musicpic.jpg'; // Poster temporaire
if($video_att){
$medias = '';
}else{
if (preg_match('!(http(s)?:\/\/[^"].*?\.(mp4|mov|mpeg|webm|m4a|m4v))!Ui', $content, $match)) { // Video
$mediav = $match[0];
$medias = '';
}
}

preg_match('#(\.be/|/embed/|/v/|/watch\?v=)([A-Za-z0-9_-]{5,11})#', $content, $matches); // Youtube video
if(isset($matches[2]) && $matches[2] != ''){
$y_id = $matches[2];
$medias = '
';
}

return $medias;
}

function media_attachments($type,$postID)
{
$args = array(
'numberposts' => 1,
'order'=> 'ASC',
'orderby' => 'ID',
//'mime_type' => 'audio/mpeg',
'post_mime_type' => $type,
'post_parent' => $postID,
'post_status' => null,
'post_type' => 'attachment'
);

$attachments = get_children( $args );

//print_r($attachments);

if ($attachments) {
foreach( $attachments as $file ) {
$attachmenturl=wp_get_attachment_url($file->ID);
return $attachmenturl;
}
} else {
$attachmenturl = '';
return $attachmenturl;
}

}

function post_cat($category)
{
$firstCategory = $category[0]->cat_name;

if ($firstCategory) {
return $firstCategory;
} else {
return $attachmenturl;
}

}

function y_video($text)
{
$text = bracket($text);

if (preg_match('#(<(object)(.+?))#is',$text,$found)) {
$embedcode = $found[1];
}

if (preg_match('#]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?#s', $text, $matches)) {
$yb_id = $matches[1];
$iframe = '
';
$text = str_replace($embedcode, $iframe, $text);
return $text;
} else {
return $text;
}

}

function bracket($text) {
$text = preg_replace('#(\[(.+?)\])#is','',$text);
return $text;
}
?>


ve tema klasöründe index.php kodları:

$plugin_url = get_bloginfo('wpurl') . '/wp-content/plugins/wpapptouch';
$template_url = get_bloginfo("template_url");
?>












<?php echo get_bloginfo( 'name' ) ?>








<script>/src/add2home.js" charset="utf-8"></script>

<script>/src/iscroll.min.js"></script>
<script>/src/zepto.min.0.8.js'></script>
<script>/src/jqtouch.min.js'></script>

<script>/src/jqt.autotitles.min.js'></script>

<script>/src/videoresize.js'></script>

<script>
var INDEX_URL = '/'; // Main url
var PLUGIN_URL = '/'; // Main url
var BLOG_TITLE = '';
var BLOG_DESC = '';


var myScroll;
function loaded() {
myScroll = new iScroll('wrapper');
}
//window.addEventListener('load', loaded, false);

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
document.addEventListener('DOMContentLoaded', setTimeout(function () { loaded(); }, 1000), false);

//document.addEventListener('DOMContentLoaded', setTimeout(function () { myScroll.refresh(); }, 500), false);
//Faster scrolling
var raw=iScroll.prototype._momentum;
iScroll.prototype._momentum= function (dist, time, maxDistUpper, maxDistLower, size){
var ret=raw.apply(this,[
dist,
time*1,
maxDistUpper,
maxDistLower,
size
]);
return ret;
};
</script>


<script>
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.match(/iPod/i))||(navigator.userAgent.match(/iPad/i))){
var jQT = new $.jQTouch({
//cacheGetRequests: false,
icon: '/img/iPhoneIcon_Medium.png',
icon4: '/img/iPhoneIcon_Big.png',
addGlossToIcon: false,
startupScreen: '/img/istartup.png',
//statusBar: 'black-translucent',
themeSelectionSelector: '#jqt #themes ul',
useFastTouch: true,
statusBar: 'default',
preloadImages: [
'/img/loading.gif',
'/img/iPhoneIcon_Medium.png',
'/img/pinstripes2.gif',
'/img/UIBack.png',
'/img/UIBackPressed.png',
]
});
//alert('is iPhone');
} else {
var jQT = new $.jQTouch({
//statusBar: 'black-translucent',
themeSelectionSelector: '#jqt #themes ul',
useFastTouch: false,
statusBar: 'default',
preloadImages: [
'/img/loading.gif',
'/img/iPhoneIcon_Medium.png',
'/img/pinstripes2.gif',
'/img/UIBack.png',
'/img/UIBackPressed.png',
]
});
//alert('is not iPhone');
}

sid = 0;
s = 0;

// Some sample Javascript functions:
$(function() {

// Home view
$('#home').bind('pageAnimationEnd', function(e, info) {

if (info.direction == 'in'){

if (myScroll) {
myScroll.destroy();
myScroll = null;
}

if ($('div#' + e.target.id + ' #wrapper').get(0)) {
setTimeout(function() {
myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
}, 0);
}

$("#single .toolbar H1").empty(); // empty single H1 title for autotitle
$("#singleappend").empty();

}

}); //pageAnimationEnd



// Page animations end with AJAX callback event, example 1 (load remote HTML only first time)
$('#single').bind('pageAnimationEnd', function(e, info) {

if (info.direction == 'in'){
//alert('in do json')
var wp_url = PLUGIN_URL + 'get_single.php';

showLoading();
//alert('show loading')
//$("#singleappend").empty().html('
Loading
');

$.getJSON(wp_url + '?id=' + sid, function(data) {

$.each(data.posts, function(i, post) {

if (post.title !== undefined) {

var post_html = '
    ';
    post_html += '
  • ';
    post_html += ' ' + post.category + '';
    //post_html += '' + post.date + '';
    post_html += '


    ';
    //post_html += '

    ' + post.title + '

    ';
    if (post.fimg) post_html += post.fimg ;


    post_html += '
';

$('#singleappend').html(post_html);

if (myScroll) {
myScroll.destroy();
myScroll = null;
}

if ($('div#' + e.target.id + ' #wrapper').get(0)) {
setTimeout(function() {
myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
//alert('New iscroll');
}, 0);
}

getid();

nextprev(post.prev_post, post.next_post, post.category);


if (e.target.nodeName.toLowerCase() != "video") {
e.preventDefault();
e.stopPropagation();
}

} // if post.title !== undefined

videosize();

}); //each


setTimeout(function () {myScroll.refresh();}, 2000);
hideLoading();
target_blank();

}); //getjson
} //if direction in

}); //pageAnimationEnd

// Categories List
$('#categories').bind('pageAnimationEnd', function(e, info) {

if ((info.direction == 'in') && ($('ul#catappend').html())) {

var sid = '';
//alert('empty sid = '+sid);
$("#postcat").empty();
$("#showposts .toolbar H1").empty();
$("#showposts .toolbar .back").html('Section');
s = 0;
//alert('not loading')

if (myScroll) {
myScroll.destroy('div#' + e.target.id + ' #wrapper');
myScroll = null;
}

if ($('div#' + e.target.id + ' #wrapper').get(0)) {
setTimeout(function() {
myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
}, 0);
}

}

if ((info.direction == 'in') && ($('ul#catappend').is(':empty'))) { //if empty load ajax
$("#showposts .toolbar H1").empty();
$("#showposts .toolbar .back").html('Section');
//$("#catappend").empty();
//alert('first load')
var wp_url = PLUGIN_URL + 'get_category.php';

showLoading();

$.getJSON(wp_url + '?', function(data) {


if (myScroll) {
myScroll.destroy();
myScroll = null;
}

if ($('div#' + e.target.id + ' #wrapper').get(0)) {
setTimeout(function() {
myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
//alert('New iscroll');
}, 0);
}


$.each(data.categories, function(i, categories) {

if (categories.cat_name !== undefined) {

var post_html = '
  • ';
    post_html += categories.cat_name + '
  • ';
    $('#catappend').append(post_html);



    } // if post.title !== undefined

    }); //each
    hideLoading();
    }); //getjson

    } //direction in end
    }); //pageAnimationEnd


    // Post List
    $('#showposts').bind('pageAnimationEnd', function(e, info) {

    if ((info.direction == 'in') && ($('ul#postcat').html())) { //if not empty don't load ajax
    $("#single .toolbar H1").empty(); // empty single H1 title for autotitle
    $("#singleappend").empty();

    if (myScroll) {
    myScroll.destroy();
    myScroll = null;
    }

    if ($('div#' + e.target.id + ' #wrapper').get(0)) {
    setTimeout(function() {
    myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
    }, 0);
    }

    }

    if ((info.direction == 'in') && ($('ul#postcat').is(':empty'))) { //if empty load ajax
    $("#single .toolbar H1").empty(); // empty single H1 title for autotitle
    $("#singleappend").empty();
    //alert('is empty')

    var wp_url = PLUGIN_URL + 'get_post.php';

    //alert('New sid = '+sid);
    showLoading();
    //alert(s);
    //var sid = $(this).attr('id');

    $.getJSON(wp_url + '?s='+s+'&id=' + sid, function(data) {
    //$.getJSON(wp_url + '?id=' + sid, function(data) {
    //alert('getjson');

    if (myScroll) {
    myScroll.destroy();
    myScroll = null;
    }

    if ($('div#' + e.target.id + ' #wrapper').get(0)) {
    setTimeout(function() {
    myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
    }, 0);
    }


    $.each(data.posts, function(i, post) {

    if (post.title !== undefined) {

    var post_html = '
  • ';
    post_html += post.get_thumb;
    post_html += '

    ' + post.title + '

    ';
    post_html += '

    ' + post.excerpt + '

  • ';

    $('#postcat').append(post_html);

    } // if post.title !== undefined

    }); //each
    hideLoading();
    //alert('hideloading');
    }); //getjson

    } //direction in end

    }); //pageAnimationEnd


    // Post List
    $('#pages').bind('pageAnimationEnd', function(e, info) {

    if ((info.direction == 'in') && ($('ul#pages_append').html())) { //if not empty don't load ajax

    $("#single .toolbar H1").empty(); // empty single H1 title for autotitle
    $("#singleappend").empty();

    if (myScroll) {
    myScroll.destroy();
    myScroll = null;
    }

    if ($('div#' + e.target.id + ' #wrapper').get(0)) {
    setTimeout(function() {
    myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
    }, 0);
    }

    }

    if ((info.direction == 'in') && ($('ul#pages_append').is(':empty'))) { //if empty load ajax
    $("#single .toolbar H1").empty(); // empty single H1 title for autotitle
    $("#singleappend").empty();

    var wp_url = PLUGIN_URL + 'get_post.php';

    //alert('New sid = '+sid);
    showLoading();
    //alert(s);
    //var sid = $(this).attr('id');

    $.getJSON(wp_url + '?id=' + sid, function(data) {
    //$.getJSON(wp_url + '?id=' + sid, function(data) {
    //alert('getjson');

    if (myScroll) {
    myScroll.destroy();
    myScroll = null;
    }

    if ($('div#' + e.target.id + ' #wrapper').get(0)) {
    setTimeout(function() {
    myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
    }, 0);
    }


    $.each(data.posts, function(i, post) {

    if (post.title !== undefined) {

    var post_html = '
  • ';
    post_html += post.get_thumb;
    post_html += '

    ' + post.title + '

    ';
    post_html += '

    ' + post.excerpt + '

  • ';

    $('#pages_append').append(post_html);

    } // if post.title !== undefined

    }); //each
    hideLoading();
    //alert('hideloading');
    }); //getjson

    } //direction in end

    }); //pageAnimationEnd


    $('#search').bind('pageAnimationEnd', function(e, info) {

    if (info.direction == 'in'){

    if (myScroll) {
    myScroll.destroy();
    myScroll = null;
    }

    if ($('div#' + e.target.id + ' #wrapper').get(0)) {
    setTimeout(function() {
    myScroll = new iScroll($('div#' + e.target.id + ' #wrapper').get(0));
    }, 0);
    }

    $("#showposts .toolbar H1").empty(); // marche pas parce que pas encole loader, peut etre if direction out
    $("#postcat").empty();

    }

    }); //pageAnimationEnd

    }); //end function()
    </script>

    <script>
    // Home
    $(document).ready(function() {

    $('.scroll').wrap('
    ').attr('id', 'scroller');

    // if text input field value is not empty show the "X" button
    $("#searchid").keyup(function() {
    $("#x").show();
    //if ($.trim($("#search").val()) == "") {
    if ($("#searchid").val() == "") {
    $("#x").hide();
    }
    });
    // on click of "X", delete input field value and hide "X"
    $("#x").bind(clickEventType, function() {
    $("#searchid").focus().val("");
    $(this).hide();
    }); //X BUTTON END

    var wp_url = PLUGIN_URL + 'get_post.php';

    showLoading();

    $.getJSON(wp_url + '?', function(data) {

    $.each(data.posts, function(i, post) {

    if (post.title !== undefined) {

    var post_html = '
  • ';
    //post_html += '
    ' + post.date + '
    ';
    post_html += post.get_thumb;
    post_html += '

    ' + post.title + '

    ';
    //post_html += '

    ' + post.excerpt + '

  • ';

    // Append html string to container div
    $('#allpost').append(post_html);
    //if ( i == 5 ) return false;
    }
    });

    hideLoading();
    setTimeout(function () { myScroll.refresh(); }, 100);

    });

    }); // end document ready

    </script>













    <script>document.write(BLOG_TITLE);</script>























      Sections


































          <script>
          //Show search
          var visible = false;
          function moveDown() {

          var height = $(".searchbox").height();
          $(".searchbox").css('-webkit-transform', 'translate3d(0px,+46px,0)');
          //$(".searchbox").show().css('-webkit-transform', 'translate3d(0px,+46px,0)');
          //$('#element').css('z-index');

          }
          function moveUp() {
          var height = $(".searchbox").height();
          $(".searchbox").css('-webkit-transform', 'translate3d(0px,0px,0)');
          //$(".searchbox").show().css('z-index', '200').css('-webkit-transform', 'translate3d(0px,0px,0)');
          }

          //ajax loading animation
          function showLoading() {
          //$("div.container").show();
          $("#loading").show(); // If image gif
          }

          function hideLoading() {
          //$("div.container").hide();
          $("#loading").hide(); // If image gif
          }

          function nextprev(prev,next,cat) {
          if (prev === null) {
          $(".previous").empty();
          }
          if (next === null) {
          $(".next").empty();
          }
          if (cat === null) {
          $("#cat").empty();
          }
          }
          function send(x) {
          sid = x;
          //alert ('Fonction '+sid);
          if(isNaN(sid)){ //not a number
          $("#pages .toolbar H1").empty(); // marche pas parce que pas encole loader, peut etre if direction out
          //$("ul#postcat").html();
          $("#pages .toolbar H1").html('Pages');
          //alert ('is not a number');
          } else {
          //$("#showposts .toolbar H1").empty();
          }
          //return false;
          }

          //Hack, ajax jsonp search
          $("#my_button").click(function(e) { // onclick event to the submit button - .tap or .click.
          $("ul#postcat").empty();
          s = $("#searchid").val(); // get the user-entered search term
          //sget(s)
          $('#showposts .toolbar H1').html(s);
          $("#pages .toolbar H1").html('Search');
          $("#showposts .toolbar .back").html('Search');
          //alert(s);
          });

          function target_blank() {
          //make all external link blank & add Hash to internal
          $("#single .blog-content a").attr("href", function(i, href) {
          if( window.location.hostname === this.hostname ) {
          $(this).attr('rel', 'url');
          $(this).attr('id', href);
          return "#";
          }else{
          $(this).attr('target', '_blank');
          return href;
          }
          });
          //alert for external link
          $('a[target="_blank"]').bind('click', function() {
          if (confirm('This External link opens in a new window.')) {
          return true;
          } else {
          return false;
          }
          });

          //$('#singleappend a').bind('click', function() {
          $('a[rel="url"]').bind('click', function() {
          //var id_url = $(this).attr('rel');
          var id_url = $(this).attr('id');
          get_id_url(id_url);
          //alert(id_url);
          });

          $('#single .blog-content a > img').unwrap(); // remove images link

          }

          function getid() {
          //$(".singlenext").bind(clickEventType, function(e) {
          $('.singlenext').bind('click', function() {
          var sid = (this.id);
          //alert(sid);
          get_id_url(sid);
          }); //end
          }

          function get_id_url(id_url) {
          sid = id_url;
          //var sid = encodeURIComponent(id_url);
          //alert(sid);
          var wp_url = PLUGIN_URL + 'get_single.php';

          showLoading();

          $.getJSON(wp_url + '?id=' + sid, function(data) {

          $.each(data.posts, function(i, post) {

          if (post.title !== undefined) {

          var post_html = '
            ';
            //var post_html = '
            • NEXT
            • ';
              post_html += '
            • ';
              post_html += ' ' + post.category + '';
              //post_html += '

              ' + post.title + '

              ';
              if (post.fimg) post_html += post.fimg ;
              post_html += '
            ';

            var post_title = post.title ;

            //$("#single .toolbar H1").empty(); // empty single H1 title for autotitle
            $('#singleappend').html(post_html);
            $('#single .toolbar H1').html(post_title);

            getid();

            nextprev(post.prev_post, post.next_post, post.category);

            } // if post.title !== undefined
            videosize();

            }); //each

            myScroll.scrollTo(0, 0, 0); //last number timer

            setTimeout(function () {myScroll.refresh();}, 2000);
            hideLoading();
            target_blank();

            }); //getjson
            }

            </script>
            <script>/src/itabbar.min.js'></script>
            <script>/src/functions.min.js'></script>





            Arkadaşlar gerekli olan kısım şurası. Ben mobilden konu içeriğine girildiğinde sadece konunun resmini gösterttim. Amacım bu resimi tıklanabilir yapmak veya bu resim altına tıklanabilir bir buton koymak (buton resim urlsine bağlı olacak.)

            Kodlarda resmin tıklanabilir olmasını istediğim kısım: (Kırmızı ile işaretledim.)

            var post_html = '
              ';
              post_html += '
            • ';
              post_html += ' ' + post.category + '';
              //post_html += '' + post.date + '';
              post_html += '


              ';
              //post_html += '

              ' + post.title + '

              ';
              if (post.fimg) post_html += post.fimg ;

              VEYA BURAYA BAHSETTİĞİM BUTONU KOYMAK İSTİYORUM, BUTON RESİM URLSİNE BAĞLI OLACAK YANİ "post.fimg" ye.


              post_html += '
            ';


            Umarım anlatabilmişimdir. Herşeyi tamamladım, sadece bu son aşama kaldı. Yardımcı olursanız çok sevinirim.

            Saygılar.
           

           

          wmaraci
          reklam

          MehmetARIK MehmetARIK Üyeliği Durdurulmuş Banlı Kullanıcı
          • Üyelik 26.01.2014
          • Yaş/Cinsiyet 40 / E
          • Meslek Öğretmen
          • Konum İstanbul Anadolu
          • Ad Soyad M** A**
          • Mesajlar 626
          • Beğeniler 13 / 260
          • Ticaret 2, (%100)
          post_html += 'post.fimg ;';

          (Burda resim dosyası post.fimg olarak tanımlanmış. Bende biraz baktım bu eklentide resim linkleri ya attachment_permalink ya da thumb_permalink olarak tanımlanıyormuş. Bu kodu dediğin yere eklersen büyük ihtimal olur.)

          ya da

          var post_html = '';

          birde bu kod var bak.

          $('#single .blog-content a > img').unwrap(); // remove images link

          bu kod resim resim linkini kaldırır diye açıklama girmiş.
          Secret35

          kişi bu mesajı beğendi.

          wmaraci
          Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)