AngularJS- button not displaying on widget 'toolbar' - javascript

I have an angularJS app, and on one of the pages, there are a number of widgets displayed. When the user click a 'Settings' button on that page (the button is separate to the widgets), the 'toolbar' for each widget is displayed on the widgets, with a number of buttons on each one (different buttons depending on which widget the toolbar belongs to).
I am currently trying to add a new button to the widget toolbars, which would take the user to the relevant page that each widget is showing information from.
The directive in which the widgets' HTML is rendered is:
.directive('umwWizard', function($q, $route, $modal, $timeout, $compile, ultUI,
umWidget, DialogMgr) {
var wizardTmpl = '<section ng-click="addWidget($event)" ' +
'class="glyphicon-clickable"><div data-ng-hide="swapTo != undefined">' +
'<span class="ti-widget"></span><p data-i18n="Click to add an item">' +
'</p></div></section>';
// Overlay editing panel template
var editPanelTmpl = '<div class="widget-preview-edit-panel">' +
'<span class="glyphicon glyphicon-transfer glyphicon-clickable" ' +
'data-ng-click="toggleSwapMode()" ' +
'data-ng-hide="!swap() || swapTo != undefined"></span>' +
'<span class="glyphicon glyphicon-cog glyphicon-clickable" ' +
'data-ng-click="editWidget()" ' +
'data-ng-hide="swapMode || swapTo != undefined"></span>' +
'<span class="glyphicon glyphicon-remove glyphicon-clickable"' +
' data-ng-click="deleteWidget()" ' +
'data-ng-hide="swapMode || swapTo != undefined"></span></div>'; /* +
/*ERF(28/07/2017 # 1030) Add 'naviateToPage' button to the widget toolbar
'<span class="ti-layers" ' +
'data-ng-click="goToWidgetRoot()" ' +
'data-ng-hide="swapMode || swapTo != undefined"></span></div>'; */
// Swap me button template
var swapMeBtnTmpl = '<button type="button" data-ng-click="swapMe()" ' +
'class="btn btn-sm btn-w-sm btn-gap-v btn-round wiz-swap-me" ' +
'data-ng-show="swapTo != undefined"><span data-i18n="Swap with me" ' +
'data-ng-show="swapTo != region"></span><span data-i18n="Cancel" ' +
'data-ng-show="swapTo == region"></span></button>';
return {
restrict: 'E',
// functions defined here
...
})
When I 'inspect' the toolbar element of one of the widgets when viewing the page in a browser, I can see that the toolbar icons are displayed by the section underneath the comment:
Overlay editing panel template.
I tried adding in the markup for the button that I want to add to the widget toolbar:
'<span class="glyphicons glyphicons-more-windows">' +
'data-ng-click="goToWidgetRoot()" ' +
'data-ng-hide="swapMode || swapTo != undefined"></span>' +
But for some reason, when I now view the page in the browser, the button that I've added to the widget toolbar is not displayed.
When I 'inspect' the toolbar in the browser, I can see the markup for the other buttons that were already there, but can't see the markup for the button that I've added...
Can anyone tell me why this is? What am I doing wrong here?

I'm unsure if your copypaste of the snippet for the button being added is accurate to what you intended to put on here, but it looks like you're closing the span prematurely in the first line.
It looks like it should be:
'<span class="glyphicons glyphicons-more-windows" ' +
'data-ng-click="goToWidgetRoot()" ' +
'data-ng-hide="swapMode || swapTo != undefined"></span>' +

Related

Why is this regex replace function creating line breaks in my html body?

I want to replace hashtags in the body of an html page with a Bootstrap4 Modal.
Sometimes, this function causes line breaks right after the replaced text link. Sometimes it doesn't. I don't understand why.
function replaceBlank() {
document.body.innerHTML = document.body.innerHTML.replace(/#blank/g, '' +
'<a data-target="#blankMod" data-toggle="modal" href="#">' +
'Blank' +
'</a>' +
'<div class="modal fade" id="blankMod">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<h4 class="modal-title">' +
'Blank' +
'</h4>' +
'<button type="button" class="close" data-dismiss="modal">' +
'x' +
'</button>' +
'</div>' +
'<div class="modal-body">' +
'Blank Text Body' +
'</div>' +
'</div>' +
'</div>' +
'</div>');
}
Do you ever run it more than once on the same page?
The text you are inserting contains the string you are replacing (the data-target="#blankMod" bit).
You are using the /g flag, so multiple replaces in one step will still work fine; but the second time you call it, it is bound to go a bit crazy.
If that is the problem, you could either stop using that data-target name, or you could capture a bit more context of where "#blank" appears in your document. (lookbehind/lookahead regex asserts are ideal for this, but require the latest versions of JavaScript, so may give browser compatibility issues.)
I discovered that the line breaks only occurred within paragraph <p> tags.
The replacement text was ending the <p> tag, and everything after it was considered a new paragraph.

How to get URL from current active Browser window/tab from within a script running in an XUL <browser> (e.g. in a sidebar)

I am creating a simple bootstrapped add-on for Firefox. I need to capture the current URL from the browser through sidebar with a button click.
My bootstrap.js:
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
/*start - windowlistener*/
var windowListener = {
//DO NOT EDIT HERE
onOpenWindow: function (aXULWindow) {
// Wait for the window to finish loading
let aDOMWindow =aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal||Ci.nsIDOMWindow);
aDOMWindow.addEventListener("load", function () {
aDOMWindow.removeEventListener("load", arguments.callee, false);
windowListener.loadIntoWindow(aDOMWindow, aXULWindow);
}, false);
},
onCloseWindow: function (aXULWindow) {},
onWindowTitleChange: function (aXULWindow, aNewTitle) {},
register: function () {
// Load into any existing windows
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
windowListener.loadIntoWindow(aDOMWindow, aXULWindow);
}
// Listen to new windows
Services.wm.addListener(windowListener);
},
unregister: function () {
// Unload from any existing windows
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
windowListener.unloadFromWindow(aDOMWindow, aXULWindow);
}
//Stop listening so future added windows dont get this attached
Services.wm.removeListener(windowListener);
},
//END - DO NOT EDIT HERE
loadIntoWindow: function (aDOMWindow, aXULWindow) {
if (!aDOMWindow) {
return;
}
//START - EDIT BELOW HERE
var browser = aDOMWindow.document.querySelector('#browser')
if (browser) {
var splitter = aDOMWindow.document.createElement('splitter');
var propsToSet = {
id: 'demo-sidebar-with-html_splitter',
//I'm just copying what Mozilla does for their social sidebar splitter
// I left it out, but you can leave it in to see how you can style
// the splitter
class: 'sidebar-splitter'
}
for (var p in propsToSet) {
splitter.setAttribute(p, propsToSet[p]);
}
var sidebar = aDOMWindow.document.createElement('vbox');
var propsToSet = {
id: 'demo-sidebar-with-html_sidebar',
//Mozilla uses persist width here, I don't know what it does and can't
// see it how makes a difference so I left it out
//persist: 'width'
}
for (var p in propsToSet) {
sidebar.setAttribute(p, propsToSet[p]);
}
var htmlVal = loadJsonHTML(0);
var sidebarBrowser = aDOMWindow.document.createElement('browser');
var propsToSet = {
id: 'demo-sidebar-with-html_browser',
type: 'content',
context: 'contentAreaContextMenu',
disableglobalhistory: 'true',
tooltip: 'aHTMLTooltip',
autoscrollpopup: 'autoscroller',
flex: '1', //do not remove this
//you should change these widths to how you want
style: 'min-width: 14em; width: 18em; max-width: 36em;',
//or just set this to some URL like http://www.bing.com/
src: 'data:text/html,'+ htmlVal
}
for (var p in propsToSet) {
sidebarBrowser.setAttribute(p, propsToSet[p]);
}
browser.appendChild(splitter);
sidebar.appendChild(sidebarBrowser);
browser.appendChild(sidebar);
}
//END - EDIT BELOW HERE
},
unloadFromWindow: function (aDOMWindow, aXULWindow) {
if (!aDOMWindow) {
return;
}
//START - EDIT BELOW HERE
var splitter = aDOMWindow.document
.querySelector('#demo-sidebar-with-html_splitter');
if (splitter) {
var sidebar = aDOMWindow.document
.querySelector('#demo-sidebar-with-html_sidebar');
splitter.parentNode.removeChild(splitter);
sidebar.parentNode.removeChild(sidebar);
}
//END - EDIT BELOW HERE
}
};
/*end - windowlistener*/
function startup(aData, aReason) {
windowListener.register();
}
function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN) return;
windowListener.unregister();
}
function loadJsonHTML(val=0){
var fileContent = "";
var localFile = Cc["#mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
//full path is okay if directory exists
localFile.initWithPath("/Users/tinuy/Desktop/test_addodn/input.txt");
//otherwise specify directory, create it if necessary, and append leaf.
//localFile.initWithPath("C:\Users\tinuy\Documents\test\input.txt");
if ( localFile.exists() == false ) {
fileContent = "File does not exist";
}
var istream = Cc["#mozilla.org/network/file-input-stream;1"]
.createInstance(Ci.nsIFileInputStream);
istream.init(localFile, 0x01, 4, null);
var fileScriptableIO = Cc["#mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
fileScriptableIO.init(istream);
// parse the XML into our internal document
istream.QueryInterface(Ci.nsILineInputStream);
//fileContent = fileScriptableIO.read( '1' );
var csize = 0;
while ((csize = fileScriptableIO.available()) != 0) {
fileContent += fileScriptableIO.read( csize );
}
var array = fileContent.split("&");
fileScriptableIO.close();
istream.close();
return makeHTML(array[val], val);
}
function makeHTML(value, key){
var arrValues = value.split(",");
var htmlContent = '<div name="content" class="content">' +
'<p> Name :' + arrValues[0] + '</p>';
htmlContent += '<p> Price :' + arrValues[2] + '</p>';
htmlContent += '<p> Color :' + arrValues[3] + '</p>';
htmlContent += '<p> UID :' + arrValues[1] + '</p>';
htmlContent += '<p><input type="radio" name="valid" value="yes" />Yes ' +
'<input type="radio" name="valid" value="no" /> No</p>' +
'<p><input type="text" placeholder="Reason" name="checkreason"></p>' +
'<p><input type="text" placeholder="Feedback" name="feedback"></p>' +
'</div><div><button name="load" type="button" id="loadit" onclick="loadHtml()" ' +
'loadurl="'+arrValues[4]+'">Load</button> <button name="save" type="button">' +
'Save </button> <button name="next" type="button" key="'+key+'">Next </button> ' +
'</div> <script> function loadHtml() {' +
'var a = gBrowser.contentWindow.location.href ;alert(a);' +
'} </script>';
return htmlContent;
}
function install() {}
function uninstall() {}
I tried all suggestions from Get current page URL from a firefox sidebar extension but nothing worked.
However, from the fact that you have set:
var propsToSet = {
id: 'demo-sidebar-with-html_browser',
type: 'content', //<---------------------------This
the <browser> type to content, I am assuming one of two things:
That you are not actually trying to get the active tab's URI from within the code you are loading into the <browser> through the src attribute.
If this is the case, please see my answer to "How to Get Active Tab Location by e10s add-on". In that case, the context from which you are running should allow you to use the code in that answer.
This possible assumption, #1, is not the case for your code.
You want to gain access to the URI form code within the <browser> you have loaded into the sidebar and are unaware of the restrictions which setting the <browser> type to content imposes upon the code you load into the <browser>.
It looks like you are trying to access the currant tab's URL from the code in your <browser>. You should consider restructuring your code such that access to chrome privileges is not required from the content that is in the <browser>. In other words, if possible, you should write your code such that you do not need to have access to the URL, or other information, directly from code running in the <browser> you insert. However, doing so may end up being significantly more complex.
Getting access to chrome privileges within the <browser> you are adding:
Setting the <browser> type to content is for:
A browser for content. The content that is loaded inside the browser is not allowed to access the chrome above it.
Setting the <browser> type to chrome is for:
(default behaviour): A browser, intended to be used for loading privileged content using a chrome:// URI. Don't use for content from web, as this may cause serious security problems!
To set the the <browser> type to chrome you can do:
var propsToSet = {
id: 'demo-sidebar-with-html_browser',
type: 'chrome', //<---------------------------This
The code provided by Noitidart comes close to what you need. However, it needs to be slightly modified, as gBrowser.currentURI is a nsIURI, not a string). Thus, you need to use gBrowser.currentURI.spec. You can get it working by changing your makeHTML() to:
function makeHTML(value, key){
var arrValues = value.split(",");
var htmlContent = '<html><head></head>'
+ '<body style="background-color: white;">'
+ ' <div name="content" class="content">'
+ ' <p> Name :' + arrValues[0] + '</p>';
htmlContent += '<p> Price :' + arrValues[2] + '</p>';
htmlContent += '<p> Color :' + arrValues[3] + '</p>';
htmlContent += '<p> UID :' + arrValues[1] + '</p>';
htmlContent +=
' <p><input type="radio" name="valid" value="yes" />Yes '
+ ' <input type="radio" name="valid" value="no" /> No</p>'
+ ' <p><input type="text" placeholder="Reason" name="checkreason" /></p>'
+ ' <p><input type="text" placeholder="Feedback" name="feedback" /></p>'
+ ' </div>'
+ ' <div>'
+ ' <button name="load" type="button" id="loadit" onclick="loadHtml()" '
+ ' loadurl="' + arrValues[4] + '">Load</button>'
+ ' <button name="save" type="button">Save </button>'
+ ' <button name="next" type="button" key="' + key + '">Next </button>'
+ ' </div>'
+ ' <script>'
+ ' function loadHtml() {'
+ ' const Cu = Components.utils;'
+ ' Cu.import("resource://gre/modules/Services.jsm");'
+ ' var win = Services.wm.getMostRecentWindow("navigator:browser");'
+ ' if (win) {'
+ ' var url = win.gBrowser.currentURI.spec;'
+ ' alert("URL=" + url);'
+ ' }'
+ ' }'
+ ' </script>'
+ '</body></html>';
return htmlContent;
}
Security concerns:
There are some really significant security concerns that you may be running into. Just from the fact that you want the URL for the current page implies that you may be rapidly approaching where these are a real issue. It is going to depend on what exactly you are going to do. Given that you are not providing that information, I am not going to go too in depth as to what the issues are. However, you should read "Firefox Security Basics for Developers" and "Security best practices in extensions"
Additional information about sidebars:
You should seriously consider creating an Add-on SDK based add-on, instead of a bootstrap one, and using the ui/sidebar API.
If you are interested, I created some code which can be used to create a "sidebar" that is located at the top, left, right, or bottom of the active tab, or in a separate window (similar to what the devtools panel will do). The sidebar created is associated with the currently active tab, not all tabs (I guess I should have made it an option to have it associated with all tabs, or just the current tab) in my answer to: "How to create a bottom-docked panel with XUL in Firefox?" and "Firefox Extension, Window related sidebar"

kendo grid command change button

How is possible to change button on click in command column? In my case, there should be "Validate" and "Reset" button that should be displayed as different buttons depending on Status. Function for validating works normally, but there is a problem with applying another class to the button, there is always .valid class. Here is a problem, I don't know where to apply .reset class. Thanks
template:
'<kendo button class = "k-primary button button-valid"ng-click="OnChangeStateMaterialDefinitionHeaders($event)"> #= Status == ' + STATUS_MDH_VALIDATE + ' ? " ' + kendo.htmlEncode(txt.TXT_VALIDATE) + '" : "' + kendo.htmlEncode(txt.TXT_RESET) + '" #</kendo button> ' +
'<button ng-click="OnRemoveMaterialDefinitionHeaders($event)">' + kendo.htmlEncode(txt.TXT_SET_VALIDATED) + ' </button>',
The other button is not important now, but is a part of this command column.

Unable to hide the file attachment browse button

I am sending attachments in email, while sending user can actually add multiple attachments. My code is keep displaying the browse button for every time. I want to display only one button and let the user opens the file picker for any no of attachments.
Please tell me whats wrong with my code.
Also see the attached image. Which is something I don't want that behavior.
What I want is on clicking the attach more button it should automatically open the file picker. Currently it is displaying the
Thank you.
<div class="col-sm-10">
<div class="element">
<label>Attachment</label>
<span class="upload_file_button"><input type="file" name="upload_file1" id="upload_file1"/></span>
</div>
<div id="moreImageUpload"></div>
<div id="moreImageUploadLink" style="display:none;margin-left: 10px;">
Attach More
</div>
</div>
</div>
</div>
javascript
<script type="text/javascript">
// onclick browse button attach the file id and show the attachmore link
$(document).ready(function() {
$("input[id^='upload_file']").each(function() {
var id = parseInt(this.id.replace("upload_file", ""));
$("#upload_file" + id).change(function() {
if ($("#upload_file" + id).val() != "") {
$("#moreImageUploadLink").show();
}
});
});
var upload_number = 2;
$('#attachMore').click(function() {
//add more file. Everytime clicking on attachmore link show the browse button also attach more as well.
var moreUploadTag = ''
moreUploadTag += '<div class="element"><label for="upload_file"' + upload_number + '>Upload File ' + upload_number + '</label>';
moreUploadTag += '<span class="upload_file_button"><input type="file" id="upload_file' + upload_number + '" name="upload_file' + upload_number + '"/></span>';
moreUploadTag += ' Delete ' + upload_number + '</div>';
$('<dl id="delete_file' + upload_number + '">' + moreUploadTag + '</dl>').fadeIn('slow').appendTo('#moreImageUpload');
upload_number++;
});
});
function del_file(eleId) {
var ele = document.getElementById("delete_file" + eleId);
ele.parentNode.removeChild(ele);
}
</script>
On click + Attach More it is displaying the browse button. Instead I want to open the file picker right away upon clicking + Attach more.
Just add this line
$('#upload_file' + upload_number).trigger('click');
before
upload_number++;
in order to have the "Attach more" button to trigger the opening of the file pickup.
Then you could hide the input file tag with CSS.

Loading popups with $.get - Jquery Mobile

I'm trying to load some data from a server. I have some links that when I click on them, I want them to open the right corresponding popup with that data in them. But the popups just appears as formatted text on the page. If you look at the code they are containing <p> tags. The result of the loadPopups function is that it just prints the <p> tags to the page. No popup behaviour.
Here is my code to get the popup data
function loadPopups() {
$.get("load.php", function(data) {
data = $.parseJSON(data);
var str = '';
for( laxa in data.laxor) {
var laxaArray = data.laxor[laxa];
str += '' +
'<div data-role="popup" id="' + (laxaArray.laxa_id + 'rubrik') + '">' +
'<p>' + laxaArray.rubrik + '<p>' +
'</div>' +
'<div data-role="popup" id="' + (laxaArray.laxa_id + 'beskrivning') + '">' +
'<p>' + laxaArray.beskrivning + '<p>' +
'</div>' +
'';
}
//alert('Data loaded');
$("#popup_containor").html(str).page();
});
}
this then gets added to this <div>
<div id="popup_containor">
</div>
When I try to display the popup by using the same id that is specified in the for loop for each popup like this
<p>Hej<p>
Nothin happens. The popups are simply displayed as if there where no <div data-role="popup">
Any help is appreciated
Thanks
Why won't you separate the logic?
Get whatever values you want first from server.
let's say var a= 'string 1 from server', b='string 2' and so on.
Create functional popup in your page with no data.
Done
<div data-role="popup" id="134rubrik" data-overlay-theme="b">
<p id="serverdata"> </p>
</div>
Than fill your popup using JS or jQuery:
document.getElementById('serverdata').value= a;

Categories