How to customize the Mini-Profiler UI - mvc-mini-profiler

I have installed Mini-Profiler on my MVC 4 application and it is working like a charm. The only problem I have with it is that the UI covers up a critical part of my UI. I can move it around the page using the css but ideally I would like to make it so it defaults to a hidden state with a drawer button to make it pop out. I tried writing a javascript function that would manipulate the results display but when I placed the following code at the bottom of my _Layout.cshtml file the mini-profiler would place all of it's code at the very bottom of the page after my customize function so the customize function would run before the profiler.
#MiniProfiler.RenderIncludes()
<script type="text/javascript">
$(function() {
CustomizeMiniProfiler();
});
</script>
Any ideas? Ideally I don't want to modify the source code of Mini-profiler as I would like to make it easy to upgrade going forward with NuGet.

Much of the Mini Profiler initialisation is deferred till way after jQuery.ready, this is so Mini Profiler has minimal impact on page load behaviour. See: https://github.com/SamSaffron/MiniProfiler/blob/master/StackExchange.Profiling/UI/includes.js#L597
I would recommend a pull request that hooks into the Mini Profiler initialization process perhaps:
MiniProfiler.afterInit(
function(){
/* if called after init happens right away, else happens after init */
});

Related

Loading Easy Fancybox with Ajax Load More + Next Page Add on

I have Easy Fancybox with Ajax Load More + Next Page Addon (Same company). My issue is Easy Fancybox does not recognize content after the first page break and so it loads images without the light box.
Example: http://boyonamountain.com/?p=118&preview=1&_ppp=fe18270bb4
Now, I have been researching for hours now and it seems there are some work arounds with requiring a call back.
Problem is, I am a designer and this is my personal site so I only have HTML/CSS knowledge.
I found this: how to bind fancybox to dynamic added element?
tried adding the code from that to the repeat template part of Ajax Load More,
I also tried to add it to the function.php, all to no avail.
Would someone be willing to help me trouble shoot this? Thank you all so much!
I'm also using easy fancybox and you just have to bind an event to the post-load easy fancy box handler;
I chose the focusin event that really happens after the loading of my completed form :
<script type="text/javascript">
jQuery( document ).on( 'focusin', easy_fancybox_handler );
</script>
You have to tell the plugin that content is loaded, choosing the good event.

Is there a way to make Omniture capture the url/page loaded via ajax as a "Load" event and not a "Click" event?

