Expand/Collapse Works for First Two Web Parts Only - sharepoint

I am trying to Maximize/Minimize a Document list Web Part.
I used the following code from http://blog.pathtosharepoint.com/2008/10/25/expandcollapse-buttons-for-your-web-parts/
and it works for my first two Web Parts but not my other two. All I did was include their titles within my coding as a change. Therefore, there shouldn't be any issue with the display.
Any suggestions on what can cause this?
The only changes I made after the first 2 were working was I added 2 more title1 to include the other 2 Web Parts.
As you can see, the bottom 2 don't fully minimize on page load
fYI: inside the coding.. the titles are changed to "... Orders" but the ... is in place of the actual name
<script type="text/javascript">
// Expand/Collapse Buttons
function WPToggle(thisId, ImageId)
{
if (document.getElementById(thisId).style.display=="none")
{
document.getElementById(thisId).style.display="";
document.getElementById(ImageId).src = "/_layouts/images/minus.gif";
}
else
{
document.getElementById(thisId).style.display="none";
document.getElementById(ImageId).src = "/_layouts/images/plus.gif";
}
}
function ExpandCollapseBody()
{
var i = 1;
var WPid = "WebPartWPQ1" ;
var WPtitleid = "WebPartTitleWPQ1" ;
var Toggleid = "ToggleImage1" ;
do
{
try
{
title1 = document.getElementById(WPtitleid).getAttribute("title");
if (title1 == "... Orders" || title1 == "... Orders" || title1 =="... Orders" || title1 == "... Orders")
{
document.getElementById(WPtitleid).innerHTML = '<IMG id="' + Toggleid + '" onClick="WPToggle(\'' + WPid + '\',\'' + Toggleid +
'\')" alt="Expand/Collapse" style="margin:6px 5px 0px 2px; float:left; cursor:pointer;" src="/_layouts/images/minus.gif" />' +
document.getElementById(WPtitleid).innerHTML ;
document.getElementById(Toggleid).src = "/_layouts/images/plus.gif";
}
}
catch(err) {}
i = i + 1;
WPid = "WebPartWPQ" + i ;
WPtitleid = "WebPartTitleWPQ" + i;
Toggleid = "ToggleImage" + i;
} while (document.getElementById(WPid))
}
_spBodyOnLoadFunctionNames.push("ExpandCollapseBody()");
</script>
I guess I see that by default, the more I add more webparts they start at expanded rather than collapse....

I see. I need the following condition of Chrome: minimize for the Web Part

Related

html2canvas does not print jsPlumb Connectors

