Opencart get current layout_id - layout

I have created a custom layout and i planned to hide products only for those custom layout assigned pages.
Is there any way to get current layout id ?
For example, Let's say my custom layout_id is 10, I planned to use some looping like below to hide/show products
if (current_layout_id != 10) {
// Display products
}else {
// Hide Products
}

find layout id of current displayed module page
if (isset($this->request->get['route'])) {
$route = $this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if (substr($route, 0, 16) == 'product/category' && isset($this->request->get['path'])) {
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
}
if (substr($route, 0, 16) == 'product/product' && isset($this->request->get['product_id'])) {
$layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
}
if (substr($route, 0, 16) == 'product/information' && isset($this->request->get['information_id'])) {
$layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
}
if (!$layout_id) { $layout_id = $this->model_design_layout->getLayout($route); }
if (!$layout_id) { $layout_id = $this->config->get('config_layout_id'); }
end of layout id finding

Related

Skipping of inputs if user types fast

I am trying to create otp view where each item is individually editable, problem arises when user types fast, the input is skipped. I believe there is some delay in focus manager. Below is the code, let me know if there is any issues in the snippet itself
#Composable
#Preview
fun OtpLayout(modifier: Modifier = Modifier, otpLength: Int = 6) {
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = modifier.fillMaxWidth()) {
val focusManager = LocalFocusManager.current
val list = remember {
List(6) {
mutableStateOf(TextFieldValue(text = "", selection = TextRange(0)))
}
}
repeat(otpLength) { index ->
key(index) {
BasicTextField(
modifier = Modifier.onKeyEvent {
if (it.key == Key.Backspace && index > 0 && list[index].value.text.isEmpty()) {
focusManager.moveFocus(FocusDirection.Left)
}
true
},
maxLines = 1,
value = list[index].value,
textStyle = TextStyle(color = Color.White, fontSize = 16.sp),
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Number),
onValueChange = { value ->
Log.e("OnValue Changed called", value.text)
if (value.text.length <= 1 && value.text.isDigitsOnly()) {
list[index].value = value
if (value.text != "" && index < otpLength - 1) {
focusManager.moveFocus(FocusDirection.Right)
} else if (value.text == "" && index > 0) {
focusManager.moveFocus(FocusDirection.Left)
}
} else if (list[index].value.text.length == 1 && index < otpLength - 1) {
list[index + 1].value = value.copy(text = value.text.last().toString())
focusManager.moveFocus(FocusDirection.Right)
}
},
decorationBox = { innerTextField ->
Box(contentAlignment = Alignment.Center,
modifier = Modifier
.size(width = 42.dp, height = 52.dp)
.border(width = 1.dp,
color = PrimaryColor,
shape = RoundedCornerShape(6.dp))
.background(color = Gray, shape = RoundedCornerShape(6.dp))) {
innerTextField()
}
}
)
}
}
}
}

How to change a color of one particular bar using jqplot and stacked bar chart

