Include .js files on my Drupal site - jquery-ui

I want to use jQueryUI Autocomplete on my Drupal site and I downloaded the .js files that are needed for it to function. Now after that, I saved my .js files on my themes folder located at /sites/all/themes/advanced/js. And in my page.tpl.php there's this code,
<head>
<?php print $head ?>
<title><?php print $head_title ?></title>
<?php print $styles ?>
<?php print $scripts ?>
<?php print phptemplate_get_scripts(); ?>
<?php if ($user->uid) print phptemplate_get_scripts_advanced(); ?>
<!--[if lt IE 7]>
<?php print phptemplate_get_ie_styles(); ?>
<![endif]-->
</head>
with the code above I'm assuming that my .js files will be included but when I reloaded the page and check the running scripts through Firebug, I could not find them. What did I miss? Thanks in advance.

Got it. I did try to put my scripts manually on my template.php and that solved it. :)

Related

Browse Another Website Inside MVC Application

I have an existing web application which I want to display inside my new application, so as to the complete application works inside the new application.
In the image i've attached google.com so on search of something is should show the result or even open the website.
I'm not sure how to achieve that.
One way I found is IFrame, so would I to know any other possibilities are their as I do want to use IFrame
Attaching an Image for an example
Thanks in advance.
Maybe you can use something like fancybox tools. http://fancyapps.com/fancybox/#examples
But usually these tools are also using iframes. Maybe you can find another way for fancybox.
edit:Embed an External Page Without an Iframe?
edit 2: did you try this?
http://www.felgall.com/noiframe.htm
<html>
<head>
<title>example</title>
</head>
<body>
Ilker Test
<br />
<!--[if lte IE 6]>
<object classid="CLSID:25336920-03F9-11CF-8FD0-00AA00686F13"
data="http://www.w3schools.com/html/html_examples.asp" style="height:800px; width:1200px; overflow:hidden;">
</object>
<![endif]-->
<!--[if gte IE 7]><!-->
<object type="text/html" data="http://www.w3schools.com/html/html_examples.asp"
style="height:800px; width:1200px;">
<p>Alternate text.</p>
</object>
<!--><![endif]-->
</object>
</body>

Dyamic CSS not loading in iOS

I am point the href of css link to a php script. Works good in all browser. When i try the same in iOs its not working.
If I put the manual entry instead of programtic entry it works.
The source that works
<html>
<head>
<link rel="stylesheet" href="http://localhost/assets?action=writeCss&cssId=38">
</head>
<body>
</body>
</html>
The source that not works
<html>
<head>
<link rel="stylesheet" href="http://localhost/assets?action=writeCss&cssId=<?php echo "38"; ?>">
</head>
<body>
</body>
</html>
Thanks in Advance.
Are you trying to use PHP in a UIWebView? I think you can't run PHP on the iOS, PHP runs on the server and not on the browser.
Read this and this.

jQuery UI Autocomplete can't figure it out

I decided to use jQuery UI for my autocomplete opposed to a plugin because I read that the plugins are deprecated. My overall goal is to have an autocomplete search bar that hits my database and returns users suggestions of city/state or zipcodes in a fashion similar to google. As of now I am not even sure that the .autocomplete function is being called. I scratched everything I had and decided to start with the basics. I downloaded the most recent version of jQuery UI from http://jqueryui.com/download and am trying to get the example that they use here http://jqueryui.com/demos/autocomplete/ to work. All the scripts that I have included seem to be connected at least linked through Dreamworks so I am fairly certain that the paths I have included are correct. The CSS and Javascripts that I have included are unaltered straight from the download. Below is my HTML code and my backend PHP code that is returning JSon formated data. Please help me. Maybe I need to include a function that deals with the JSon returned data but I am trying to follow the example although I see that they used a local array.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQueryUI Demo</title>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.17.custom.css" type="text/css" />
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#tags").autocomplete({
source: "search_me.php"
});
});
</script>
</head>
<body>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->
</body>
</html>
Below the PHP part.
<?php
include 'fh.inc.db.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
$location = htmlspecialchars(trim($_GET['term'])); //gets the location of the search
$return_arr = array();
if(is_numeric($location)) {
$query = "SELECT
zipcode_id
FROM
user_zipcode
WHERE
zipcode_id REGEXP '^$location'
ORDER BY zipcode_id DESC LIMIT 10";
$result = mysql_query($query, $db) or die(mysql_error($db));
while($row = mysql_fetch_assoc($result)) {
extract($row);
$row_array['zipcode_id'] = $zipcode_id;
array_push($return_arr, $row_array);
}
}
mysql_close($db);
echo json_encode($return_arr);
?>
Thanks for the ideas. Here is an update.
I checked the xhr using firebug and made sure that it is responding thanks for that tip. also the above php code I hadn't initialized $return_arr so i took care of that. Also thanks for the clarification of the js required or rather not required. Now when I type in a zipcode a little box about a centimeter shows up underneath it but I can't see if anything is in there, I would guess not. I went to my php page and set it up to manually set the variable to "9408" and loaded the php page directly through my browser to see what it returned. This is what it returned.
[{"zipcode_id":"94089"},{"zipcode_id":"94088"},{"zipcode_id":"94087"},{"zipcode_id":"94086"},{"zipcode_id":"94085"},{"zipcode_id":"94083"},{"zipcode_id":"94080"}]
I then went to a JSON code validator at this url http://jsonformatter.curiousconcept.com/ at it informed me that my code is in fact returning JSON formatted data. Anymore suggestions to help me troubleshoot the problem would be terrific.
Wow after more research I stumbled across the answer on someone another post.
jquery autocomplete not working with JSON data
Pretty much the JSON returned data must contain Label or Value or both. Switched the zipcode_id to value in my $row_array and... boom goes the dynamite!
Your scripts (js files) references are not correct, should only be:
<!-- the jquery library -->
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<!-- the full compressed and minified jquery UI library -->
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
The files "jquery.ui.core.js", "jquery.ui.widget.js" and "jquery.ui.position.js" are the separated development files, the jquery ui library is splitted into modules.
The file "jquery-ui-1.8.17.custom.min.js" contains them all, compressed and minified !
Concerning the data source, as stated in the "Overview" section of the Autocomplete documentation: when using a an URL, it must return json data, either of the form of:
an simple array of strings: ['string1', 'string2', ...]
or an array of objects with label (and a value - optionnal) property [{ label: "My Value 1", Value: "AA" }, ...]
I'm really not familiar with PHP so just make sure your php script returns one of those :-)

