Do we have any option to disable the save and publish button available in umrbaco programmatically.?
If you don't want to modify the source, here's a down & dirty way to disable it using ApplicationBase to inject some jQuery:
public class RemoveToolbarButtons : ApplicationBase
{
public RemoveToolbarButtons()
{
umbracoPage.Load += new umbraco.presentation.masterpages.MasterPageLoadHandler(umbracoPage_Load);
}
void umbracoPage_Load(object sender, EventArgs e)
{
var page = (umbracoPage)sender;
if (page.Page.Request.Path.ToLower().Replace((GlobalSettings.Path + "/").ToLower(), "").Contains("editcontent.aspx"))
{
var currentDocId = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
Document d = new Document(currentDocId);
if (d.ContentType.Alias == "YourDocTypeAlias")
{
string s = #"<script type='text/javascript'>
$(document).ready(function() {
$('.editorIcon').each(function() { if(String($(this).attr('alt')) == 'Save and publish') {$(this).hide(); return false;} });
});
</script>";
page.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jshidetoolbar", s);
}
}
}
}
Change YourDocTypeAlias to the doctypealias where you want to disable it. Note this only hides the button using jQuery, the user may still have access to Publish via the context menu or other methods.
Minor tweak to Tom's approach - adjust the jQuery to not return false (otherwise it only hides the first 'Save and publish' button when you have multiple tabs)
string s = #"<script type='text/javascript'>
$(document).ready(function() {
$('.editorIcon').each(function() { if(String($(this).attr('alt')) == 'Save and publish') {$(this).hide(); } });
});
</script>";
The full-source code for Umbraco is available as an open source project, so yes, you can disable the save and publish (and do anything else you want).
Link
Related
I am trying to have a div show if an option is selected using the Select2 plug in.
I tried using the following code but it does not work:
$(document).ready(function() {
var h = $(".shipment-details--other-description");
$("#shipment-details-select-pacakage-types").change(function() {
if (this.checked && this.value == "Other") {
h.show();
} else {
h.hide();
}
}).change()
});
The div is being hid but not being shown if the Other option is selected.
Is there a different way to do this with Select2?
Edit: Forgot to mention that this a multiple select field. Also, adjusted the code and took out the this.checked as that was for a check field.
try to create a new css class, is-hidden{ display:none;}
$(document).ready(function() {
var h = $(".shipment-details--other-description");
$("#shipment-details-select-pacakage-types").change(function() {
if (this.checked && this.value == "Other") {
h.addClass('is-hidden');
} else {
h.removeClass('is-hidden');
}
}).change()
});
i have created a directive to handle selectable provided by Jquery
mydirectives.directive('uiSelectable', function ($parse) {
return {
link: function (scope, element, attrs, ctrl) {
element.selectable({
stop: function (evt, ui) {
var collection = scope.$eval(attrs.docArray)
var selected = element.find('div.parent.ui-selected').map(function () {
var idx = $(this).index();
return { document: collection[idx] }
}).get();
scope.selectedItems = selected;
scope.$apply()
}
});
}
}
});
to use in html
<div class="margin-top-20px" ui-selectable doc-array="documents">
where documents is an array that get returned by server in ajax response.
its working fine i can select multiple items or single item
Issue: i want to clear selection on close button
http://plnkr.co/edit/3cSef9h7MeYSM0cgYUIX?p=preview
i can write jquery in controller to remove .ui-selected class but its not recommended approach
can some one guide me whats the best practice to achieve these type of issue
Update:
i fixed the issue by broadcasting event on cancel and listening it on directive
$scope.clearSelection=function() {
$scope.selectedItems = [];
$timeout(function () {
$rootScope.$broadcast('clearselection', '');
}, 100);
}
and in directive
scope.$on('clearselection', function (event, document) {
element.find('.ui-selected').removeClass('ui-selected')
});
is this the right way of doing it or what is the best practice to solve the issue.
http://plnkr.co/edit/3cSef9h7MeYSM0cgYUIX?p=preview
I'm using jquery UI's tabs. When a user switches tabs, I'm checking for unsaved changes, and prompting the user accordingly. However, before the user even clicks Yes or No, the tab loads anyway. Does anyone know how I can get my function to NOT return anything until after the result has come back from my fancybox dialog?
You can see I've tried a couple of different methods to return my boolean value in CheckSomething().
$("#myTabs").tabs({
select:
function (event, ui) {
return CheckSomething();
},
show:
function (event, ui) {
//do some stuff
}
});
function CheckSomething() {
var loadMyTab = true; //If I set this to false, then it always returns false.
if (myCondition) {
//Show a FancyBox prompt.
if (fancyYes) {
//return true;
loadMyTab= true;
}
else {
//return false;
loadMyTab = false;
}
}
else {
//return true;
loadMyTab = true;
}
return loadMyTab;
}
With a standard confirm instead of a fancy is working can it be a fast solution? http://jsfiddle.net/nuywj/
I ended up going w/ a standard javascript confirm box instead of FancyBox. That solved my problem, because Confirm will block code from being executed:
function CheckSomething() {
if (myCondition) {
return confirm("Are you sure you want to change tabs without saving?");
}
else {
return true;
}
}
I would like to have a custom handler for the save button.
How can I override the default command?
The current top answer messed up the toolbar grouping for me (put the save button at the end), and the other answer did not work in ckeditor v4.
Here's how to do it in ckeditor 4:
html:
<textarea id="CKEditor1"></textarea>
javascript:
<script>
// Need to wait for the ckeditor instance to finish initialization
// because CKEDITOR.instances.editor.commands is an empty object
// if you try to use it immediately after CKEDITOR.replace('editor');
CKEDITOR.on('instanceReady', function (ev) {
// Create a new command with the desired exec function
var editor = ev.editor;
var overridecmd = new CKEDITOR.command(editor, {
exec: function(editor){
// Replace this with your desired save button code
alert(editor.document.getBody().getHtml());
}
});
// Replace the old save's exec function with the new one
ev.editor.commands.save.exec = overridecmd.exec;
});
CKEDITOR.replace('CKEditor1');
</script>
CKEDITOR.plugins.registered['save']=
{
init : function( editor )
{
var command = editor.addCommand( 'save',
{
modes : { wysiwyg:1, source:1 },
exec : function( editor ) {
//YOUR CODE
}
}
);
editor.ui.addButton( 'Save',{label : 'YOUR LABEL',command : 'save'});
}
}
If you want to override the save command for just one instance, you can try the following code:
var editor = $('#myTextarea').ckeditorGet(); // Retrieving CKeditor instance with jQuery
editor.getCommand('save').exec = function(editor) {
// Do whatever you need to
...
return true;
};
This should work for any CKEditor command.
function configureEditor(id) {
var editor = CKEDITOR.replace(id);
editor.on("instanceReady", function () {
// overwrite the default save function
editor.addCommand("save", {
modes: { wysiwyg: 1, source: 1 },
exec: function () {
// get the editor content
var theData = editor.getData();
alert("insert your code here");
}
});
editor.ui.addButton('Save', { label: 'My Save', command: 'save', enabled: 'true' });
var saveButton = $('#cke_' + id).find('.cke_button__save');
saveButton.removeClass('cke_button_disabled');
});
}
In CKEditor 4, the save plugin is meant to be cancelable. If unsure, one can always have a look at the source. You can cancel the event and apply your own logic in a handler, like in this example:
//assuming editor is a CKEDITOR.editor instance
editor.on('save', function (event) {
event.cancel();
//your custom command logic
//(you can access the editor instance through event.editor)
});
I would advise against creating a new command and replacing the default with it, as it is an unnecessary workaround.
Is anybody able to -execute- a generated Ajax.ActionLink when a user presses a key on the keyboard? (This is needed for accessibility)
NOTE: I'm using ASP.NET MVC + Microsoft Js libraries (...Ajax.js / ...MvcAjax.js) + jQuery
Javascript to capture keypress (IE + Firefox)
$(document).keypress(function(event) {
if(event.keyCode == 27) {
//execution here
var a = document.getElementById('linkid');
}
});
Html generated by ASP.NET MVC (Ajax.ActionLink())
<a id="linkid" href="/controller/action" onclick="
Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event),
{ insertionMode: Sys.Mvc.InsertionMode.replace,
updateTargetId: 'SomeDivId' });
">LinkText</a>
The following is not what i'm looking for, this doesn't work!
$(document).keypress(function(event) {
if(event.keyCode == 27) {
var a = document.getElementById('linkid');
a.onclick(); //doesn't exist in Firefox
a.click(); //doesn't "work" in Firefox (reference to "this" [a] is needed .NET MVC javascript)
a["onclick"](); //same as .onclick()
a["click"](); //same as .click()
//or even:
a.onclick.apply(a); //doesn't exist in Firefox
a.click.apply(a); //Somehow keeps "this" reference, but throws Sys.ArgumentUndefinedException
}
});
Have you tried using jQuery's trigger mechanism?
$(document).keypress( function(e) {
if (e.keyCode == 27) {
$(this).trigger('click');
}
}
Failing that, you could just invoke the href, which will do a full postback, but should accomplish the desired action if the action is written to handle both AJAX and non-AJAX requests.
$(document).keypress( function(e) {
if (e.keyCode == 27) {
location.href = $(this).attr('href');
}
}
Please Try this:
var a = document.getElementById('linkid');
$(a).trigger('click');