Mailing List Archive

Specify flypage using javascript or another non-database method
Hi all. I'm working an making IC5 site a bit more mobile friendly and so
far it's been fairly painless. Using javascript to redirect mobile
visitors to the mobile version of a page works well. But I now need a
way to make mobile visitors see a different flypage than non-mobile
visitors see.

PageSelectField looks like one way to change the flypage on a
per-product basis but that's not what I need here. Can anyone think of a
way to change the flypage using javascript or ome other non-database
method? Thanks for any ideas!

DB

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
Quoting DB (db@m-and-d.com):
> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
> far it's been fairly painless. Using javascript to redirect mobile
> visitors to the mobile version of a page works well. But I now need a
> way to make mobile visitors see a different flypage than non-mobile
> visitors see.
>
> PageSelectField looks like one way to change the flypage on a
> per-product basis but that's not what I need here. Can anyone think of a
> way to change the flypage using javascript or ome other non-database
> method? Thanks for any ideas!

Surely you can detect the presence of a mobile browser? If so,
you can easily do:

Sub change_fp <<EOR
sub {
return unless $Tag->is_mobile();
$Config->{SpecialPage}->{flypage} = 'mflypage';
return;
}
EOR

Autoload change_fp

--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.253.4194 <mike@perusion.com>

There is something fascinating about science. One gets such wholesale
returns of conjecture out of such a trifling investment of fact.
-- Mark Twain

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
>> far it's been fairly painless. Using javascript to redirect mobile
>> visitors to the mobile version of a page works well. But I now need a
>> way to make mobile visitors see a different flypage than non-mobile
>> visitors see.
>>
>> PageSelectField looks like one way to change the flypage on a
>> per-product basis but that's not what I need here. Can anyone think of a
>> way to change the flypage using javascript or ome other non-database
>> method? Thanks for any ideas!
>
> Surely you can detect the presence of a mobile browser? If so,
> you can easily do:
>
> Sub change_fp <<EOR
> sub {
> return unless $Tag->is_mobile();
> $Config->{SpecialPage}->{flypage} = 'mflypage';
> return;
> }
> EOR
>
> Autoload change_fp
>
> --
> Mike Heins
> Perusion -- Expert Interchange Consulting http://www.perusion.com/
> phone +1.765.253.4194 <mike at perusion.com>

Thanks - I'd been using something like below but I see other ways in the
archives that would probably work better with your example.

<script type="text/javascript">
<!--
if (screen.width <= 699) {
...
}
//-->
</script>

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
On 04/27/2015 07:10 AM, DB wrote:
>>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
>>> far it's been fairly painless. Using javascript to redirect mobile
>>> visitors to the mobile version of a page works well. But I now need a
>>> way to make mobile visitors see a different flypage than non-mobile
>>> visitors see.

> Thanks - I'd been using something like below but I see other ways in the
> archives that would probably work better with your example.
>
> <script type="text/javascript">
> <!--
> if (screen.width <= 699) {
> ...
> }
> //-->
> </script>

Using javascript is all well and good, but you do have to direct them
after the page is loaded and then load another page as a result. If you
use server-side code to detect the presence of a mobile based on the
UserAgent string then you can use Mike's code above to do it without
needing a redirect. I suggest using the HTTP::BrowserDetect module to
parse the useragent string for you. It has, among others, methods that
tell you if it's a mobile device and whether it's a tablet, etc.


Peter

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
Quoting Peter (peter@pajamian.dhs.org):
> On 04/27/2015 07:10 AM, DB wrote:
> >>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
> >>> far it's been fairly painless. Using javascript to redirect mobile
> >>> visitors to the mobile version of a page works well. But I now need a
> >>> way to make mobile visitors see a different flypage than non-mobile
> >>> visitors see.
>
> > Thanks - I'd been using something like below but I see other ways in the
> > archives that would probably work better with your example.
> >
> > <script type="text/javascript">
> > <!--
> > if (screen.width <= 699) {
> > ...
> > }
> > //-->
> > </script>
>
> Using javascript is all well and good, but you do have to direct them
> after the page is loaded and then load another page as a result. If you
> use server-side code to detect the presence of a mobile based on the
> UserAgent string then you can use Mike's code above to do it without
> needing a redirect. I suggest using the HTTP::BrowserDetect module to
> parse the useragent string for you. It has, among others, methods that
> tell you if it's a mobile device and whether it's a tablet, etc.

