difficulties on locating javascript and css codeigniter - javascript

Hi how can i aces in view model
i saved my css and javascript inside the js folder and css folder inside the application in codeigniter how can i aces it i'm having difficulties to link them
www
application
-jsfolder
-jsfiles
-cssfolder
-cssFiles
<?php
//birds.php
class Birds extends CI_Controller{
function index(){
$this->load->view('birds_view');
}
function get_birds(){
$this->load->model('birds_model');
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$this->birds_model->get_bird($q);
}
}
}
<?php
//birds_model.php
class Birds_model extends CI_Model{
function get_bird($q){
$this->db->select('bird');
$this->db->like('bird', $q);
$query = $this->db->get('birds');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['bird'])); //build an array
}
echo json_encode($row_set); //format the array into json data
}
}
}
}
bird_view.php
<style>
.ui-autocomplete-loading {
background: #fff url('../link/to/ajax-loading-image') right center no-repeat !important;
}
</style>
<link href="<?php echo base_url().'css/' ?>./css/jquery.ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url().'js/'?>/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url().'js/'?>/js/jquery.ui.js"></script>
<input type="text" id="birds" />
<script>
$(function(){
$("#birds").autocomplete({
source: "birds/get_birds" // path to the get_birds method
});
});
</script
it only display white screen tnx in advance guys

You should link your css and js file as:-
<link href="<?php echo base_url().'css/jquery.ui.css'; ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?php echo base_url().'js/query.js'; ?>"></script>
<script type="text/javascript" src="<?php echo base_url().'js/jquery.ui.js'; ?>"></script>

do your really need that 'dot' after your closing php tag?
<?php echo base_url(); ?>./
also remove extra leading slashes:
<link href="<?php echo base_url(); ?>css/jquery.ui.css" />
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.ui.js"></script>
p.s make sure that base_url is set properly in your config file: $config['base_url']='localhost/websitename/'
with a trailing slash

Related

Owl Carousel with Magnific Popup - Popup not even displaying, not sure what I'm doing wrong