I got one straight forward question. Is it possible to change the color of one bar in stacked bar chart in any way (using jqplot options or relying on a hack)?
I have this:
I want this:
So as you can already assume I am using 3 different colors for the stacked bar chart:
seriesColors: ['#afafaf', '#c4c6c4', '#dbdcdd']
Problem is that I want to add one specific color for 1 particular bar.
Here is the JS code:
$(document).ready(
function() {
var el = [ 3, 6, 0, 10, 12 ];
var ael = [ 14, 5, 0, 4, 2 ];
var ipv = [ 4, 9, 0, 8, 4 ];
var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May' ];
var colors = ['blue', 'red', 'white'];
plot3 = $.jqplot('elDiagram', [ el, ael, ipv ], {
stackSeries : true,
seriesColors: colors,
captureRightClick : true,
seriesDefaults : {
renderer : $.jqplot.BarRenderer,
rendererOptions : {
barMargin : 30,
varyBarColor : true,
highlightMouseDown : true,
barWidth: 60
},
pointLabels : {
show : true
}
},
axes : {
xaxis : {
renderer : $.jqplot.CategoryAxisRenderer,
ticks : months,
tickOptions : {
mark : 'outside'
}
},
yaxis : {
tickOptions : {
show : false
},
padMin : 0
}
},
series : [ {
label : 'bla1'
}, {
label : 'bla2'
}, {
label : 'bla3'
} ],
legend : {
show : true,
location : 'ne',
placement : 'inside'
}
});
});
Thanks!
OK, the solution was a hack which I will show and describe here:
You need to overwrite the function called $.jqplot.BarRenderer.prototype.draw and change some of the lines
You need to overwrite the function called getStart(sidx, didx, comp, plot, axis)
You need to overwrite the function called $.jqplot.ShapeRenderer.prototype.draw and change some of the lines
1.:
$.jqplot.BarRenderer.prototype.draw = function(ctx, gridData, options, plot) {
var i;
// Ughhh, have to make a copy of options b/c it may be
// modified later.
var opts = $.extend({}, options);
.................................
<other code>
.................................
var clr = opts.fillStyle || this.color;
this._dataColors.push(clr);
this.renderer.shapeRenderer.draw(ctx, points, opts, i, pos); // changed line
I changed the line in that way that I added i and pos parameters into the function. The reason was to indicate the current bar and position in the bar.
2.:
function getStart(sidx, didx, comp, plot, axis) {
// check if sign change
var seriesIndex = sidx, prevSeriesIndex = sidx - 1, start, prevVal, aidx = (axis === 'x') ? 0 : 1;
// is this not the first series?
if (seriesIndex > 0) {
prevVal = plot.series[prevSeriesIndex]._plotData[didx][aidx];
// is there a sign change
if ((comp * prevVal) < 0) {
start = getStart(prevSeriesIndex, didx, comp, plot, axis);
}
// no sign change.
else {
start = plot.series[prevSeriesIndex].gridData[didx][aidx];
}
}
// if first series, return value at 0
else {
start = (aidx === 0) ? plot.series[seriesIndex]._xaxis.series_u2p(0) : plot.series[seriesIndex]._yaxis.series_u2p(0);
}
return start;
}
Nothing is changed here. You just need to copy the function because your new overwritten function cannot use it from jQPlot library.
3.:
$.jqplot.ShapeRenderer.prototype.draw = function(ctx, points, options, currentBar, position) {
ctx.save();
var opts = (options != null) ? options : {};
var fill = (opts.fill != null) ? opts.fill : this.fill;
var closePath = (opts.closePath != null) ? opts.closePath : this.closePath;
var fillRect = (opts.fillRect != null) ? opts.fillRect : this.fillRect;
var strokeRect = (opts.strokeRect != null) ? opts.strokeRect
: this.strokeRect;
var clearRect = (opts.clearRect != null) ? opts.clearRect : this.clearRect;
var isarc = (opts.isarc != null) ? opts.isarc : this.isarc;
var linePattern = (opts.linePattern != null) ? opts.linePattern
: this.linePattern;
var ctxPattern = $.jqplot.LinePattern(ctx, linePattern);
ctx.lineWidth = opts.lineWidth || this.lineWidth;
ctx.lineJoin = opts.lineJoin || this.lineJoin;
ctx.lineCap = opts.lineCap || this.lineCap;
ctx.strokeStyle = (opts.strokeStyle || opts.color) || this.strokeStyle;
ctx.fillStyle = opts.fillStyle || this.fillStyle;
if (currentBar == activeColumn && position == 0) { // adding different color for the specific bar
ctx.fillStyle = defaultColors[0];
} else if (currentBar == activeColumn && position == 1) {
ctx.fillStyle = defaultColors[1];
} else if (currentBar == activeColumn && position == 2) {
ctx.fillStyle = defaultColors[2];
}
ctx.beginPath();
if (isarc) {
ctx.arc(points[0], points[1], points[2], points[3], points[4], true);
if (closePath) {
ctx.closePath();
}
if (fill) {
ctx.fill();
} else {
ctx.stroke();
}
ctx.restore();
return;
} else if (clearRect) {
ctx.clearRect(points[0], points[1], points[2], points[3]);
ctx.restore();
return;
} else if (fillRect || strokeRect) {
if (fillRect) {
ctx.fillRect(points[0], points[1], points[2], points[3]);
}
if (strokeRect) {
ctx.strokeRect(points[0], points[1], points[2], points[3]);
ctx.restore();
return;
}
} else if (points && points.length) {
var move = true;
for ( var i = 0; i < points.length; i++) {
// skip to the first non-null point and move to it.
if (points[i][0] != null && points[i][1] != null) {
if (move) {
ctxPattern.moveTo(points[i][0], points[i][1]);
move = false;
} else {
ctxPattern.lineTo(points[i][0], points[i][1]);
}
} else {
move = true;
}
}
if (closePath) {
ctxPattern.closePath();
}
if (fill) {
ctx.fill();
} else {
ctx.stroke();
}
}
ctx.restore();
};
Here you need to check whether the bar your currently at, is the default one. The important part of the code is:
if (currentBar == activeColumn && position == 0) { // adding different color for the specific bar
ctx.fillStyle = defaultColors[0];
} else if (currentBar == activeColumn && position == 1) {
ctx.fillStyle = defaultColors[1];
} else if (currentBar == activeColumn && position == 2) {
ctx.fillStyle = defaultColors[2];
}
I added 3 different colors for that bar just to have "more fancy" diagram :)