I think you can find the is_mobile tag in our repository, it is something
we use for the Strap catalog, I believe. If not, here it is:

UserTag is_mobile hasEndTag
UserTag is_mobile Routine <<EOR
use HTTP::BrowserDetect;
sub {
if(! defined $Vend::Session->{mobile_browser}) {
my $ua = HTTP::BrowserDetect->new($Vend::Session->{browser});
if($ua->mobile()) {
$Vend::Session->{mobile_browser} = 1;
}
else {
$Vend::Session->{mobile_browser} = 0;
}
}

return $Vend::Session->{mobile_browser}
? Vend::Interpolate::pull_if(shift (@_))
: Vend::Interpolate::pull_else(shift (@_) );
}
EOR


--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.253.4194 <mike@perusion.com>

Celebrate Diversity...
except veterans, small-business owners, practicing Catholics, gun
owners, talk-radio listeners, tea-party attendees, Texans, smokers, limited-
government proponents, pro-lifers, taxpayers, NASCAR fans, Boy Scouts,
oil-company employees, secure-border advocates, capitalists, global-
warming agnostics, Cuban refugees, school-choicers.. -- Peter Kirsanow

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
Quoting Mike Heins (mikeh@perusion.com):
> Quoting Peter (peter@pajamian.dhs.org):
> > On 04/27/2015 07:10 AM, DB wrote:
> > >>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
> > >>> far it's been fairly painless. Using javascript to redirect mobile
> > >>> visitors to the mobile version of a page works well. But I now need a
> > >>> way to make mobile visitors see a different flypage than non-mobile
> > >>> visitors see.
> >
> > > Thanks - I'd been using something like below but I see other ways in the
> > > archives that would probably work better with your example.
> > >
> > > <script type="text/javascript">
> > > <!--
> > > if (screen.width <= 699) {
> > > ...
> > > }
> > > //-->
> > > </script>
> >
> > Using javascript is all well and good, but you do have to direct them
> > after the page is loaded and then load another page as a result. If you
> > use server-side code to detect the presence of a mobile based on the
> > UserAgent string then you can use Mike's code above to do it without
> > needing a redirect. I suggest using the HTTP::BrowserDetect module to
> > parse the useragent string for you. It has, among others, methods that
> > tell you if it's a mobile device and whether it's a tablet, etc.
>
> I think you can find the is_mobile tag in our repository, it is something
> we use for the Strap catalog, I believe. If not, here it is:

From here:
https://github.com/perusion/interchange-extras/tree/master/mobile

--
Josh Lavin
Perusion -- Expert Interchange Consulting http://www.perusion.com/
... ask me about job opportunities ...

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
>> far it's been fairly painless. Using javascript to redirect mobile
>> visitors to the mobile version of a page works well. But I now need a
>> way to make mobile visitors see a different flypage than non-mobile
>> visitors see.
>>
>> PageSelectField looks like one way to change the flypage on a
>> per-product basis but that's not what I need here. Can anyone think of a
>> way to change the flypage using javascript or ome other non-database
>> method? Thanks for any ideas!
>
> Surely you can detect the presence of a mobile browser? If so,
> you can easily do:
>
> Sub change_fp <<EOR
> sub {
> return unless $Tag->is_mobile();
> $Config->{SpecialPage}->{flypage} = 'mflypage';
> return;
> }
> EOR
>
> Autoload change_fp
>
> --
> Mike Heins
> Perusion -- Expert Interchange Consulting http://www.perusion.com/
> phone +1.765.253.4194 <mike at perusion.com>

I got around to trying this finally. In my global directory I created
is_mobile.tag containing:

UserTag is_mobile hasEndTag
UserTag is_mobile Routine <<EOR
use HTTP::BrowserDetect;
sub {
if(! defined $Vend::Session->{mobile_browser}) {
my $ua =
HTTP::BrowserDetect->new($Vend::Session->{browser});
if($ua->mobile()) {
$Vend::Session->{mobile_browser} = 1;
}
else {
$Vend::Session->{mobile_browser} = 0;
}
}

return $Vend::Session->{mobile_browser}
? Vend::Interpolate::pull_if(shift (@_))
: Vend::Interpolate::pull_else(shift (@_) );
}
EOR