How to print SVG elements that are built by jsPlumb.
Known that getting all SVG Elements drawen by jsPlumb is retrieved by this code :
var uiJsPlumbConnectors=jsPlumb.getAllConnections().map(function(conn){return conn.canvas;})
All connectors are SVG elements :
Using html2canvas to print all connectors (SVG), it does not work :
html2canvas(uiJsPlumbConnectors).then(function(c){
window.open(c.toDataURL('image/png'))
});
An image has been generated , however, it is an emply image .
FIDDLE
It seems that html2canvas does not support yet multi-elements drawing ?
Last time I checked html2canvas was not able to convert SVGs, you will need another script to handle that.
The steps:
transfer html elements to canvas
transfer svg elements to canvas
export canvas
I used https://code.google.com/p/canvg/ to export to the same canvas after using html2canvas. Hope that helps you.
I just implemented this
<%--stuff for printing--%>
<script type="text/javascript" src="../../../../Scripts/Print/html2canvas.js"></script>
<script src="<%=AdminPath%>Scripts/canvg/rgbcolor.js" type="text/javascript"></script>
<script src="<%=AdminPath%>Scripts/canvg/StackBlur.js" type="text/javascript"></script>
<script src="<%=AdminPath%>Scripts/canvg/canvg.js" type="text/javascript"></script>
jsplumb div
<div class="demo statemachine-demo" id="statemachine-demo" style="margin: 0px;">
</div>
hidden div for printing
<div id="canvasDiv" style='visibility:hidden;' >
</div>
function renderImage()
{
var statemachinediv = document.getElementById('statemachine-demo');
html2canvas([statemachinediv], {
onrendered: function (canvas) {
document.getElementById('canvasDiv').appendChild(canvas);
var svgList = $(statemachinediv).find( "svg" );
svgList.each(function(index, value) {
try
{
var svgExample = this;
var serializer = new XMLSerializer();
var svgMarkup = serializer.serializeToString(svgExample);
if(svgMarkup.indexOf("_jsPlumb_connector") > -1)
{
var leftIndex = svgMarkup.indexOf("left: ");
var endOfLeft = svgMarkup.indexOf("px", leftIndex);
var leftPosition = svgMarkup.substring(leftIndex+6, endOfLeft );
var left = parseInt(leftPosition);
var topIndex = svgMarkup.indexOf("top: ");
var endOfTop = svgMarkup.indexOf("px", topIndex);
var topPosition = svgMarkup.substring(topIndex+5, endOfTop );
var top = parseInt(topPosition);
svgMarkup = svgMarkup.replace('xmlns="http://www.w3.org/2000/svg"','');
var connectorCanvas = document.createElement('canvas');
canvg(connectorCanvas, svgMarkup); //add connector to canvas
var context = canvas.getContext('2d');
context.drawImage(connectorCanvas, left, top);
}
}
catch(err)
{
showBalloon('error in print');
}
});
var stateMachineName = $("#stateMachineDropDown option:selected").text();
var data = canvas.toDataURL('image/png');
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>' + stateMachineName + '</title>');
mywindow.document.write('</head><body ><table><tr><td>');
mywindow.document.write('</td></tr></table><img src="' + data + '" />');
mywindow.document.write('</body></html>');
mywindow.print();
}
});
return false;
}
Its a old question, but, this helped me. Mode details.
$clone.find('.jtk-connector').each(function () {
// for every SVG element created by JsPlumb for connections...
var left = parseInt(this.style.left, 10) + 'px';
var top = parseInt(this.style.top, 10) + 'px';
this.removeAttribute('style');
this.removeAttribute('position');
this.setAttribute('width', parseInt(this.getAttribute('width'), 10) + 'px');
this.setAttribute('height', parseInt(this.getAttribute('height'), 10) + 'px');
this.setAttribute('preserveAspectRatio', 'xMidYMid meet');
this.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
// this.children[0] is the path for connection line
// this.children[1] is the path for connection arrow shape
this.children[0].setAttribute('xmlns', 'http://www.w3.org/2000/svg');
this.children[1].setAttribute('xmlns', 'http://www.w3.org/2000/svg');
this.setAttribute('viewbox', '0 0 ' + parseInt(this.getAttribute('width'), 10) + ' ' + parseInt(this.getAttribute('height'), 10));
this.children[0].setAttribute('stroke-width', '2px');
this.children[0].setAttribute('stroke', '#c9c9c9');
this.children[1].setAttribute('fill', '#c9c9c9');
this.children[1].setAttribute('stroke', '#c9c9c9');
$clone.find(this).wrap('<span style="position: absolute; left: ' + left + '; top: ' + top + ';"></span>');
});

Opencart 1.5.4 Search by Description

I have read various entries about searching by description and subcategories in opencart by default but I have a unique problem. I have two header files because my site has 2 headers... one for the home page and one for every other page.
Home Page:
https://garrysun.com/
Other Page:
https://garrysun.com/ayurveda-products/categories
When I search on the home page I get the correct results (search the word "heart") but when I search any other page it doesn't return the search for descriptions or subcategories.
Home Page Search Results:https://garrysun.com/index.php?route=product/search&filter_description=true&filter_sub_category=true&filter_name=heart
Other Page Search Results:https://garrysun.com/index.php?route=product/search&filter_name=heart
As you can see, when I search the other page the extra code is not being added to search in descriptions and subcategories.
So why is this new code that I added working for the home page an not any other page?
To make this search function work I have changed the common.js file to look like this (adding the two lines below each "url= $(base..." section:
/* Search */
$('.button-search').bind('click', function() {
url = $('base').attr('href') + 'index.php?route=product/search';
url += '&filter_description=true'; // ADDED this to search descriptions
url += '&filter_sub_category=true'; // ADDED this to search sub-categories
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name) ;
}
location = url;
});
$('#header input[name=\'filter_name\']').bind('keydown', function(e) {
if (e.keyCode == 13) {
url = $('base').attr('href') + 'index.php?route=product/search';
url += '&filter_description=true'; // ADDED this to search descriptions
url += '&filter_sub_category=true'; // ADDED this to search sub-categories
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name) ;
}
location = url;
}
});
Both header files use the same code to call the search function:
<div id="search">
<div class="button-search"></div>
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#000000';" />
<?php } ?>
</div>
</div>
After trying to figure out what's wrong in your code for few minutes (unsuccessfully), I ran a network debugging and found out that nothing is wrong with your code, you are just calling 2 different Javascript files(!):
On your home page, you are using common.js that is located at https://garrysun.com/catalog/view/javascript/common.js.
On your category pages, you are using common.js that is located at https://garrysun.com/catalog/view/javascript/add2cart-go2cart/common.js.
The 2nd one does not include your modifications, and looks like this:
$('.button-search').bind('click', function() {
url = $('base').attr('href') + 'index.php?route=product/search';
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
location = url;
});
$('#header input[name=\'filter_name\']').bind('keydown', function(e) {
if (e.keyCode == 13) {
url = $('base').attr('href') + 'index.php?route=product/search';
var filter_name = $('input[name=\'filter_name\']').attr('value');
if (filter_name) {
url += '&filter_name=' + encodeURIComponent(filter_name);
}
location = url;
}
});
Vuala.
Hope this helps!

