0

the below script doenst work unless the page is in edit mode..how can I resolve this ? I have it put on a CEWP underneath the sharepoint calendar it is handling

the goal of the script is to have the title displayed on the calendar cells as hyperlinks, open the display form in a dialog form instead of that:

    <script src="https://stackoverflow.com/jquery-1.9.1.js"></script> 
    <script type="text/javascript">   
    function openDialogBox(Url)  

    {    
    var ModalDialogOptions = { url:Url, width: 600, height: 500, showClose: true, allowMaximize:   true};     

    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', ModalDialogOptions); 

} 
    $('.ms-acal-month').ready(function () {  
    setTimeout(function() { 

$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('onclick', 'openDialogBox("' +  $(this).attr('href') + '")'); 

//$(this).attr('onclick', ' '); 

//alert($(this).attr('href')); 

}); 


$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('href','javascript:openDialogBox("' +  $(this).attr('href') + '")'); 

}); 

}, 3000); 

}); 
    </script>
2
  • And how does it behave in display mode? does it display an error? IS there any message in the console? Commented Oct 25, 2013 at 8:44
  • no errors, it just behaves as if no script is inserted in the CEWP Commented Oct 25, 2013 at 9:27

2 Answers 2

0

I think you should be calling $(document).ready(function()... instead of $('.ms-acal-month').ready(function().... .ready() doesn't work on specific elements.

The edit mode is probably loading the CEWP after the DOM is ready, or even just after the links are ready, which is why it works there.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the feedback Benjamin..unfortuntaley I just tried the $(document).ready(function() and is still can't have the script execute outside of the edit mode
Can you clarify what you're actually trying to do? It sounds like you're trying to replicate existing functionality i.e. clicking on a calendar event and having it display in a dialog == default functionality of SharePoint. Unless, of course, you're trying to have the Calendar list itself behave in one way, and your custom calendar page behave differently (non-dialog, and dialog, respectively)?
I have enabled the open in dialog option on the list properties, and it is working fine , as long as the user clicks inside the cell of the event..However, because the event displays the title as a hyperlink, users have the tendency to click on that hyperlink instead of the cell space..in which case the event is opened in a whole window instead of the dialog one..(I don't mind this behavior in itself as a UI , but I need the dialog to be opened at all times, because the script that I have on the default display page for some reason doesn't seem to work unless the event is viewed from a dialog
I'm not quite sure what your setup is. Are you displaying as a list instead of a calendar view? i.e. like the "All Events" view? I'm not sure what you mean by "clicks inside the cell of the event"? So, I guess I'm asking which view are you using? I wish I could see your set up! SharePoint can be very finicky.
i know, it has been messing wit me lately :w I am on the calendar view, and in calendar view you can choose an attribute to be displayed on the calendar , in my case that's the title..and because it's hyperlinked people click on it instead of the empty space of the cell in which it belongs..and wich does open the default display form with the script i ave on it being properly executed....I will try to disable the minimum download strategy , as i am on SharePoint 2013..although i have been avoiding to do that as it's not recommended
|
0

One of the SharePoint JavaScript file (CMSSiteManager.js) redefined the $ object and can conflict with jQuery.

This file is not always registered on the page. Maybe in your case, this is registered only in edit mode (typically when you have an asset selector).

There is, fortunately, possible workarounds.

Let's say your current js code is:

$(function(){
    $(".someclass").hide();
});

1. Use the explicit jQuery call

Transform your code to use directly the jQuery object, instead of the $ alias:

jQuery(function(){
    jQuery(".someclass").hide();
});

This is easy, but you loos some readability (as we are all used to see the $ alias).

2. Use a self contained function, with a local $

Use this code:

(function($){
    $(function(){
        $(".someclass").hide();
    });
})(jQuery);

This code creates a closure waiting for the local $ parameter. This parameter is fed with the actual jQuery object.

I love this technique because you can avoid conflict and still use the $ alias (actually it's no more the alias, but a local parameter).

PS: this applis to SP2010... I don't know for SP2013

1 Comment

Thank you Steve...Looks like it wasn't the problem as I still have the script only working on edit mode..i am still reluctant to deactivate the Minimum download strategy..i guess still try to make oit work then, see of the MDT is the problem. as i don't know what to expect after deactivating it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.