Custom meta tag configuration

I have 2 tables, page and settings.
page is just a bunch of fields, such as name and slug, and has 3 other fields for meta tags (title, keywords, description) and displays a cms page.
The settings has 3 fields: default_meta_title, default_meta_keywords, default_meta_description
Now what I'm looking to do is to display the default_meta_* tags in the HTML source if the page I am on does not have the particular meta info set from the cms page.
All pages, except the homepage is managed this way, so I was thinking I'd need to add some code to the layout.php to get this to work.
So the homepage will display my default_meta_*, as I cannot set this in the cms pages table.
There are two ways to solve the problem.
First is to use sfYaml class to update view.yml with default meta tags (see documentation about view.yml). After that if specific page should use another metas you can override defaults with addMeta method of response object
Second (as ManseUK suggested) is to declare slot placing code like this into layout
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<?php include_javascripts() ?>
<?php include_stylesheets() ?>
<?php include_title() ?>
<?php if (has_slot('metas')): ?>
<?php include_slot('metas') ?>
<?php else: ?>
<?php include_component('page', 'metas') ?>
<?php endif; ?>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
<body>
Default metas will be rendered via page components. On top of your template (i guess modules/page/templates/showSuccess.php) place code
<?php slot('metas') ?>
<?php if($page->hasMetas()):?>
<!-- code to render nondefault page metas -->
<?php echo $page->getMetas(); ?>
<?php else: ?>
<?php include_component('page', 'metas') ?>
<?php endif;?>
<?php end_slot() ?>
I assume that you will replace $page->hasMetas() with real code that will check if your page object has metatags.
Actually i would prefer to go further and code page components to accept parameters. Code in a template will look like
<?php slot('metas') ?>
<?php include_component('page', 'metas', array('metas'=>$page->getMetas())) ?>
<?php end_slot() ?>
Deciding which metas (default or not) should be rendered will take place in page components (i assume that you can easily retrieve defaul;t settings from your database). If no parameters were passed (see layout code) than your component should also render default metas.
I hope this will help.
You could use a slot - check for existence of the slot in the layout - if it exists then add the custom meta fields - if not add the default ones

$sf_response->addStyleSheet() dosen't work in SF 1.4?

Does anyone know how to add stylesheets in a template with Symfony 1.4 ?
I have tried everything I can think of, from modifying frontend/config/view.yml to modifying the template itself - bothing works.
I have seen from my searches, that other people have had the same problem. There seems to be a clash of sorts between using include_stylesheets and use_stylesheets - however this is not documented anywhere AFAIK.
Edit:
Ok I think I got it now. You should add include_stylesheets() into the head section of your layout file:
<html>
<head>
<title>This is the title</title>
<?php include_stylesheets() ?>
</head>
<body>
<!-- ... -->
Then in your template file, you use use_stylesheet() to add a particular stylesheet for this template:
<?php use_stylesheet('/path/to/stylesheet.css') ?>
From the API documentation:
include_stylesheets()
Prints <link> tags for all stylesheets configured in view.yml or added to the response object.
use_stylesheet()
Adds a stylesheet to the response object.
Same for Javascript.
According to the API documentation it should still work in 1.4, sfWebResponse still has this method:
addStylesheet ($file, $position, $options)
$file The stylesheet file
$position Position
$options Stylesheet options
Adds a stylesheet to the current web response.
At least the method exists.
What exactly is the problem? Do you get an error if you want to call that method or is the stylesheet just not added?
http://www.symfony-project.org/tutorial/1_4/en/upgrade#removal_of_the_common_filter
As of 1.4 your javascripts and stylesheets are no longer automatically injected into your head tag. Instead, you need to include the following in your layout where you'd like them to be placed:
<?php include_javascripts() ?>
<?php include_stylesheets() ?>
and just in case your post title wasn't a typo you'll want to use addStylesheet('...') off of the response:
$sf_response->addStylesheet('main');
$sf_context->getResponse()->addStylesheet('style.css')
$sf_context->getResponse()->addJavascript('script.js')

Resources