Greasemonkey: Re-write all links based on param

I need alittle help with getting a script that will take param from the orginal link and re-write them into a new link. I guess it should be pretty easy but I'm a noob still when it comes to this.
Here is the orginal HTML code for 1 link. (should be replaced globaly on the page. image1.jpg, image2.jpg etc.)
<div align="center"><img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" /></div>
This should be done global on all the links that contain the imagepath "/preview/"
Thanks to Brock Adams I kinda understand how to get the param values with this code but I still don't really get it how to re-write all the links in a page.
var searchableStr = document.URL + '&';
var value1 = searchableStr.match (/[\?\&]id=([^\&\#]+)[\&\#]/i) [1];
var value2 = searchableStr.match (/[\?\&]connect=([^\&\#]+)[\&\#]/i) [1];
and then rewrite the links with "newlink"
var domain = searchableStr.match (/\/\/([w\.]*[^\/]+)/i) [1];
var newlink = '//' + domain + '/' + value1 + '/data/' + value2 + '.ext';
If someone could be so nice to help me setup an example greasemonkey script I would be very greatful for it.
OK, This is a fairly common task and I don't see any previous, Stack Overflow questions like it -- at least in a 2 minute search.
So, here's a script that should do what you want, based on the information provided...
// ==UserScript==
// #name Site_X, image relinker.
// #namespace StackOverflow
// #description Rewrites the preview links to ???
// #include http://Site_X.com/*
// #include http://www.Site_X.com/*
// #include https://Site_X.com/*
// #include https://www.Site_X.com/*
// ==/UserScript==
function LocalMain () {
/*--- Get all the images that have /preview/ in their path.
*/
var aPreviewImages = document.evaluate (
"//img[contains (#src, '/preview/')]",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
var iNumImages = aPreviewImages.snapshotLength;
GM_log (iNumImages + ' preview images found.');
/*--- Rewrite the parent links to our new specifications.
Note, all the target links are of the form:
<a href="/index.php?Submit=ok&seson=b1e4&connect=127.0.0.1&id=13033&name=on">
<img src="/preview/image1.jpg" width="128" height="128" border="0" style="border: 0px black solid;" />
</a>
The desired rewrite changes the link to this form:
<a href="{current page's domain}/{id-value}/data/{connect-value}.ext">
*/
for (var iLinkIdx=0; iLinkIdx < iNumImages; iLinkIdx++) {
var zThisImage = aPreviewImages.snapshotItem (iLinkIdx);
var zParentLink = zThisImage.parentNode;
//--- Get the key href parameters.
var sIdValue = sGetUrlParamValue (zParentLink, 'id');
if (!sIdValue) continue; //-- Oopsie, this link was a malformed.
var sConnectValue = sGetUrlParamValue (zParentLink, 'connect');
if (!sConnectValue) continue;
//--- Get the current page's domain. (Or just use a relative link.)
var sPageDomain = document.URL.match (/\/\/([w\.]*[^\/]+)/i) [1];
//--- Generate the desired link value.
var sDesiredLink = 'http://' + sPageDomain + '/' + sIdValue + '/data/' + sConnectValue + '.ext';
//--- Rewrite the target link.
zParentLink.href = sDesiredLink;
}
}
function sGetUrlParamValue (zTargLink, sParamName) {
var zRegEx = eval ('/[\?\&]' + sParamName + '=([^\&\#]+)[\&\#]/i');
var aMatch = (zTargLink.href + '&').match (zRegEx);
if (aMatch)
return decodeURI (aMatch[1]);
else
return null;
}
window.addEventListener ("load", LocalMain, false);

Is it possible to 'freeze panes' in SharePoint lists?

I need to keep my columns header, so people can see what data is displayed there, but I can not find if it is possible, or how to do it. Also will be nice to add a navigation bar to the list. Any suggestions?
Thanks,
I had similar challenge recently, and worked out the following code. The code works for IE, but there's a problem with the width of the freeze header in Chrome.
Anyway, hope it helps.
<script type="text/javascript">
$(document).ready(function(){
// Replace 'NameOfList' with the name of the SharePoint list
var $header = $("table[summary^='NameOfList']:first > tbody > tr.ms-viewheadertr");
var headertop = $header.offset().top;
// Replace 'NameOfColumn' with the name of the column that you would like to freeze
var $fzCol= $("tr.ms-viewheadertr th:contains('NameOfColumn')");
// IE has iFrame, Chrome doesn't have, so the 'n-th' count of the column is different in IE than in Chrome
if( $fzCol.siblings().eq(0).children().eq(0).prop("tagName") == "IFRAME"){ var shift = 0} else { var shift = 1};
var nfzCol=$fzCol.index()+shift;
var $mcol=$("table[summary^='NameOfList'] > tbody > tr:not(.ms-viewheadertr) > td:nth-child("+nfzCol+")");
var colleft=$mcol.eq(0).offset().left;
$(window).scroll(function(){
var windowtop = $('body').scrollTop();
if( windowtop > headertop ){
$header.css({"position":"absolute", "top":windowtop});
} else {
$header.css({"position":"static", "top":"0px"});
}
var windowleft = $('body').scrollLeft();
if (windowleft > colleft ){
$mcol.css({"position":"relative", "left": windowleft-colleft});
} else {
$mcol.css({"position":"static", "left":"0px"});
}
});
}

Allow only Copy/Paste Context Menu in System.Windows.Forms.WebBrowser Control

The WebBrowser control has a property called "IsWebBrowserContextMenuEnabled" that disables all ability to right-click on a web page and see a context menu. This is very close to what I want (I don't want anyone to be able to right-click and print, hit back, hit properties, view source, etc).
The only problem is this also disables the context menu that appears in TextBoxes for copy/paste, etc.
To make this clearer, this is what I don't want:
This is what I do want:
I would like to disable the main context menu, but allow the one that appears in TextBoxes. Anyone know how I would do that? The WebBrowser.Document.ContextMenuShowing event looks promising, but doesn't seem to properly identify the element the user is right-clicking on, either through the HtmlElementEventArgs parameter's "FromElement" and "ToElement" properties, nor is the sender anything but the HtmlDocument element.
Thanks in advance!
have you considered writing your own context menu in javascript? Just listen to the user right clicking on the body, then show your menu with copy and paste commands (hint: element.style.display = "block|none"). To copy, execute the following code:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Copy");
And to paste:
CopiedTxt = document.selection.createRange();
CopiedTxt.execCommand("Paste");
Source:
http://www.geekpedia.com/tutorial126_Clipboard-cut-copy-and-paste-with-JavaScript.html
NOTE: This only works in IE (which is fine for your application).
I know its not bulletproof by any means, but here is a code sample that should get you started:
<html>
<head>
<script type = "text/javascript">
var lastForm = null;
window.onload = function(){
var menu = document.getElementById("ContextMenu");
var cpy = document.getElementById("CopyBtn");
var pst = document.getElementById("PasteBtn");
document.body.onmouseup = function(){
if (event.button == 2)
{
menu.style.left = event.clientX + "px";
menu.style.top = event.clientY + "px";
menu.style.display = "block";
return true;
}
menu.style.display = "none";
};
cpy.onclick = function(){
copy = document.selection.createRange();
copy.execCommand("Copy");
return false;
};
pst.onclick = function(){
if (lastForm)
{
copy = lastForm.createTextRange();
copy.execCommand("Paste");
}
return false;
};
};
</script>
</head>
<body oncontextmenu = "return false;">
<div id = "ContextMenu" style = "display : none; background: #fff; border: 1px solid #aaa; position: absolute;
width : 75px;">
Copy
Paste
</div>
sadgjghdskjghksghkds
<input type = "text" onfocus = "lastForm = this;" />
</body>
</html>
//Start:
function cutomizedcontextmenu(e)
{
var target = window.event ? window.event.srcElement : e ? e.target : null;
if( navigator.userAgent.toLowerCase().indexOf("msie") != -1 )
{
if (target.type != "text" && target.type != "textarea" && target.type != "password")
{
alert(message);
return false;
}
return true;
}
else if( navigator.product == "Gecko" )
{
alert(message);
return false;
}
}
document.oncontextmenu = cutomizedcontextmenu;
//End:
I hope this will help you Anderson Imes
A quick look at the MSDN documentation shows that none of the mouse events (click, button down/up etc) are supported to be used in your program. I'm afraid its either or: Either disable conetxt menus, or allow them.
If you disable them, the user can still copy & paste using keyboard shortcuts (Ctrl-C, Ctrl-V). Maybe that gives you the functionality you need.
We ended up using a combination of both of the above comments. Closer to the second, which is why I gave him credit.
There is a way to replace the context menu on both the client-side web code as well as through winforms, which is the approach we took. I really didn't want to rewrite the context menu, but this seems to have given us the right mix of control.

Resources