This is a migrated thread and some comments may be shown as answers.

Bug + Fix: error in Ajaxed Window content

10 Answers 99 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
frederic rybkowski
Top achievements
Rank 1
frederic rybkowski asked on 24 Mar 2011, 11:43 AM
Hi,

I use opensource telerik mvc extensions...
... so this post will be ignored by Telerik Team.


ther is a bug in telerik.window.js (2010.3.1318) : 
replace
    function isLocalUrl(url) {
        var loweredUrl = url ? url.toLowerCase() : '';
        return loweredUrl && loweredUrl.indexOf('http') !== 0 && loweredUrl.indexOf('https') !== 0;
    }
with     function isLocalUrl(url) {         var loweredUrl = url ? url.toLowerCase() : '';         return loweredUrl && (loweredUrl.indexOf('http') !== 0 || loweredUrl.indexOf('https') !== 0);     } Thanks for the reading... - Frederic.

10 Answers, 1 is accepted

Sort by
0
frederic rybkowski
Top achievements
Rank 1
answered on 24 Mar 2011, 01:58 PM


<script type="text/javascript">
   function EditClick(ev1) {
        // alert("click");
        var ev = stopEvent(ev1);
  
        var windowElement = $.telerik.window.create({
          
            title: "Form",
            html: '',
            contentUrl: ev.srcElement.href,
            modal: true,
            resizable: true,
            draggable: true,
            onClose: function (e) {
                e.preventDefault();
                windowElement.destroy();
                GridRebind('Vendors');
            },
            onRefresh: function (e) {
                windowElement.center();
            }
  
        }).data('tWindow');
  
        windowElement.center().open();
    }
 
function GridRebind(gridname) {
    var Grid = $('#' + gridname).data('tGrid');
    Grid.rebind();
}
 
function stopEvent(e) {
    if (!e) var e = window.event;
  
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = false;
  
    //e.stopPropagation works only in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
    return e;
}
  
</script>



in the grid for example the link to activate :

.ClientTemplate(
Html.ActionLink("Edit", MVC.Bid.ActionNames._editBidVendor, MVC.Bid.Name,
new
{
Id = "<#=Id#>"
},
new
{
@onclick = "EditClick()",
@class = "t-grid-action t-button t-state-default btnEdit"
}).ToString()
)

- Frederic
0
Alex Gyoshev
Telerik team
answered on 24 Mar 2011, 02:07 PM
Hello Frederic,

Thank you for reporting this, we fixed it right away. The following code is a more robust solution, as it will catch protocols different than http(s) and protocol-less URLs:
    function isLocalUrl(url) {
        return url && !(/^([a-z]+:)?\/\//i).test(url);
    }


Your Telerik points have been updated for the bug report and the provided work-around.

Kind regards,
Alex Gyoshev
the Telerik team
0
frederic rybkowski
Top achievements
Rank 1
answered on 24 Mar 2011, 02:21 PM
Wow !
My First answer !

Thank you Alex !

Since I have your attention.... :)
can you have a look to this, or follow to somebody else (GridBindingSettings bug or limitation) :
http://www.telerik.com/community/forums/aspnet-mvc/grid/loadcontentfrom-ajax-binding-with-infinite-nested-grid-tabstrip.aspx#1563013

thank you in advance !
0
Atanas Korchev
Telerik team
answered on 24 Mar 2011, 03:38 PM
Hello frederic rybkowski,

 I just replied to your forum thread. By the way Telerik does not guarantee replies to forum threads. 

Regards,
Atanas Korchev
the Telerik team
0
frederic rybkowski
Top achievements
Rank 1
answered on 25 Mar 2011, 01:44 PM
You mean :

    function isLocalUrl(url) {
            return url && url.match(/^([a-z]+:)?\/\//);
    }
0
frederic rybkowski
Top achievements
Rank 1
answered on 14 Jul 2011, 01:46 PM
Hi Alex,
Still incorrect in 2011.2.712
As I mention previously, the code in telerik.window.js (line 6) should be :

   function isLocalUrl(url) {
        return url && url.match(/^([a-z]+:)?\/\//);
    }

Thank you.
- Frédéric
0
Alex Gyoshev
Telerik team
answered on 15 Jul 2011, 09:35 AM
Hello Frederic,

What is incorrect about the current code? Please clarify with an example.

Greetings,
Alex Gyoshev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
frederic rybkowski
Top achievements
Rank 1
answered on 15 Jul 2011, 12:48 PM

Actual isLocalUrl will always return false when url string starts with a protocol ( "http:" "https:"...)

    function isLocalUrl(url) {
        return url && !(/^([a-z]+:)?\/\//i).test(url); // need to remove "!"
    }


To work it should be :

    function isLocalUrl(url) {
        return url && (/^([a-z]+:)?\/\//i).test(url);
    }


- Frédéric
0
Alex Gyoshev
Telerik team
answered on 15 Jul 2011, 12:58 PM
Hi Frederic Rybkowski,

Indeed, that is the point. if the URL has a protocol specified, it is not considered local (i.e. http://google.com/). This approach has the drawback that it doesn't try to parse fully qualified URLs, but it is uncommon for the framework to generate such URLs. In your example, instead of calling the method with ev.srcElement.href, call it with ev.srcElement.getAttribute("href", 2) to get the relative URL that was generated.

Kind regards,
Alex Gyoshev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
frederic rybkowski
Top achievements
Rank 1
answered on 15 Jul 2011, 01:58 PM
I replaced ev.srcElement.href with ev.srcElement.getAttribute("href", 2) and it works as expected !
I based my comments on initial version : It seemed to search for protocol, either "http" or "https"... I thought this way we ensure that this is a true url... ...initially...     function isLocalUrl(url) {         var loweredUrl = url ? url.toLowerCase() : '';         return loweredUrl && loweredUrl.indexOf('http') !== 0 && loweredUrl.indexOf('https') !== 0;     } ... thx for the reply. - Frédéric
Tags
Window
Asked by
frederic rybkowski
Top achievements
Rank 1
Answers by
frederic rybkowski
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Atanas Korchev
Telerik team
Share this question
or