1

Before jumping off the deep end with Ajaxify on a large Razor project, I thought it best to create an MVC4/Razor test-bed app and try it out.

Repro:

  1. Created a standard MVC4/Razor Web Application in VS 2012

  2. Added the requisite JQuery add-in files (It already has JQuery 1.8.2 by default in the Razor project template).

Added this to BundleConfig.RegisterBundles

bundles.Add(new ScriptBundle("~/bundles/ajaxify").Include(
            "~/Scripts/jquery-scrollto-{version}.js",
            "~/Scripts/jquery.history-{version}.js",
            "~/Scripts/ajaxify-html5-{version}.js"
            ));

Note: I rename all add-ins to the MS standard ~/scripts/addinname-9.9.9.js format to allow for easier upgrading

Added one line to the bottom of Views/Shared/_Layout.cshtml

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/ajaxify")    <=== ADDED THIS LINE
@RenderSection("scripts", required: false)

When I run the web app the home page comes up normally (as expected), but the contact page comes up using the mobile styles. To verify this I made the body yellow in that media selector and sure enough, it kicks in on the Ajaxified (dynamically loaded) About page:

enter image description here

These CSS styles are defined in the CSS within the following selector:

@media only screen and (max-width: 850px)

The page corrects itself if you resize it at all or refresh the browser: enter image description here

I am surprised that this is possible, as the media selector is meant to be resolution dependant, so thought I would see if anyone can shed light on the cause. The browser window is greater than 850px at all times so the mobile styles should not be shown at all.

The Actual Question Is:

To avoid further confusion the actual question is: I need to know why the media filter selector is triggering, even though the screen is bigger than the min size specified?

Update:

I reduced the Standard MVC4/Razor CSS mobile styles section to the minimum below and the problem still exists. If I removed the float: none, the problem does not occur:

/********************
*   Mobile Styles   *
********************/
@media only screen and (max-width: 850px) {
    body{
        background-color: yellow;
    }
    /* header
    ----------------------------------------------------------*/
    header .float-left,
    header .float-right {
        float: none;
    }
}
iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202

1 Answers1

-1

As the details provided, I will say the problem is with float only, Just update float and one more tag

.header .float-left{float:left;}
.header .float-right{float:right;}
.clearfix{clear:both}

Use this clearfix class with div below header div

<div class="header">
   //your codes
</div>
<div class="clearfix"></div>

I think this will do..

Edit : Ajaxify Update,

The script file of ajaxify has this code,

// Prepare Variables
        var contentSelector = '#content,article:first,.article:first,.post:first',
        $content = $(contentSelector).filter(':first'),
        contentNode = $content.get(0),
        $menu = $('#menu,#nav,nav:first,.nav:first').filter(':first'),
        activeClass = 'active selected current youarehere',
        activeSelector = '.active,.selected,.current,.youarehere',
        menuChildrenSelector = '> li,> ul > li',
        completedEventName = 'statechangecomplete',
        /* Application Generic Variables */
        $window = $(window),
        $body = $(document.body),
        rootUrl = History.getRootUrl(),
        scrollOptions = {
                duration: 800,
                easing:'swing'
        };

Now for clarification the CSS you have specified is not clashing with the CSS changed by ajaxify.js so there must be something that you are missing, I will say that AJAXIFY.js is not the one who is changing behavior of page, please post live link of your page or total work for more details.

Update: Large Razor Site.

If you have ajaxify large razor project, that will not change the behavior; Yes, it prepares strong html objects in MVC4 so if there is some standard ignores in the razor code or html page code or master page code. this will occur, I will stay with My Vote that Ajaxify does not change the behavior, its something else that is classifies under mobile site.

Update : Removing float

Removing float:none helps --> that prov that this is a float issue, that has not been taken care before this node..

I will like to add that simplify CSS to base page/master page which are commonly used, as the ajaxify calls the page and if the CSS of that razor page is not loaded then also this problem occur.

MarmiK
  • 5,639
  • 6
  • 40
  • 49
  • If you have Visual Studio, and follow the step by step instructions, there is certainly enough code :) Why does everyone want to correct the standard out-of-the-box CSS template instead of explaining why it is activating the media filter in the first place? Your answer is not an explanation and simply hides the problem. Thanks anyway. – iCollect.it Ltd Aug 28 '13 at 15:45
  • THis is due to float that is carried by nest element or sibling and creates a problem, thank you for comments. FYI: This does not hide problem this clear the problem. THis is a solution if you like.. I am not forcing you to accept. thank you again – MarmiK Aug 29 '13 at 03:45
  • *The question is:* What causes Ajaxify to fire CSS styles for a smaller resolution than what is actually displayed? Your answer does not explain that in any way, so I cannot accept it. Thanks anyway. – iCollect.it Ltd Aug 29 '13 at 08:24
  • I think you are still missing the point. Ajaxify does not create or change CSS that I am aware of. It simply loads page content, via Ajax, into relevant panels but that is somehow fooling the CSS interpretation into thinking the page is smaller than it is. If you can explain that, you certainly deserve the bounty, if not a down-vote is appropriate as your current answer is "not useful" for the question asked. – iCollect.it Ltd Aug 30 '13 at 08:41
  • I am not looking towards bounty, there are 200/300 bounties raised, I focus where I can help :) this is what I have explained, if not satisfying your question please provide details what is missing, I will try to justify further questions :) thank you – MarmiK Aug 30 '13 at 08:56
  • What is missing is an explanation of the actual problem. CSS workarounds do not explain why the CSS styles are activated when the CSS filter condition is not met i.e. `(max-width: 850px)` is firing when the screen is wider than 850px (but only if the content is loaded via Ajaxify). It is either a bug in the way Ajaxify loads the content, or a bug in CSS that allows floating headers to somehow adjust the screen width. – iCollect.it Ltd Aug 30 '13 at 10:27
  • @HiTechMagic Please provide live link of page that will help with details as I have demanded in past, the provided code is not sufficient to conclude the problem. So, Please provide code of generated page for more analysis to find actual reasons then only we can explain :) – MarmiK Aug 30 '13 at 11:16
  • *Demanded???* Thought you were here to help :) If you have Visual Studio 2012 then it is very easy to reproduce in about 3 minutes, following the detailed instructions provided *from the start*. If you do not have Visual Studio 2012 you would need the entire project, hosted on a website as it uses AJAXIFY loading. If you do not have VS 2012, you should not attempt to solve this problem :) – iCollect.it Ltd Aug 30 '13 at 16:07
  • I think I should not request for code, even if I have visual studio, the same generated code will not be available at my end although its easy, if you can provide generated code that will do the missing part.. – MarmiK Aug 31 '13 at 12:56