How to pass current index to fancybox iframe - iframe

I have a group of links that I call fancybox on with the arrows enabled so that the user can click next and prev. Each link is decorated with the iframe class and href='/editdata.aspx'. I would to remove the arrows and pass in the current index so that the editdata.aspx save button can say "save and next" until it reaches the last link, which will then say "save and close".
From editdata.aspx I use
var numLinks = $(".link-items", parent.document.body).children("a.iframe").size();
This gives me the total number of links. I just need to know the current link that is being displayed to the user so that I can update the save button text.
Here is a sample of my code in editdata.aspx:
// change the save button to save and next if fancybox is loading multiple links
if (parent.$.fancybox) {
var links = $(".links", parent.document.body);
if (links && links.length > 0) {
var numlinks = $(links).children("a.popup").size();
var index = getParameterByName('index');
if (index == numlinks ) {
// this element is the last item to display so change the "save and next" to "save and close"
$("#btnSave").val("Save & Close");
$("#btnSave").click(function () {
parent.$.fancybox.close();
});
}
else {
$("#btnSave").val("Save & Next");
$("#btnSave").click(function () {
parent.$.fancybox.next();
});
}
}
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
How can I achieve this?

Thats easy for v2 -
jQuery(".fancybox").fancybox({
beforeLoad : function() {
this.href = this.href + '?index=' + this.index;
}
});

Related

Full Calendar revert an external drop event

I'm a complete beginner regarding the Full Calendar, so apologies for a possible simple question.
I am trying to revert a drop from an External Event. If I use the revertFunc(), the event snaps back to it's original position in the list but the event is still on the calendar until it is refreshed. Ideally I would like it to disappear as soon as the dialog box is closed. This is the code
drop: function(date, jsEvent, ui, resourceId)
{
var tag = $(this).data('event').tag;
var eventDate = $(this).data('event').projectDate;
var calDate = date.format();
if (tag == PSTag)
{
if(eventDate != calDate)
{
alert('You must drop the event on the correct date');
revertFunc();
return;
}
var eventObjectId = $(this).data('event').schWork;
}
if (tag == WOTag)
{
var eventObjectId = $(this).data('event').workorder;
}
var title = $(this).data('event').title;
alert(tag);
updateCalendarEvent(eventObjectId, date.format(), resourceId, tag, title);
if (tag != PHTag)
{
$(this).remove();
}
setupDraggableEvents();
}
Many thanks for any assistance

redirect chrome users in new window

I have tried this but its not what I want ....
also this code does not works
<%= Html.ActionLink("Paypal", "HowItWorksRedirect", null, new { #class = "Paypal" })%>
public ActionResult HowItWorksRedirect()
{
return Redirect("https://www.paypal-deutschland.de/sicherheit/schutzprogramme.html");
}
I want to redirect all chrome users to new window
I want to keep users on my website but also redirect them to new window... (600x800 or something like this)
How can I do that?
Opening a new window (or tab, depending on browser settings) is easy:
With a link, you can use
LINK
Or you can use JS:
window.open('http://google.com', 'Google', 'width=800, height=600');
With the help of navigator.userAgent you can get the User Agent and use a regex to find out if the user is using Chrome
if(/Chrome/.test(navigator.userAgent)) { /* CHROME USER */ }
<script>
//specify page to pop-under
var popunder="http://wow.ge/"
//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0
///No editing beyond here required/////
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){
win2=window.open(popunder,"",winfeatures)
win2.blur()
window.focus()
}
if (once_per_session==0)
loadpopunder()
else
loadornot()
</script>
but browsers blocking that !

pop up div tag only once after successfull login

In my site am doing popup div with colorbox (in master page).my req is i want to popup this color box only once and that to after login only.
Hi , In my site am doing popup div with colorbox (in master page). its working fine. but i want to pop up this colorbox div after successfull login. this is also done. but my req is i want to popup this color box only once and that to after login only. so could u give any suggestion to find the page is loading firsttime or second time. not using (!ispostback concept in page load)
$(document).ready(function () {
var hfClose = $('#hfCloseColorbox').val();
var page = $(location).attr('pathname'); // index.php
if (page == '/Default.aspx') {
if (hfClose == '2') {
$.colorbox({ width: "32%", inline: true, href: "#DisplayChat" });
}
}
});
if (!IsPostBack)
{
if (hfCloseColorbox.Value == "")
hfCloseColorbox.Value = "2";
else if (ViewState["count"] == null)
hfCloseColorbox.Value = Convert.ToString(int.Parse(hfCloseColorbox.Value) + 1);
else if (ViewState["count"].ToString() == "1")
hfCloseColorbox.Value = Convert.ToString(int.Parse(ViewState["count"].ToString()) + 1);
hfCloseColorbox.Value = Convert.ToString(int.Parse(hfCloseColorbox.Value) + 1);
}
else
{
if (ViewState["count"] == null)
hfCloseColorbox.Value = Convert.ToString(int.Parse(hfCloseColorbox.Value) + 1);
else if (ViewState["count"].ToString() == "1")
hfCloseColorbox.Value = Convert.ToString(int.Parse(ViewState["count"].ToString()) + 1);
}
You can create own special variable within ViewState to determine if page is loaded for the first time (after login).
if (ViewState["Foo"] != null && ViewState["Foo"] == "True")
{
// Code for Pop-Up display
}
Only place that will assign value for ViewState["Foo"] is code after successful login.

creating a Placemarks that can be hidden

I have been trying to create a Placemark that I can hide and show (like turning visibility on and off) on demand (on click)... I am using this to make the placemark:
function placemark(lat, long, name, url, iconsrc){
var placemark = ge.createPlacemark(name);
ge.getFeatures().appendChild(placemark);
placemark.setName(name);
// Create style map for placemark
var icon = ge.createIcon('');
if(iconsrc == "0")
icon.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');
else{
icon.setHref(iconsrc);
}
var style = ge.createStyle('');
style.getIconStyle().setIcon(icon);
if(iconsrc != "0")
style.getIconStyle().setScale(2.5);
placemark.setStyleSelector(style);
// Create point
var point = ge.createPoint('');
point.setLatitude(lat);
point.setLongitude(long);
//point.setAltitudeMode(1500);
placemark.setGeometry(point);
google.earth.addEventListener(placemark, 'click', function(event) {
// Prevent the default balloon from popping up.
event.preventDefault();
var balloon = ge.createHtmlStringBalloon('');
balloon.setFeature(placemark); // optional
balloon.setContentString(
'<iframe src="'+ url +'" frameborder="0"></iframe>');
ge.setBalloon(balloon);
});
}
I have tried everything... from this:
function hidePlacemark(name){
var children = ge.getFeatures().getChildNodes();
for(var i = 0; i < children.getLength(); i++) {
var child = children.item(i);
if(child.getType() == 'KmlPlacemark') {
if(child.getId()== name)
child.setVisibility(false);
}
}
}
to using this ge.getFeatures().removeChild(child);
can anyone point me to the right direction on creating a function that will allow me to turn the visibility on/off on demand please.
Your hidePlacemark function is missing some {} in your final IF statement
if(child.getId()== name)
you have
function hidePlacemark(name){
var children = ge.getFeatures().getChildNodes();
for(var i = 0; i < children.getLength(); i++) {
var child = children.item(i);
if(child.getType() == 'KmlPlacemark') {
if(child.getId()== name)
child.setVisibility(false);
}
}
}
make it
function hidePlacemark(name){
var children = ge.getFeatures().getChildNodes();
for(var i = 0; i < children.getLength(); i++) {
var child = children.item(i);
if(child.getType() == 'KmlPlacemark') {
if(child.getId()== name) {
child.setVisibility(false);
}
}
}
}
HOWEVER ------- you are better off doing this as it is much faster as you don't need to loop through ALL your placemarks
function hidePlacemark(name) {
var placemark = ge.getElementById(name);
placemark.setVisibility(false);
}
I think the plain ge.getFeatures().removeChild(placemark); works.
I played with this GooglePlayground, and just added the following code to line 8 (that is empty in this GooglePlayground Sample):
addSampleButton('Hide Placemark', function(){
ge.getFeatures().removeChild(placemark);
});
Clicking the button Hide Placemark hides the placemark like a charm here. Any chances your problem is somewhere else in your code?

Show static non-clickable heading in AutoCompleteExtender list

I have an AutoCompleteExtender from the Ajax Control Toolkit. I need to have a heading in the dropdown list that shows how many items found, but it should not be selectable as an item.
I have tried this using jQuery, but even when I just add as a div, it is still selected as an item into the text box when I click on it:
function clientPopulated(sender, e) {
var completionList = $find("AutoCompleteEx").get_completionList();
var completionListNodes = completionList.childNodes;
for (i = 0; i < completionListNodes.length; i++) {
completionListNodes[i].title = completionListNodes[i]._value.split(':')[2];
}
var resultsHeader;
if(completionListNodes.length==1000)
resultsHeader = 'Max count of 1000 reached.<br/>Please refine your search.';
else if(completionListNodes.length>0)
resultsHeader = completionListNodes.length + ' hits.';
else
resultsHeader = msg_NoObjectsFound ;
jQuery(completionListNodes[0]).before('<div>' + resultsHeader + '</div>');
}
Add OnClientItemSelected and OnClientShowing events handlers and try script below:
function itemSelected(sender, args) {
if (args.get_value() == null) {
sender._element.value = "";
}
}
function clientShowing() {
var extender = $find("AutoCompleteEx");
var optionsCount = extender.get_completionSetCount();
var message = "";
if (optionsCount == 1000) {
message = 'Max count of 1000 reached.<br/>Please refine your search.';
}
else if (optionsCount > 0) {
message = optionsCount + " hits."
}
else {
message = "oops."
}
jQuery(extender.get_completionList()).prepend("<li style='background-color:#ccc !important;'>" + message + "</li>");
}
Added:
you even can do this without OnClientItemSelected handler:
function clientShowing() {
var extender = $find("AutoCompleteEx");
var oldSetText = extender._setText;
extender._setText = function (item) {
if (item.rel == "header") {
extender._element.value = "";
return;
}
oldSetText.call(extender, item);
};
var optionsCount = extender.get_completionSetCount();
var message = "";
if (optionsCount == 1000) {
message = 'Max count of 1000 reached.<br/>Please refine your search.';
}
else if (optionsCount > 0) {
message = optionsCount + " hits."
}
else {
message = "oops."
}
jQuery(extender.get_completionList()).prepend("<li rel='header' style='background-color:#ccc !important;'>" + message + "</li>");
}
We can give a better answer if you post the output html of your autocomplete control. Anyway if its a dropdown control;
jQuery(completionListNodes[0]).before('
<option value="-99" disabled="disabled">your message here</option>'
);
The answer by Yuriy helped me in solving it so I give him credit although his sollution needed some changes to work.
First of all, the clientShowing event (mapped by setting OnClientShowing = "clientShowing" in the AutoExtender control) is executed on initialization. Here we override the _setText method to make sure nothing happens when clicking on the header element. I have used the overriding idea from Yuriy's answer that really did the trick for me. I only changed to check on css class instead of a ref attribute value.
function clientShowing(sender, e) {
var extender = sender;
var oldSetText = extender._setText;
extender._setText = function (item) {
if (jQuery(item).hasClass('listHeader')) {
// Do nothing. The original version sets the item text to the search
// textbox here, but I just want to keep the current search text.
return;
}
// Call the original version of the _setText method
oldSetText.call(extender, item);
};
}
So then we need to add the header element to the top of the list. This has to be done in the clientPopulated event (mapped by setting OnClientPopulated = "clientPopulated" in the AutoExtender control). This event is executed each time the search results have been finished populated, so here we have the correct search count available.
function clientPopulated(sender, e) {
var extender = sender;
var completionList = extender.get_completionList();
var completionListCount = completionList.childNodes.length;
var maxCount = extender.get_completionSetCount();
var resultsHeader;
if(completionListCount == maxCount)
resultsHeader = 'Max count of ' + maxCount + ' reached.<br/>'
+ 'Please refine your search.';
else if(completionListCount > 0)
resultsHeader = completionListCount + ' hits.';
else
resultsHeader = 'No objects found';
jQuery(completionList).prepend(
'<li class="listHeader">' + resultsHeader + '</li>');
}
I have also created a new css class to display this properly. I have used !important to make sure this overrides the mousover style added from the AutoExtender control.
.listHeader
{
background-color : #fafffa !important;
color : #061069 !important;
cursor : default !important;
}

Resources