and then in my catalog.cfg I added:

Sub change_fp <<EOR
sub {
return unless $Tag->is_mobile();
$Config->{SpecialPage}->{flypage} = 'mflypage';
return;
}
EOR

Autoload change_fp

I restarted IC and it squawked about HTTP::BrowserDetect missing, so I
installed that using yum. But now in my catalog error log I get:

CAT /cgi-bin/CAT/index.html Died in server spawn: Can't locate object
method "mobile" via package "HTTP::BrowserDetect" at (eval 500) line 5.

Maybe the version of HTTP::BrowserDetect that yum (Centos 5) installed
is too old? Any other thoughts?

DB


_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
> I got around to trying this finally. In my global directory I created
> is_mobile.tag containing:
>
> UserTag is_mobile hasEndTag
> UserTag is_mobile Routine <<EOR
> use HTTP::BrowserDetect;
> sub {
> if(! defined $Vend::Session->{mobile_browser}) {
> my $ua =
> HTTP::BrowserDetect->new($Vend::Session->{browser});
> if($ua->mobile()) {
> $Vend::Session->{mobile_browser} = 1;
> }
> else {
> $Vend::Session->{mobile_browser} = 0;
> }
> }
>
> return $Vend::Session->{mobile_browser}
> ? Vend::Interpolate::pull_if(shift (@_))
> : Vend::Interpolate::pull_else(shift (@_) );
> }
> EOR
>
>
> and then in my catalog.cfg I added:
>
> Sub change_fp <<EOR
> sub {
> return unless $Tag->is_mobile();
> $Config->{SpecialPage}->{flypage} = 'mflypage';
> return;
> }
> EOR
>
> Autoload change_fp
>
> I restarted IC and it squawked about HTTP::BrowserDetect missing, so I
> installed that using yum. But now in my catalog error log I get:
>
> CAT /cgi-bin/CAT/index.html Died in server spawn: Can't locate object
> method "mobile" via package "HTTP::BrowserDetect" at (eval 500) line 5.
>
> Maybe the version of HTTP::BrowserDetect that yum (Centos 5) installed
> is too old? Any other thoughts?
>
> DB

I think it was just too old. I was able to manually install the current
version and the warning went away. So now I can test to see if the
detection works.

DB

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
Quoting DB (db@m-and-d.com):
> > I got around to trying this finally. In my global directory I created
> > is_mobile.tag containing:
> >
[snip]

Something else you might be interested in:

https://github.com/perusion/interchange-extras/tree/master/mobile

--
Josh Lavin
Perusion -- Expert Interchange Consulting http://www.perusion.com/
... ask me about job opportunities ...

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> > I got around to trying this finally. In my global directory I created
>> > is_mobile.tag containing:
>> >
> [snip]
>
> Something else you might be interested in:
>
> https://github.com/perusion/interchange-extras/tree/master/mobile
>
> --
> Josh Lavin
> Perusion -- Expert Interchange Consulting http://www.perusion.com/
> ... ask me about job opportunities ...

Thanks - looks useful!

DB

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> > I got around to trying this finally. In my global directory I created
>> > is_mobile.tag containing:
>> >
> [snip]
>
> Something else you might be interested in:
>
> https://github.com/perusion/interchange-extras/tree/master/mobile
>
> --
> Josh Lavin
> Perusion -- Expert Interchange Consulting http://www.perusion.com/
> ... ask me about job opportunities ...

I'm making some progress but having an issue getting this to fully work.

I added the code from
https://github.com/perusion/interchange-extras/blob/master/mobile/i/usertag/is_mobile.tag
into a file named is_mobile.tag in my global directory which in included
from my catalog.cfg. I also added

Autoload [handle-mobile]

to my catalog.cfg and restarted IC.

I can tell the is_mobile code works because I added to my pages/index.html:

[is_mobile]YO[/is_mobile]

and I indeed see YO if I visit my page from a phone or use a browser
plugin to change my user agent string.

But the automatic redirects don't seem to work. I have a directory
pages/m and in there I have index.html and flypage.html. Both of these
pages load as expected if I directly visit domain.com/m/index.html or
domain.com/m/flypage.html

