Monday, April 23, 2012

jQuery - changed element won't clone

I have changed the html text of an element, in this case #main_cluster_id_reach_12



$("#main_cluster_id_reach_12").html( '400' ).effect("highlight", {color: '#2a6500'}, 60000 * 5);


That works fine but when I try to clone the container that is holding it(#applications), it doesn't contain the updated html of #main_cluster_id_reach_12 but rather the original text that loaded with the page. Here is how I am cloning it:



var $applications = $('#applications');
var $data = $applications.clone();


What am I doing wrong?



edit: Here is the js and html. I am using jquery 1.7.2



What i am trying to do is update the reach of a group of clusters on a 10 second interval via ajax and then resorting the li items with quicksand ordered by their reach. The updating occurs without problem but quicksand clones the original list, not the updated list. This morning i've been playing with some logging and it appears the cloning is happening before the ajax update completes.



// quicksand sorting plugin
(function($) {
$.fn.sorted = function(customOptions) {
var options = {
reversed: true,
by: function(a) { return a.text(); }
};
$.extend(options, customOptions);
$data = $(this);
arr = $data.get();
arr.sort(function(a, b) {
var valA = options.by($(a));
var valB = options.by($(b));
if (options.reversed) {
return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;
} else {
return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;
}
});
return $(arr);
};
})(jQuery);


$(document).ready(function(){
//loop through all reaches to update
setInterval(function() {
//reach
$("[id^='main_cluster_id_reach_']").each(function(){

//Check for reach updates

//get cluster id first
var cluster_id = parseInt(this.id.replace("main_cluster_id_reach_", ""));

//get cluster reach
$.post("./lib/ajax/meme_cluster_update.php", { cluster_id: cluster_id },
function(data) {

//get reach - new
var new_reach = 0;

new_reach = parseInt(data.ItemReach, 10);

//get reach - old
var reach = $("#main_cluster_id_reach_" + cluster_id).html();

// Format as American input
reach = parseInt(reach.replace(/[^\d\.\-\ ]/g, ''));

//compare new vs old and change cell view
compareReach(cluster_id, reach, new_reach);

}, "json");
});

// get the first collection
var $applications = $('#applications');

// clone applications to get a second collection
var $data = $applications.clone();

var $filteredData = $data.find('li[data-type=app]');

var $sortedData = $filteredData.sorted({
by: function (v) {
return parseFloat($(v).find('span[data-type=size]').text());
}
});

// finally, call quicksand
$applications.quicksand($sortedData, {
duration: 800,
easing: 'easeInOutQuad'
});
}, 10000);

//compare the reaches to update accordingly
function compareReach(cluster_id, reach, new_reach) {
//determine what color to change cells
if(new_reach > reach) {
$(".main_cluster_id_reach_" + cluster_id).html( new_reach ).effect("highlight", {color: '#2a6500'}, 60000 * 5);
}
else if(new_reach < reach) {
$(".main_cluster_id_reach_" + cluster_id).html( new_reach ).effect("highlight", {color: '#990004'}, 60000 * 5);
}
}


html



 <div class="span-24" id='demo'>
<ul id="applications" class="image-grid">
<li data-id="id-210639" data-type="app" class='cluster'>
<div class='cluster_byline'>@awkwardisco</div>
<div class="cluster_padding">
<span class='cluster_headline'>Avengers on Thursday!!!</span>
<br>
<div class="cluster_stats">
<div class="span-2 reach">
<strong>REACH</strong>
<span class="main_cluster_id_reach_210639" data-type="size">26777</span>
</div>
<div class="span-2 retweets">
<strong>RETWEETS</strong>
</div>
<div class="span-2 velocity">
<strong>VELOCITY</strong>
</div>
<div class="span-8 LAST">
<strong>LINKS</strong>
</div>
</div>
</div>
</li>
</ul>
</div>




DataGridViewRow to DataRow - object reference not set to an instance

What I'm doing (or trying to do) is getting a row from DataGridView and convert it to DataRow, so I can put that DataRow into DataTable. So I searched for examples on the Web,
and people claimed they work just fine, but my doesn't.
This is my code:



DataGridViewRowCollection rows = myDataGridView.Rows;
foreach (DataGridViewRow row in rows)
{
/*(1)*/ DataRow myRow = (row.DataBoundItem as DataRowView).Row;
myDataTable.Rows.Add(myRow);
}


but I get "Object reference not set to an instance of an object." on line (1).





Friday, April 20, 2012

asp.net imagebutton new window

I have a Telerik Grid. In that I have the following code in an .aspx page. What I want to happen is that when the user click on the imagebutton control it launches a new window to show that image. Note, I have seen some code which use Postback but they are blocked by popup blockers. The control's image is set via codebehind but that should not matter for this question. Here is my code. Thanks!



<asp:ImageButton ID="prod_image_main" runat="server" AlternateText="Product Main Image"
Height="500PX" Width="540PX" />




Windows service implementation in MVC3

Hi I am working on MVC3 Application i want to call a function when the date is expire.For that i want to use windows service.Can anyone tell me steps to implement window service in MVC and if there is any other better option to call the function at certain date.



Thanks in advance.





Shell scripting: export test1="a b c" works, but $(echo 'export test2="a b c"') doesn't

I seem to be having issues with some shell scripting (ZSH in particular), where the shell fails to understand exports with spaces in them. The problem only happens when `runcommand` or $(runcommand) is used.



Test case:



# Works fine:
export test1="a b c"

# Does not work:
$(echo 'export test2="a b c"')


The error is something along the lines of export:4: not valid in this context: c". Adding 1-2 \-escapes before the spaces and/or the quotes might change the error message to export:4: not valid in this context: b\.



Might anyone have insight into what the problem is? Thank you.



(The reason I am doing this is a hack to allow python to set shell variables by dynamically generating code which gets run in .myshellrc; if anyone knows of a more elegant way to do this, that would be quite welcome as a comment. Thank you.)



(&ast;sigh&ast;, I hope this isn't a version-specific issue in 4.3.12... I think this may have worked in the past.)





FabricJS support for SVG viewBox element?

Does fabricJS support SVG viewBox element so that it will render only that on canvas? That way, zooming of the entire screen could be implemented easily.





Webdevelopment using JSP and XML

I am developing an online exam for which I retrieve questions from an XML file. But when I retrieve the questions using JSP, I am getting all questions at a time in a single page.



I want to show one question in one page, for the next question the user needs to click on the next buttun. There is also a timer for each question and when that expires the system automatically moves to the next question.



I tried different codes but I didn't get what I wanted. Can some one help me in this?