The Microsoft developers are not really good, and we can see it if you use IE8 in standard mode with Sharepoint 2010: the web parts don’t work anymore due to an error with the wpadder.js file.
After few hours trying to find the problem I’ve finally discovered that the WPAdder class uses the for..in
statement without testing the hasOwnProperty
(more about that problem), then it causes some issues…
Here is how I fixed it (this code must be added after the DOM is loaded in the master page to be called by all the pages) :
EnsureScript("WPAdderClass", undefined, function() { if (typeof loadWPAdderCallback === "function") { var _loadWPAdderCallback=loadWPAdderCallback; loadWPAdderCallback = function() { _WPAdder.prototype._layout = function (a) { ULSior: ; var l = this._saveDescriptionForLayout(); if (this._lastLayoutWidth == -1) { var g = this._getCategoryContainer(); for (var b in this._cats) { if (this._cats.hasOwnProperty(b)) g.appendChild(this._cats[b].el) } } if (this._table.clientHeight != this._lastLayoutHeight) { this._selCat != -1 && this._removeItemHover(); this._layoutCategoryColumn(); this._getNavigationTable().parentNode.colSpan = 1; var d = 0, f = 0, c = document.createElement("DIV"), g = this._itemContainerTemplate.cloneNode(true); c.style.whiteSpace = "nowrap"; c.style.width = "1px"; c.style.height = "1px"; c.style.overflow = "auto"; c.innerHTML = "Quick Brown Fox!
It jumped!"; this._getFirstChild(g).appendChild(c); this._getItemContainer().appendChild(g); var j = c.scrollWidth, i = c.scrollHeight; this._removeElement(g); if (a && (parseInt(a[0][0]) != j || parseInt(a[0][1]) != i || parseInt(a[0][2]) != this._table.clientHeight)) a = null; if (a) { d = parseInt(a[0][3]); for (var b = 0; b < this._cats.length; b++) { if (this._cats.hasOwnProperty(b)) { var e = this._fillCachedItems(this._cats[b].items, this._itemContainerTemplate, a[b + 1]); if (e.length > f) f = e.length; this._cats[b].itemCols = e } } } else { a = ""; for (var b in this._cats) { if (this._cats.hasOwnProperty(b)) { var e = [], h = this._fillItems(e, this._cats[b].items, this._getItemContainer(), this._itemContainerTemplate, _WPAdder_maximumItemWidth); if (h[1] > d) d = h[1]; if (e.length > f) f = e.length; this._cats[b].itemCols = e; a += ";" + h[0] } } a = j + "," + i + "," + this._table.clientHeight + "," + d + a; this._getHiddenField("layout").value = this._layoutHash + ";" + a } for (var b in this._cats) { if (this._cats.hasOwnProperty(b)) { var k = this._cats[b].itemCols; for (var m in k) { if (k.hasOwnProperty(m)) this._finishColumn(k[m], d) } } } for (var b in this._dummyCols) { if (this._dummyCols.hasOwnProperty(b)) this._finishColumn(this._dummyCols[b], d); } this._maxCols = f; this._widestColumn = d }(this._table.clientWidth != this._lastLayoutWidth || this._table.clientHeight != this._lastLayoutHeight) && this._calculateVisibleItemColumns(); this._restoreDescriptionAndLayout(l); this._lastLayoutWidth = this._table.clientWidth; this._lastLayoutHeight = this._table.clientHeight }; _WPAdder.prototype._removeItemHover = function () { ULSior: ; var a = this._getItems(); for (var b in a) { if (a.hasOwnProperty(b)) a[b].removeHover() } }; _loadWPAdderCallback(); } } })
Actually, when we load the WPAdder class, then I override the two functions that are buggy in adding the hasOwnProperty
. That’s it.
I have looked at a lot of solutions to the wpadder.js problem, and yours, by far, seems to be the best.
Currently, I am trying to implement a solution similarly for this wpadder.js issue:
Uncaught TypeError: Cannot call method ‘add’ of undefined
Many other solutions call for the use of edit panels, which is not so elegant when you are using scripts that affect the layout like jQuery Mobile.
Do you see any way to utilize a solution like yours to « fix » Sharepoint’s poor coding in my current wpadder.js situation?
What sort of solution have you worked on to address this?
Again, very clever! Thank you for your help in advance!
Hi mistafi. Sorry for the delay on reply but I was on vacation 🙂
To find the problem with wpadder.js I’ve had to find where the error was raised (with the developer toolbar of IE you can find which part of the code raised the error) then I search the full code in the original file and I overwrite it trying to find where the problem is (with the alert javascript function) and I go up thru the parent functions until I found where the problem really is. It’s not easy, and it’s a very long process…
When I’m lucky the problem appears also with Firefox and I can use Firebug to quickly find the root and fix it !