Get parent Id on checked unchecked event in aciTree

I want to ask a question that how can i get the parent id of child node in aciTree. If uservchecked the child node then i want to save its id with its parent id.
Any help in this regard will be highly appreciated.
I have gone through aciTree documentation http://acoderinsights.ro/source/aciTree/documentation.html# but didn't found any method to get the parent id on child selection.
if (eventName == 'checked') {
if (bankUsers.indexOf(api.getId(item)) == -1) {
if (api.getId(item) == -2 || api.getId(item) - 3) {
bankUsers = new Array();
bankUsers[0] = api.getId(item);
} else {
bankUsers.push(api.getId(item));
}
}
} else if (eventName == 'unchecked') {
if (bankUsers.indexOf(api.getId(item)) != -1) {
if (api.getId(item) == -2 || api.getId(item) - 3) {
bankUsers = new Array();
} else {
bankUsers.splice(bankUsers.indexOf(api.getId(item)), 1);
}
}
}
you can use this function :
var parentID = api.itemData(api.parent(item)).id;
as simple as this.
if .id give undefiend you can use the following:
var parentID = api.getId(api.parent(item));

How to return scrollbar in Sharepoint 2010

I want to fix scrollbar in popUp window,but unfortunately fix it in my other pages!
Please,tell me- how to return scrollbars in Sharepoint 2010.
When i want to fix scrolls- use :
function FixRibbonAndWorkspaceDimensions() {
ULSxSy:;
g_frl = true;
var elmRibbon = GetCachedElement("s4-ribbonrow");
var elmWorkspace = GetCachedElement("s4-workspace");
var elmTitleArea = GetCachedElement("s4-titlerow");
var elmBodyTable = GetCachedElement("s4-bodyContainer");
if (!elmRibbon || !elmWorkspace || !elmBodyTable) { return; }
if (!g_setWidthInited) {
var setWidth = true;
if (elmWorkspace.className.indexOf("s4-nosetwidth") > -1)
setWidth = false;
g_setWidth = setWidth;
g_setWidthInited = true;
}
else { var setWidth = g_setWidth; }
var baseRibbonHeight = RibbonIsMinimized() ? 44 : 135;
var ribbonHeight = baseRibbonHeight + g_wpadderHeight;
if (GetCurrentEltStyle(elmRibbon, "visibility") == "hidden") { ribbonHeight = 0; }
// Override default resizing behavior
// -- adds padding to the top of the "s4-workspace" <div> if the ribbon exists and has content
// -- allows the ribbon to be positioned using CSS instead of JavaScript (more accessible)
// -- checks to see if the page is inside a "no-ribbon" dialog
var elmRibbonContainer = GetCachedElement("RibbonContainer");
if (elmRibbonContainer != null) {
if (elmRibbonContainer.children.length > 0 && document.getElementsByTagName("html")[0].className.indexOf('ms-dialog-nr') == -1) {
elmWorkspace.style.paddingTop = ribbonHeight + 'px';
}
}
}
i think ,that i have to write

Opening tabs in Chrome news reader extension