If I add to my pages/index.html:

[is_mobile]
[bounce page="m/[var MV_PAGE 1]" status="301 Permanent Redirect"]
[/is_mobile]

that works. If I add to my catalog.cfg:

Specialpage flypage m/flypage

that works. I also tried Mike's simpler version from
http://www.icdevgroup.org/pipermail/interchange-users/2015-April/054897.html
but that also doesn't work. If anyone has ideas to help me debug I'd be
grateful.

DB



_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>>> > I got around to trying this finally. In my global directory I
>>> > created is_mobile.tag containing:
>>> >
>> [snip]
>>
>> Something else you might be interested in:
>>
>> https://github.com/perusion/interchange-extras/tree/master/mobile
>>
>> --
>> Josh Lavin
>> Perusion -- Expert Interchange Consulting http://www.perusion.com/
>> ... ask me about job opportunities ...
>
> I'm making some progress but having an issue getting this to fully work.
>
> I added the code from
>
https://github.com/perusion/interchange-extras/blob/master/mobile/i/usertag/
is_mobile.tag
> into a file named is_mobile.tag in my global directory which in included
from my catalog.cfg. I also added
>
> Autoload [handle-mobile]
>
> to my catalog.cfg and restarted IC.
>
> I can tell the is_mobile code works because I added to my
pages/index.html:
>
> [is_mobile]YO[/is_mobile]
>
> and I indeed see YO if I visit my page from a phone or use a browser
plugin to change my user agent string.
>
> But the automatic redirects don't seem to work. I have a directory pages/m
and in there I have index.html and flypage.html. Both of these pages load as
expected if I directly visit domain.com/m/index.html or
domain.com/m/flypage.html
>
> If I add to my pages/index.html:
>
> [is_mobile]
> [bounce page="m/[var MV_PAGE 1]" status="301 Permanent Redirect"]
[/is_mobile]
>
> that works. If I add to my catalog.cfg:
>
> Specialpage flypage m/flypage
>
> that works. I also tried Mike's simpler version from
http://www.icdevgroup.org/pipermail/interchange-users/2015-April/054897.html
> but that also doesn't work. If anyone has ideas to help me debug I'd be
grateful.
>
> DB

In the github code I see logDebug lines, have you uncommented those to
actually see those values written in the log as well? That would give me
more a feeling that 'it works' than printing of 'YO'.

Other than that I don't have any ideas, it's late :)

CU,

Gert



_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users


_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
> I also tried Mike's simpler version from
> http://www.icdevgroup.org/pipermail/interchange-users/2015-April/054897.html
>> but that also doesn't work. If anyone has ideas to help me debug I'd be
> grateful.
>>
>> DB
>
> In the github code I see logDebug lines, have you uncommented those to
> actually see those values written in the log as well? That would give me
> more a feeling that 'it works' than printing of 'YO'.
>
> Other than that I don't have any ideas, it's late :)
>
> CU,
>
> Gert