I am currently working on a Ajax based mobile website project and am not able to get Omniture to work correctly. Here is a brief detail of the problem.
Assume a mobile site which has multiple pages, like example.com/a, example.com/b, example.com/c, example.com/d, example.com/e, example.com/f, etc.
Each page of the site, has Omniture's code, like:
<html><head></head><body>
<script type="text/javascript" src="//domain-and-path-to-omniture-code-files/s_code.js">
<script type="text/javascript">
s.pageName = "blah";
// some other ... s.blahBlah ... properties here...
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code);
</script>
<div id="content">SOME CONTENT</div>
</body>
User opens the browser and opens one url/page, like example.com/a
The page (example.com/a) has multiple links to the content on the same page, like #topic1, #topic2, #topic3, etc. and also has links to other static pages of the site, like example.com/b, example.com/c, example.com/d, etc.
I use jQuery to control click events on these links.
When user clicks on a named link, like #topic1, #topic2, etc., the page is animated/smooth-scrolled to the target element/content-section; and Omniture's "s.tl()" function is triggered, to track/capture the click event with relevant/required details.
## THIS IS THE PROBLEM AREA ## When user clicks on a link to a different static page, like example.com/b, example.com/c, etc., instead of allowing the browser to do a full page-load, the Ajax version of the target page is loaded into the content holder (by Ajax version, I mean to say that the page only has bare-minimum markup/content and not the entire html/head/common-css/js includes/etc).
Now the problem is that, when the page is loaded normally, Omniture captures it correctly as a "Load" event, but when it's loaded via JavaScript/Ajax, Omniture captures it as a "Click" event!
The Ajax/version of the page, does not include Omniture library "s_code.js" JS again (for obvious reasons, its already there on the parent/main page). Along with the required content, this page only has a script-tag, which sets required "s.blahBlah" values for the new page and the call to "s.t();".
I also tried to keep the Omniture code separate, in a common JS file, which is already loaded with the parent page, and only set the required "s.blahBlah" values in the Ajax call/function (which is also in a global/already loaded JS file), but still Omniture captures it as a "Click" event.
// s.tl(); ... gets captured as a click event
// s.t(); ... on normal page load... gets captured as a load event
// s.t(); ... after DOM-ready/page loaded via Ajax... gets captures as a click event
Any ideas! How can I make Omniture capture a load event? Is there a function like "s.l()" or something to trigger Omniture's "Load" event on demand.
The problem was not Omniture capturing it incorrectly, it was the tool "Omnibug", which I use to see the requests.
Omnibug 0.5.448 logs all "s.t()" calls made before page load event as Omniture "Load" event and any "s.t()" call made afterwards is captured as "Click" event.
Apparently, I was not the only one facing this issue. Others had already reported this to the developer of Omnibug (https://github.com/simpsora/omnibug/issues/4) and a fix has been made by him/a new version Omnibug 0.5.500 has been released.
The new version of Omnibug 0.5.500 captures all "s.t()" calls as "Load" events correctly and all "s.tl()" calls as "Click" event.
Thanks!

Rendering javascript in template on initial page load meteorjs

I'm trying to load a chart from the google charts api. For the most part it is working as planned. The issue comes on the initial page load. If I navigate from another part of my site to the page (using router) it loads fine. However, if I hit the refresh button on the page the chart does not load until I leave and re-enter the page.
I have this in my main.html header:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
and in my template.templatename.rendered AND template.templatename.created I have
google.load("visualization", "1", {'callback':function() {},packages:["corechart"]});
google.setOnLoadCallback(drawChart);
Deps.autorun(function () {
drawChart()
})
Where drawChart() calls the google visualization commands. I do understand I'm probably calling some repetitive code currently, but all of this is in an effort to get the page to load when I hit refresh.
I appreciate any help.
Please let me know if there is any more info needed. Thanks.
Placing the Google jsapi file in the main.html header will cause the browser to run the Javascript after the DOM is completely loaded, which is too late for your purposes.
Meteor is calling your google.load code before the DOM is completely rendered, so when you hit refresh page, the jsapi file is undefined when Meteor calls google.load.
However, if you navigate away and then back, the DOM has already been loaded once, so the chart will be rendered correctly.
To solve this, I would suggest just saving a local version of http://www.google.com/jsapi in your client folder.
Thus, Meteor will load it before it calls the google.load code.

How to properly use pjax?

I have a very sketchy idea of how pjax works and therefore a very sketchy implementation of it on my site. I have this code at the beginning of all my jquery
$('li a').pjax('#container');
and the thing that you would click looks like this
<li><div id="sortmain" class="catagories">main</div></li>
so when I click that li it loads the main.html into the container div. But it is glitchy and pretty slow. How can I improve this? Also, because main.html is a real document when I refresh the page it only shows what main.html outputs, how do I fix that?
I can't tell why it is slow or glitchy without looking at your site.
If you want main.html to be a full-page (so that refresh works without server-side processing) you can use the fragment option in pjax:
$('li a').pjax("#container", { fragment: "#container" });
This will update the #container div with PJAX (if pushState is available) and on older browsers your site will just work the way it used to.

Form submitted twice after updating from ASP MVC 3 Preview to Beta

After upgrading my ASP MVC from 3 Preview to 3 Beta I see strange behaviour in my Ajax forms.
#using(Ajax.BeginForm("New", new AjaxOptions() {OnSuccess = "onAjaxSuccess", OnFailure = "onAjaxFailure", OnBegin = "onAjaxBegin", HttpMethod = "Post"})) {}
<form action="/Order/New" data-ajax="true" data-ajax-begin="onAjaxBegin" data-ajax-failure="onAjaxFailure" data-ajax-method="Post" data-ajax-success="onAjaxSuccess" method="post"></form>
I have placed an alert inside my function onAjaxBegin and it is beeing fired twice, each time i click on my submit button.
Anyone else seen this behaviour? I have not changed anything in the code after upgrading, and it worked perfectly before the upgrade.
I had the same problem, and i found the solution: I included the "jquery.unobtrusive-ajax.min.js"-Script twice :-)
Look at the generated HTML. In ASP.NET MVC 3 Beta there's new support for unobtrusive jquery based ajax and all the Ajax helpers use jquery now. Maybe there's something left with MS Ajax which causes the double call. Make sure you remove all the inclusions of MSAjax scripts from the page. Also why using Ajax.BeginForm when you could simply use Html.BeginForm with unobtrusive jquery?
The duplicated jquery.unobtrusive-ajax.min.js can also happened if your controller returns a View() instead of PartialView().
I had the same problem using a AJAX.BeginForm call that is loaded dynamically using $.load()
I solved it by removing the extra include of jquery.unobtrusive-ajax.min.js on the loaded form. That's the key!
one small tip all the time before you using .live(), do .die() :)
this will kill all the java scripts attached to this event and will create a new one.
example:
$(function() {
$('#MyInfoForm').die();
$("#MyInfoForm").live('submit', function(e) {
//some code
e.preventDefault();
});
});
Just for future reference for those using ASP.NET MVC; "~/Scripts/jquery.unobtrusive*" does also include "~/Scripts/jquery.unobtrusive-ajax.js".
So if your BundleConfig looks like this;
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.unobtrusive-ajax.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
It will result in submitting an Ajax form twice. Removing either "~/Scripts/jquery.unobtrusive*" or "~/Scripts/jquery.unobtrusive-ajax.js" will fix the problem.
Just posting this because it is easy to overlook "~/Scripts/jquery.unobtrusive*" when searching for unobtrusive-ajax.
You can use bind instead of live in jquery.unobtrusive-ajax.min.js~~~ This is very important.Because live event will call the previous events every time but bind only calls the current event.
Moving jquery.unobtrusive-ajax.js outside partial-view solved the issue in my case.
I had the same problem. I had a login partial view in master page that included jquery.unobtrusive-ajax.min.js. I also had this file included in my view. So I removed one and the problem is solved now.
I also had this exact problem and for a very different reason. I had included the script reference to the jquery.unobtrusive-ajax.min.js within the div that got updated. Moving it outside the div fixed it.
This might be helpful for someone having a scenario similar to what I have:
On my page, the edit form opens a partial view inside a Kendo UI modal pop-up window, which loads the code of the form dynamically, including jquery.unobtrusive-ajax.js. With this setting, - which can relate to any pop-up such as that of jQuery UI and not just Kendo UI - the behavior of form submission is as follows:
The first time the pop-up window is opened, the form submission causes a single call to the controller (server-side) code. So far so good. However, for the second time that the window is opened (without closing the container page), the form submission calls the controller 2 times. Subsequently, each re-opening of the pop-up window, causes an additional loading of the jquery.unobtrusive-ajax.js code, which in turn causes an additional unwanted call to the controller at each single submission of the form.
In order to fix the problem, I moved the inclusion of jquery.unobtrusive-ajax.js from the partial view of the pop-up window into the main page. However this made the client-side validation stop working, and to fix that, I used the solution provided in here:
client side validation with dynamically added field which links to this blog post:
http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/
I found out the solution, just remove all jquery.unobtrusive-ajax.js references, since you are using the Ajax.BeginForm it will use the ajax normally.
So it doesn't has to disable the ajax.
this is old but I found something really stupid that is easy to overlook.
Our form also had the following attached to it:
$(document).ready(function () {
$('#submit-button').on('click', function (e) {
....
}
});
Obviously the .NET code handles this itself.

Resources