I'm trying to create a simple chrome extension using the following google RSS reader sample,
http://code.google.com/chrome/extensions/samples.html#597015d3bcce3da693b02314afd607bec4f55291
I can add links in the pop-up window that open tabs, but not from the feeds themselves.
Looping through the items in the feed, grabbing title tags and link tags, I want the title to link the the appropriate sites
var entries = doc.getElementsByTagName('item');
var count = Math.min(entries.length, maxFeedItems);
for (var i = 0; i < count; i++) {
item = entries.item(i);
// Grab the title for the feed item.
var itemTitle = item.getElementsByTagName('title')[0];
if (itemTitle) {
itemTitle = itemTitle.textContent;
} else {
itemTitle = "Unknown title";
}
// Grab the link for this feed item
var itemLink = item.getElementsByTagName('link')[0];
if (itemLink) {
itemLink = itemLink.textContent;
} else {
itemLink = "Unknown link";
}
var title = document.createElement("a");
title.className = "item_title";
title.innerText = itemTitle; //display title in iframe
title.addEventListener("click", titleLink); // should open link when clicking on title, but does not.
}
// -------------------------------------------------------------------
// Show |url| in a new tab.
function showUrl(url) {
// Only allow http and https URLs.
if (url.indexOf("http:") != 0 && url.indexOf("https:") != 0) {
return;
}
chrome.tabs.create({url: url});
}
function moreStories(event) {
showUrl(moreStoriesUrl);
}
function titleLink(event) {
showUrl(itemLink);
}
Any thoughts on why this is not working.
If I replace title.addEventListener("click", titleLink); with title.addEventListener("click", moreStories); each title will link to moreStories, I cannot get each title to link to itemLink.
Thanks
Its a bit hard to answer your question without the whole code, but Ill give it a shot ;)
First up, titleLink() isnt going to work because itemLink isnt known. When you create title (the link) you should of attached it to that...say title.href=itemLink then in tiltleLinks you could access that href with showUrl(event.currentTarget.href)
Also did you fix the error in that example?...if not then change frameLoaded to....
function frameLoaded() {
var links = document.getElementsByTagName("A");
for (i = 0; i < links.length; i++) {
var clssName = links[i].className;
if (clssName != "item_title" && clssName != "open_box") {
links[i].addEventListener("click", showStory);
}
}
window.addEventListener("message", messageHandler);
}
If you still have probs could you attach the whole code so I can see what your doing and Ill give you a hand.
Thank you very much for your help.
code title.href=itemLink and code showUrl(event.currentTarget.href) was exactly what I needed.
For completeness, here is the full code,
<script id="iframe_script">
function reportHeight() {
var msg = JSON.stringify({type:"size", size:document.body.offsetHeight});
parent.postMessage(msg, "*");
}
function frameLoaded() {
var links = document.getElementsByTagName("A");
for (i = 0; i < links.length; i++) {
var class = links[i].className;
if (class != "item_title" && class != "open_box") {
links[i].addEventListener("click", showStory);
}
}
window.addEventListener("message", messageHandler);
}
function showStory(event) {
var href = event.currentTarget.href;
parent.postMessage(JSON.stringify({type:"show", url:href}), "*");
event.preventDefault();
}
function messageHandler(event) {
reportHeight();
}
</script>
<script>
// Feed URL.
var feedUrl = 'http://localhost/newsfeed.xml';
// The XMLHttpRequest object that tries to load and parse the feed.
var req;
function main() {
req = new XMLHttpRequest();
req.onload = handleResponse;
req.onerror = handleError;
req.open("GET", feedUrl, true);
req.send(null);
}
// Handles feed parsing errors.
function handleFeedParsingFailed(error) {
var feed = document.getElementById("feed");
feed.className = "error";
feed.innerText = "Error: " + error;
}
// Handles errors during the XMLHttpRequest.
function handleError() {
handleFeedParsingFailed('Failed to fetch RSS feed.');
}
// Handles parsing the feed data we got back from XMLHttpRequest.
function handleResponse() {
var doc = req.responseXML;
if (!doc) {
handleFeedParsingFailed("Not a valid feed.");
return;
}
buildPreview(doc);
}
// The maximum number of feed items to show in the preview.
var maxFeedItems = 10;
// Where the more stories link should navigate to.
var moreStoriesUrl;
function buildPreview(doc) {
// Get the link to the feed source.
var link = doc.getElementsByTagName("link");
var parentTag = link[0].parentNode.tagName;
if (parentTag != "item" && parentTag != "entry") {
moreStoriesUrl = link[0].textContent;
}
// Setup the title image.
var images = doc.getElementsByTagName("image");
var titleImg;
if (images.length != 0) {
var urls = images[0].getElementsByTagName("url");
if (urls.length != 0) {
titleImg = urls[0].textContent;
}
}
var img = document.getElementById("title");
// Listen for mouse and key events
if (titleImg) {
img.src = titleImg;
if (moreStoriesUrl) {
document.getElementById("title_a").addEventListener("click",moreStories);
document.getElementById("title_a").addEventListener("keydown",
function(event) {
if (event.keyCode == 13) {
moreStories(event);
}});
}
} else {
img.style.display = "none";
}
// Construct the iframe's HTML.
var iframe_src = "<!doctype html><html><head><script>" +
document.getElementById("iframe_script").textContent + "<" +
"/script></head><body onload='frameLoaded();' " +
"style='padding:0px;margin:0px;'>";
var feed = document.getElementById("feed");
// Set ARIA role indicating the feed element has a tree structure
feed.setAttribute("role", "tree");
var entries = doc.getElementsByTagName('item');
var count = Math.min(entries.length, maxFeedItems);
for (var i = 0; i < count; i++) {
item = entries.item(i);
// Grab the title for the feed item.
var itemTitle = item.getElementsByTagName('title')[0];
if (itemTitle) {
itemTitle = itemTitle.textContent;
} else {
itemTitle = "Unknown title";
}
// Grab the link for the feed item.
var itemLink = item.getElementsByTagName('link')[0];
if (itemLink) {
itemLink = itemLink.textContent;
} else {
itemLink = "Unknown link";
}
var item = document.createElement("div");
var title = document.createElement("a");
title.innerText = itemTitle; //display title in iframe
title.href=itemLink;
title.addEventListener("click", titleLink);
item.appendChild(title);
feed.appendChild(item);
}
if (moreStoriesUrl) {
var more = document.createElement("a");
more.className = "more";
more.innerText = "***Site Main Page*** \u00BB";
more.tabIndex = 0;
more.addEventListener("click", moreStories);
more.addEventListener("keydown", function(event) {
if (event.keyCode == 13) {
moreStories(event);
}});
feed.appendChild(more);
}
}
// -------------------------------------------------------------------
// Show |url| in a new tab.
function showUrl(url) {
// Only allow http and https URLs.
if (url.indexOf("http:") != 0 && url.indexOf("https:") != 0) {
return;
}
chrome.tabs.create({url: url});
}
// -------------------------------------------------------------------
function moreStories(event) {
showUrl(moreStoriesUrl);
}
function titleLink(event) {
showUrl(event.currentTarget.href);
}
function keyHandlerShowDesc(event) {
// Display content under heading when spacebar or right-arrow pressed
// Hide content when spacebar pressed again or left-arrow pressed
// Move to next heading when down-arrow pressed
// Move to previous heading when up-arrow pressed
if (event.keyCode == 32) {
showDesc(event);
} else if ((this.parentNode.className == "item opened") &&
(event.keyCode == 37)) {
showDesc(event);
} else if ((this.parentNode.className == "item") && (event.keyCode == 39)) {
showDesc(event);
} else if (event.keyCode == 40) {
if (this.parentNode.nextSibling) {
this.parentNode.nextSibling.children[1].focus();
}
} else if (event.keyCode == 38) {
if (this.parentNode.previousSibling) {
this.parentNode.previousSibling.children[1].focus();
}
}
}
function showDesc(event) {
var item = event.currentTarget.parentNode;
var items = document.getElementsByClassName("item");
for (var i = 0; i < items.length; i++) {
var iframe = items[i].getElementsByClassName("item_desc")[0];
if (items[i] == item && items[i].className == "item") {
items[i].className = "item opened";
iframe.contentWindow.postMessage("reportHeight", "*");
// Set the ARIA state indicating the tree item is currently expanded.
items[i].getElementsByClassName("item_title")[0].
setAttribute("aria-expanded", "true");
iframe.tabIndex = 0;
} else {
items[i].className = "item";
iframe.style.height = "0px";
// Set the ARIA state indicating the tree item is currently collapsed.
items[i].getElementsByClassName("item_title")[0].
setAttribute("aria-expanded", "false");
iframe.tabIndex = -1;
}
}
}
function iframeMessageHandler(e) {
// Only listen to messages from one of our own iframes.
var iframes = document.getElementsByTagName("IFRAME");
for (var i = 0; i < iframes.length; i++) {
if (iframes[i].contentWindow == e.source) {
var msg = JSON.parse(e.data);
if (msg) {
if (msg.type == "size") {
iframes[i].style.height = msg.size + "px";
}
else if (msg.type == "show") {
var url = msg.url;
if (url.indexOf("http://localhost/index.html") == 0) {
// If the URL is a redirect URL, strip of the destination and go to
// that directly. This is necessary because the Google news
// redirector blocks use of the redirects in this case.
var index = url.indexOf("&url=");
if (index >= 0) {
url = url.substring(index + 5);
index = url.indexOf("&");
if (index >= 0)
url = url.substring(0, index);
}
}
showUrl(url);
}
}
return;
}
}
}
window.addEventListener("message", iframeMessageHandler);
</script>
Thanks again for the help.
-Mike

Resources