Yes I saw that too and un-commented them. Two things I notice is that an
second .html gets added. Also I see a Safe warning which maybe prevents
the sub from working (I saw on RTFM site "Website-specific subroutines
may not perform unsafe operations").

Use of uninitialized value in eval "string" at (eval 849) line 1.
Use of uninitialized value in eval "string" at (eval 849) line 1.
Use of uninitialized value in eval "string" at (eval 849) line 1.
Vend::Interpolate:debug: FinalPath is: /SKU.html
Vend::Interpolate:debug: path is:
/home/user/catalogs/CAT/pages/SKU.html.html
Vend::Interpolate:debug: found special page
Safe: syntax error at (eval 858) line 1, near ">"

>0

Safe: syntax error at (eval 858) line 1, near ">"

>0

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
> Use of uninitialized value in eval "string" at (eval 849) line 1.
> Use of uninitialized value in eval "string" at (eval 849) line 1.
> Use of uninitialized value in eval "string" at (eval 849) line 1.
> Vend::Interpolate:debug: FinalPath is: /SKU.html
> Vend::Interpolate:debug: path is:
> /home/user/catalogs/CAT/pages/SKU.html.html


I noticed that if I comment the line

for($path, $mpath) {
s:(/|index/?)$:/index:;
# s:(?!\.html)$:.html:;
}

from the is_mobile tag, the redirect to m/index.html starts to work. So
maybe I'm onto something with this second .html getting added.

DB

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> >
> [snip]
>
> Something else you might be interested in:
>
> https://github.com/perusion/interchange-extras/tree/master/mobile
>
> --
> Josh Lavin


I'm slowly making progress with this. As I mentioned previously, if I
comment the line

for($path, $mpath) {
s:(/|index/?)$:/index:;
# s:(?!\.html)$:.html:;
}

Then the redirect to pages/m/index.html works. However despite the
presence of pages/m/flypage.html, I'd still always get the default
pages/flypage.html on a product page.

The debug log suggested that that again an extra .html may be to blame.
So I added a line to is_mobile:

## send to 'm/flypage', if a sku in products
$fp =~ s{\.[^.]+$}{}; # <-Added this to line to remove extension
my $sku = dbref($Vend::Cfg->{ProductFiles
[0])->record_exists(substr($fp, 1));

And then the mobile flypage started to work. But instead of actually
using this hacked-up code, I thought I'd see if anyone here has any
words of wisdom, and any would be welcomed.

DB



_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
Quoting DB (db@m-and-d.com):
> >> >
> > [snip]
> >
> > Something else you might be interested in:
> >
> > https://github.com/perusion/interchange-extras/tree/master/mobile
> >
> > --
> > Josh Lavin
>
>
> I'm slowly making progress with this. As I mentioned previously, if I
> comment the line
>
> for($path, $mpath) {
> s:(/|index/?)$:/index:;
> # s:(?!\.html)$:.html:;
> }
>
> Then the redirect to pages/m/index.html works. However despite the
> presence of pages/m/flypage.html, I'd still always get the default
> pages/flypage.html on a product page.
>
> The debug log suggested that that again an extra .html may be to blame.
> So I added a line to is_mobile:
>
> ## send to 'm/flypage', if a sku in products
> $fp =~ s{\.[^.]+$}{}; # <-Added this to line to remove extension
> my $sku = dbref($Vend::Cfg->{ProductFiles
> [0])->record_exists(substr($fp, 1));
>
> And then the mobile flypage started to work. But instead of actually
> using this hacked-up code, I thought I'd see if anyone here has any
> words of wisdom, and any would be welcomed.

I think the is_mobile tag was developed for a catalog with "Scratch
mv_add_dot_html" set to "0", but I was under the impression it would
work either way.

Perhaps not. I would be interested what your catalog uses for this
setting -- it may be that you have found a bug.

--
Josh Lavin
End Point Corporation

_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users
Re: Specify flypage using javascript or another non-database method [ In reply to ]
>> I'm slowly making progress with this. As I mentioned previously, if I
>> comment the line
>>
>> for($path, $mpath) {
>> s:(/|index/?)$:/index:;
>> # s:(?!\.html)$:.html:;
>> }
>>
>> Then the redirect to pages/m/index.html works. However despite the
>> presence of pages/m/flypage.html, I'd still always get the default
>> pages/flypage.html on a product page.
>>
>> The debug log suggested that that again an extra .html may be to blame.
>> So I added a line to is_mobile:
>>
>> ## send to 'm/flypage', if a sku in products
>> $fp =~ s{\.[^.]+$}{}; # <-Added this to line to remove extension
>> my $sku = dbref($Vend::Cfg->{ProductFiles
>> [0])->record_exists(substr($fp, 1));
>>
>> And then the mobile flypage started to work. But instead of actually
>> using this hacked-up code, I thought I'd see if anyone here has any
>> words of wisdom, and any would be welcomed.
>
> I think the is_mobile tag was developed for a catalog with "Scratch
> mv_add_dot_html" set to "0", but I was under the impression it would
> work either way.
>
> Perhaps not. I would be interested what your catalog uses for this
> setting -- it may be that you have found a bug.
>
> --
> Josh Lavin
> End Point Corporation

Hi Josh - thanks for the reply. Spiffy new sig you've got there! My
catalog has
ScratchDefault mv_add_dot_html 1

DB


_______________________________________________
interchange-users mailing list
interchange-users@icdevgroup.org
http://www.icdevgroup.org/mailman/listinfo/interchange-users