I have in my main page dojox/layout/ContentPane widget. This widget dynamically load any Hrefs with content which have Javascript & HTML the being formed by PHP.
Javascript
$scriptCode .= 'require(["' . $scriptFile . '", "dojo/ready"], function(PageScript, ready){' . "\n";
$scriptCode .= ' ready(function(){' . "\n";
$scriptCode .= ' setTimeout(function(){new PageScript(' . $scriptOptions . '); }, 0);' . "\n";
$scriptCode .= ' });' . "\n";
$scriptCode .= '});' . "\n";
PageScript() is a dojo class drawing widgets and logic of page. The problem consists in that that when loading other href the object of old page partially gains properties of new objects. Removal of object of page after an drawing , destruction of widgets don't help to solve a problem.
PageScript
define(['dojo/_base/declare', 'common/widget/Card'], function (declare, pageWidget) {
return declare(pageWidget, {
constructor: function(options){
}
});
});
PS. Sorry for my bad english
Um, your code and question don't make a lot of sense. If you want to load dynamically created content into a ContentPane the easiest way is to pass in a dojo template. Just use data-dojo-type to create any widgets that you need. If you need to run code on widget load, put it in the widget's startup function.
Related
I'm trying to build a widget for a website that displays a random background image everytime the page is refreshed and i'm running into some trouble with string concatenation.
$display .= "<p class=\"ey-image-quote\" style\"background-image:url('".$img."')\">" . $this->quote . "</p>";
This returns a url without slashes (replaced by spaces) and i have not found a viable solution yet.
Is there any way to achieve this in php?
$display .= "<p class=\"ey-image-quote\" style=\"background-image:url('".$img."')\">" . $this->quote . "</p>";
You forgot = in style
I have i guess a bit dirty code. This is a function php with custom wp_nav code.
$output .= $indent . '<div class="categories-wrapper"><li' . z_taxonomy_image($cat->term_id) . $id . $class_names .'>';
So i have plugin that gives images to categories. What i need is that image will apply to the 'li' block and can be seen as a 'background:url(plugin url)' in css if it possible. this one does nothing.
Not sure which should i even use though.
z_taxonomy_image($cat->term_id)
Plugin documentation list - categories image
Rest of the code i think don't that matter. If not , i will add.
EDIT
Found a useful post that i think will solve my problem but i still don't know how to properly use it. How do i inster it in the <li>?
if (function_exists('z_taxonomy_image_url')) $background_url = 'background:url(' . z_taxonomy_image_url() . ')';
echo '<div class="' . $tax_term->slug . '" style="display:none; ' . $background_url . '">';
full help thread stackoverflow
EDIT 2
Figured out myself a proper code
$output .= $indent . '<div class="categories-wrapper"><li style="background: url(' . z_taxonomy_image_url($cat->term_id) . ')"' . $id . $class_names .'>';
it now shows in inspector url of my site instead of picture given by plugin.
EDIT 3
if i add foreach (get_categories() as $cat) it's working, i got the images
foreach (get_categories() as $cat)
$output .= $indent . '<div class="categories-wrapper"><li style="background:url(' . (function_exists('z_taxonomy_image') ? z_taxonomy_image_url($cat->term_id) : '') . ')"' . $id . $class_names .'>';
But it messed up the whole html code, added tons of <li> block and others so it overrides each other. Maybe i should put it somewhere else?
Small edit - code is not working on a index page (it's a block with categories-sidebar), but when you enter any post, it shows you correct picture of category, but also it shows it for EVERY block of categories on a sidebar same picture.
So maybe i ask something imposible and that plugin can't do that.
you need to insert the image in style=""
like this maybe:
'<li style="url('z_taxonomy_image($cat->term_id) ')"' . $id . $class_names .'>';
another solution
Why not use json response and append dom elements? insert each picture to the required element.
In the following example, I am receiving a json array of pictures and inset them to a specific element.
you could retrieve the picture and the picture type for instance and inset to elements by type.
this is my first attempt to help, be gentle.
for your example you could set the css of each li element using .css()
$.ajax({
type: "POST",
data: {text: text, images: images, images_big: images_big},
url: "/ajax/" + $(this).attr('data-post') + "/createPostComment",
dataType: 'json',
error: function () {
$el.remove();
return;
},
success: function (r) {
$el.attr('data-id',r.comment_id);
if(typeof r.pictures != 'undefined'){
for(var i=0; i < r.pictures.length; i++){
el.find('.comment-pictures-container').append('<img src="'+ r.pictures[i] +'" data-big="'+ r.pictures_big[i] +'" />');
}
}
bindCommentGallery($el);
bindCommentMenu($el);
}
});
This question already has answers here:
Open link in new tab or window [duplicate]
(4 answers)
Closed 7 years ago.
and first off a thank you to all of the StackOverFlow users as I have found a lot of good answers here. I am a PHP/mySql newbie and I’m teaching myself from books and examples from others.
My problem: I have a mySQL DB with a URL column and a text column with a “clickme_text”, all the same DB row.
From my website I want to be able to hit the “clickme” and then the DB URL will open in a new tab.
Right now my PHP code works but it will not open the url in a new tab, it opens the new url in the same tab.
I’m sure the answer is already out there somewhere, but I’ve gone crossed eye’d trying to create the html and PHP to both go to the new url and open in a new tab.
My DB url is “picture_link” and my clickme text in the DB is “picture_text”.
This code pulls the url and the “clickme text just fine from my DB, but it opens the url in the same tab.
echo '<li>' . '' . $row['picture_text'] . '' . '</li>' . '<br/>';
I’ve tried a bunch of variations of something like this but it’s a no-go:
Echo ("<script> window.open(\""'<li>' . '' . $row['picture_text'] . '' . '</li>' . '"\");
I know this html will open a new tab to “google” (for example):
Click Me!
Do I need to create a var that points to my DB url, and then point my html to this var?
Any help on how to open my “clickme” DB url in a new tab is appreciated, thank you.
You need to add target="_blank" to your link.
echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
Simply add target="_blank" to your generated link:
echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
Ted,
You just need to add the target to your tag
echo '<li>' . '<a href="' . $row['picture_link'] . '" target=_blank>' . $row['picture_text'] . '</a>' . '</li>' . '<br/>';
when looking in codeigniter user manual or some other open source CI base project, i realize that form are store/generate/create in views, here the example:
application/view/main_view.php
<?php echo form_open("/user/create");?>
<?php echo form_input("input1",$value); ?>
.
.
.
<?php echo form_close(); ?>
then load it in controller.
But in my project, i create long string that contain form + table code, when load->view, passing the hold string into that view, here are part of the code:
application/controller/user.php
$this->table->add_row(array("data"=>form_input("name",$value)));
$data["content"]=form_open("/user/create");
$data["content"].=$this->table->generate();
$data["content"].=form_close();
$this->load->view("main_view",$data);
which style are better? and why?
(PS: sorry for the broken English)
i using table to ensure the form layout, here come with the situation:
form writing in view with html table tag.
load html library in view(or related controller), but my view is flooding with many php code
if u work in a team better you use a pure html in view file and never do defining part of view in controller. but if you want to use CI form helper better you type like this :
<?php
$form = form_open("/user/create");
$form .= form_input("input1",$value) . '<br>' ;
$form .= form_input("input2",$value) . '<br>' ;
$form .= form_input("input3",$value) . '</br>' ;
$form .= form_close();
echo $form;
?>
it just a simple example to make shorter of code.
I apologise for the potentially nebulous title, but I hope that the question will clarify why I've called it that.
I've gotten into webdev from UI design/dev so I'm finding the programming and design aspects fairly easy to handle. However, I'm not used to using three/four different languages with a fair amount of overlap to do a single thing.
In this case, I've written up a PHP script to pull the latest $n tweets from $x user. Currently I'm loading the Twitter PHP via jQuery, crafting the HTML for the tweet in PHP, echoing in the PHP, this is then plopped into a timeline element in the jQuery's callback function.
This way of doing it seems a bit hacky? I was just hoping someone would be able to point me towards another way, or at least waylay my concerns regarding this method.
Here's some Code:
HTML:
<section id="twitterContainer">
<section id="glitchTimeline" class="timeline">
<!--Twitter articles go here-->
</section>
</section>
Javascript:
function getTweets(n,user)
{
//This is run when the page is loaded
//Will be changing this to an ajax call later, aware that it's a bit silly as is.
$('<article class="twitterPost">').load("http://xxxxxxxxx.com/php/index.php?user="+user+"&count="+n, function(data){
$(this).appendTo("#glitchTimeline");
});
}
PHP:
(This is called once the twitter API stuff has come back)
function craftTweet($jsonStr)
{
$json = json_decode($jsonStr);
for($i = 0; $i<count($json); $i++)
{
echo '<img class="twitterAvatar" src=' . $json[$i]->user->profile_image_url .' alt=' . $json[$i]->user->screen_name .' width="48">';
echo '<div class="tweetText">';
echo ' <b>' . $json[$i]->user->screen_name .'</b><span>#' . $json[$i]->user->screen_name . '</span><span> </span>';
echo ' <p>' . $json[$i]->text . '</p>';
echo ' <img class="twitterIconFav" src="img/utils/transBackground.png">';
echo ' <img class="twitterIconRetweet" src="img/utils/transBackground.png">';
echo ' <img class="twitterIconReply" src="img/utils/transBackground.png">';
echo ' <div class="clearfix"> </div>';
echo '</div>';
}
}