I'm using Magnific Popup for my Owl Carousel Slider. I just want the images to pop-up on screen. However, it doesn't seem to be working. The only thing it does it when I click the images, it opens up its src link. But I just want the Magnific Popup. Am I importing the files wrong? Am i formatting wrong? I've tried so much and can't seem to get the Magnific Popup to even display...
HTML/PHP
<div class="owl-carousel owl-theme details_banner">
#forelse($home_images as $image_model)
#php
$real_image = public_path('uploads/frontend/home/' . $image_model->name);
$image = asset('public/uploads/frontend/home/' . $image_model->name);
if (!file_exists($real_image)) {
$image=DEFAULT_IMG;
}
#endphp
<a class="popup1" href="<?php echo $image ?>"><img src="<?php echo $image ?>"/></a>
#empty
<a a class="popup1" href="<?php echo DEFAULT_IMG ?>"><img src="<?php echo DEFAULT_IMG ?>"/></a>
#endforelse
</div>
Javascript
<script type ="text/javascript">
$(document).ready(function() {
$('.popup1').magnificPopup({
type: 'image',
closeOnBgClick :true,
enableEscapeKey: true
});
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="vendor/Magnific-Popup-master/dist/jquery.magnific-popup.min.js"></script>
I put this at the top of my file
<link rel="stylesheet" href="{{asset('public/frontend/css/owl.carousel.min.css')}}" />
<link href="{{asset('public/backend/css/jquery-confirm.min.css') }}" rel="stylesheet">
<!-- Magnific Popup core CSS file -->
<link rel="stylesheet" href="vendor/Magnific-Popup-master/dist/magnific-popup.css" media="screen"/>
Solved by putting these 2 lines above my Magnific Function
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>

Why my DataTable jQuery cant load on my table view?

This is the code for the script,
but it's not working please help me.
<script>
function loading(){
$("#loading").removeAttr("hidden");
}
$(function () {
//Initialize Select2 Elements
$(".select2").select2();
$("#example1").DataTable();
});
</script>
This is the code for the script, but its not working please help me.
<script src="<?php echo base_url()?>public/jquery-1.12.3.min.js"></script>
<script src="<?php echo base_url()?>public/bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo base_url()?>public/app.min.js"></script>
<!-- DataTables -->
<script src="<?php echo base_url()?>public/datatables/jquery.dataTables.min.js"></sc‌ript>
<script src="<?php echo base_url()?>public/datatables/dataTables.bootstrap.min.js"><‌​/script>
<!-- Select2 -->
<script src="<?php echo base_url()?>public/plugins/select2/select2.full.min.js"></sc‌​ript>
this image is the console error please click here
I Fix it on my Own..
I have a "colspan= 2" in the view table and i have a extra "td" in my code thanks to all your comment.

bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6

i make control panel and there is a problem with jquery (data-toggle) not working and this message appear in console" bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery at bootstrap.min.js:6 "
this is footer file
<div calss="footer">
</div>
<script src="<?php echo $js; ?>jquery-3.2.1.min.js"></script>
<script src="<?php echo $js; ?>jquery-ui.min.js"></script>
<script src=" <?php echo $js; ?>bootstrap.min.js"></script>
<script src="<?php echo $js; ?>jquery.selectBoxIt.min.js"></script>
<script src="<?php echo $js; ?>backend.js"></script>
</body>
</html>
and i include footer
include $tpl.'footer.php';
and thats working in main site with the same folders and pathes and names
i dont know whats wrong
Try this
Change the order of files it should be like below..
<script src="<?php echo $js; ?>jquery-3.2.1.min.js"></script>
<script src="<?php echo $js; ?>bootstrap.min.js"></script>
<script src="<?php echo $js; ?>jquery-ui.min.js"></script>
<script src="<?php echo $js; ?>jquery.selectBoxIt.min.js"></></script>
<script src="<?php echo $js; ?>backend.js"></script>

how to dynamically (or not) move javascript to the footer

I have a wordpress site, and I need to move some javascript to the footer. I am using a theme (photocrati) that only uses the wp_enqueue_scripts tag a total of 4 times in the header.php file.
What I'm looking to do is find a way, hopefully dynamically, to move the javascript files to the footer. I realize this would be much easier using the $in_footer if they were properly referenced using the enqueue_scripts, but alas, that's not the case.
Being that this is a photography studio website, I need to do everything I can to reduce loading time. Now, obviously I'm not about to move CSS to the footer like google page speed recommends because I don't want my site being rendered unformatted when the visitor first views it.
After doing everything else I can (I obviously can't do anything about minimizing or setting leveraging browser caching on files not hosted with my site, ie the google analytics js file), the page speed insights recommends, "Remove render-blocking JavaScript and CSS in above-the-fold content" is all I have left. I am hoping once I move the js to the footer my page load time will be under 5 seconds considering it is now just under 6 and there are 19 script resources.
Hopefully someone can give me some guidance on being able to do this through some PHP code added to the functions.php file since I (for the most part) understand what's going on with PHP code when I am writing. But, I am having a hard time deciphering what is going on in the header file, and being able to find all 19 js files to delete them from the header file and enqueue them properly.
EDIT Here is the header.php file. I've noticed that some of the scripts are not even called here in any way because when I search the file for say "hoverintent.js" it's nowhere to be found, but if I search the source code after my page loads, sure enough it's in the header.
<?php
$preset = Photocrati_Style_Manager::get_active_preset();
extract($preset->to_array());
$rcp = $wpdb->get_results("SELECT fs_rightclick,lightbox_mode,lightbox_type FROM ".$wpdb->prefix."photocrati_gallery_settings WHERE id = 1");
foreach ($rcp as $rcp) {
$fs_rightclick = $rcp->fs_rightclick;
$lightbox_mode = $rcp->lightbox_mode;
$lightbox_type = $rcp->lightbox_type;
}
$music = $wpdb->get_results("SELECT music_blog,music_blog_auto,music_blog_file,music_blog_controls,music_cat,music_cat_auto,music_cat_file,music_cat_controls FROM ".$wpdb->prefix."photocrati_gallery_settings WHERE id = 1");
foreach ($music as $music) {
$music_blog = $music->music_blog;
$music_blog_auto = $music->music_blog_auto;
$music_blog_controls = $music->music_blog_controls;
$music_blog_file = $music->music_blog_file;
$music_cat = $music->music_cat;
$music_cat_auto = $music->music_cat_auto;
$music_cat_controls = $music->music_cat_controls;
$music_cat_file = $music->music_cat_file;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--[if IE 9 ]> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?> class='ie9'><!--<![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>><!--<![endif]-->
<head profile="http://gmpg.org/xfn/11">
<?php
Photocrati_Fonts::render_google_font_link(array(
array($font_style, $font_weight, $font_italic),
array($sidebar_font_style, $sidebar_font_weight, $sidebar_font_italic),
array($sidebar_title_style, $sidebar_title_weight, $sidebar_title_italic),
array($title_style, $title_font_weight, $title_italic),
array($h1_font_style, $h1_font_weight, $h1_font_italic),
array($h2_font_style, $h2_font_weight, $h2_font_italic),
array($h3_font_style, $h3_font_weight, $h3_font_italic),
array($h4_font_style, $h4_font_weight, $h4_font_italic),
array($h5_font_style, $h5_font_weight, $h5_font_italic),
array($description_style, $description_font_weight, $description_font_italic),
array($menu_font_style, $menu_font_weight, $menu_font_italic),
array($submenu_font_style, $submenu_font_weight, $submenu_font_italic),
array($footer_widget_style, $footer_widget_weight, $footer_widget_italic),
array($footer_font_style, $footer_font_weight, $footer_font_italic)
));
?>
<title><?php
if ( is_single() ) { single_post_title(); }
elseif ( is_home() || is_front_page() ) { bloginfo('name'); print ' | '; bloginfo('description'); get_page_number(); }
elseif ( is_page() ) { single_post_title(''); }
elseif ( is_search() ) { bloginfo('name'); print ' | Search results for ' . wp_specialchars($s); get_page_number(); }
elseif ( is_404() ) { bloginfo('name'); print ' | Not Found'; }
else { bloginfo('name'); wp_title('|'); get_page_number(); }
?></title>
<meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<!-- IMPORTANT! Do not remove this code. This is used for enabling & disabling the dynamic styling -->
<?php if($dynamic_style) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/styles/dynamic-style.php" />
<?php if($logo_menu_position == 'left-right') { ?>
<!--[if lt IE 8]>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles/style-ie7-menufix.css" type="text/css" />
<![endif]-->
<?php } ?>
<?php } else { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/styles/style.css" />
<?php if($logo_menu_position == 'left-right') { ?>
<!--[if lt IE 8]>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles/style-ie7-menufix.css" type="text/css" />
<![endif]-->
<?php } ?>
<?php } ?>
<!-- End dynamic styling -->
<!--[if IE 8]>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles/style-ie.css" type="text/css" />
<![endif]-->
<!--[if lt IE 8]>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/styles/style-ie7.css" type="text/css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/admin/css/jquery.lightbox-0.5.css" />
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
<?php
if( !is_admin()){
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-effects-core');
if ($preset->custom_js) wp_enqueue_script('photocrati-custom-js', site_url('?photocrati-js'));
}
?>
<?php wp_head(); ?>
<link rel="alternate" type="application/rss+xml" href="<?php bloginfo('rss2_url'); ?>" title="<?php printf( __( '%s latest posts', 'photocrati-framework' ), wp_specialchars( get_bloginfo('name'), 1 ) ); ?>" />
<link rel="alternate" type="application/rss+xml" href="<?php bloginfo('comments_rss2_url') ?>" title="<?php printf( __( '%s latest comments', 'photocrati-framework' ), wp_specialchars( get_bloginfo('name'), 1 ) ); ?>" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if($fs_rightclick == "ON") { ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/clickprotect.js"></script>
<?php } ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/jquery.jplayer.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/scripts/jplayer.style.css" />
<?php if($lightbox_type == 'fancy'): ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/admin/css/jquery.fancybox-1.3.4.css" type="text/css" />
<?php elseif($lightbox_type == 'light'): ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/admin/css/jquery.fancybox-1.3.4-light.css" type="text/css" />
<?php elseif($lightbox_type == 'thick'): ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/admin/css/jquery.fancybox-1.3.4-thick.css" type="text/css" />
<?php endif ?>
<?php if($style_skin == 'modern' || $lightbox_type == 'magnific'): ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/admin/css/jquery.fancybox-1.3.4.css" type="text/css" />
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/scripts/lightbox/magnific-popup/magnific-popup.css" type="text/css" />
<?php endif ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/admin/js/jquery.fancybox-1.3.4.pack.js"></script>
<?php if($style_skin == 'modern' || $lightbox_type == 'magnific'): ?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/lightbox/magnific-popup/magnific-popup-v0.9.9.min.js"></script>
<?php endif ?>
<?php if($style_skin == 'modern' && is_front_page()): ?>
<?php
// when selecting multiple images as background then $home_bg_image is an array
if (!is_array($home_bg_image)) {
$home_bg_image = array($home_bg_image);
}
$home_bg_list = array();
foreach ($home_bg_image as $bg_image) {
if ($bg_image != null) {
$bg_img = Photocrati_Style_Manager::get_image_url($bg_image, true);
if ($bg_img != null) {
$home_bg_list[] = array(
'image' => $bg_img,
'thumb' => Photocrati_Style_Manager::get_image_url($bg_image, true, 'thumbnail'),
'title' => $bg_image,
);
}
}
}
// check that there are 1 or more images selected, otherwise fallback to default
if ($home_bg_list == null) {
$home_bg = 'default';
}
?>
<?php if($home_bg == 'slideshow'): ?>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ? >/scripts/supersized/slideshow/css/supersized.css" type="text/css" />
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/scripts/supersized/slideshow/theme/supersized.shutter.css" type="text/css" media="screen" />
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/supersized/slideshow/js/supersized.3.2.7.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/supersized/slideshow/theme/supersized.shutter.min.js"></script>
<script type="text/javascript">
jQuery(function($){
$.supersized({
// Functionality
slideshow : 1, // Slideshow on/off
autoplay : 1, // Slideshow starts playing automatically
start_slide : 1, // Start slide (0 is random)
stop_loop : 0, // Pauses slideshow on last slide
random : 0, // Randomize slide order (Ignores start slide)
slide_interval : <?php echo (floatval($home_bg_interval_speed) * 1000) ?>, // Length between transitions
transition : <?php echo ($home_bg_transition_effect) ?>, // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
transition_speed : <?php echo (floatval($home_bg_transition_speed) * 1000) ?>, // Speed of transition
new_window : 1, // Image links open in new window/tab
pause_hover : 0, // Pause slideshow on hover
keyboard_nav : 1, // Keyboard navigation on/off
performance : 1, // 0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
image_protect : 1, // Disables image dragging and right click with Javascript
// Size & Position
min_width : 0, // Min width allowed (in pixels)
min_height : 0, // Min height allowed (in pixels)
vertical_center : 1, // Vertically center background
horizontal_center : 1, // Horizontally center background
fit_always : 0, // Image will never exceed browser width or height (Ignores min. dimensions)
fit_portrait : 1, // Portrait images will not exceed browser height
fit_landscape : 0, // Landscape images will not exceed browser width
// Components
slide_links : 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
thumb_links : 1, // Individual thumb links for each slide
thumbnail_navigation : 0, // Thumbnail navigation
slides : <?php echo json_encode($home_bg_list) ?>,
// Theme Options
progress_bar : 1, // Timer for each slide
mouse_scrub : 0
});
});
</script>
There's the part of the header.php file that contains the js file references. As I said before, not all of them are called through the header.php file.
Enqueue script has a fifth parameter, which is a boolean, false as default. If you set to true, your scripts will be in the footer. In case, your theme has the wp_footer() method in the footer.
<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
An example:
<?php wp_enqueue_script( 'mysript', get_template_directory_uri() . '/js/myscript.js', array(), false, true ); ?>

Wordpress Conditional Javascript Include

I am trying to conditionally include javascript files on specific pages in wordpress. I finally found a snippet of code that does exactly what I want but it doesn't seem to be working. Any thoughts? I didn't include the real page names but I am using the page slug.
<?php if (is_page(array('page-slug','page-slug','page-slug'))) { ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
<? } else { ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/conditional-script.js"> </script>
<? } ?>
I Put this code where I call the rest of my scripts in my custom template files.
On third last line and last line, it looks like you are using <? to open the line. Try using <?php instead. So, it should be:
<?php
if (is_page(array('page-slug','page-slug','page-slug')))
{ ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
<?php
}
else
{ ?>
<script src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/conditional-script.js"></script>
<?php
}
?>
And as I mentioned, I would recommend enqueuing scripts in the future ;)

Categories