nicEdit cant load - nicedit

When i init nicEdit with this script :
script 1
<script type="text/javascript">
bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
My textarea still default , and then i add this script:
script 2
$(document).ready(function() {
nicEditors.allTextAreas();
It's work but what the function of the first script ?
bcause while i just used the second script its work
this is my problem :D
After i'm success init nicEdit , i create new textarea again in new div (i write again script 1 and 2) and then firebug speak " A.removeInstance is not a function "
help me Master
I'm just newbie

In niceEdit.js replace the checkReplace function with the following:
checkReplace : function(e) {
var r;
var editors = nicEditors.editors;
for(var i=0;i<editors.length;i++) {
if(editors[i].instanceById(e)) {
r = editors[i]; // r is an instance of nicEditorInstance therefore it does not have removeInstance or removePanel methods
break;
}
}
if(r) {
r.removeInstance(e);
r.removePanel();
}
return e;
}

Try the newer version from https://github.com/danishkhan/NicEdit/downloads - it's from September 2010. The version from his website is created on April.
On his github-website you can see a comment on the top: "fixed removeInstance bug: r is an instance of nicEditorInstance( or nicE"
Maybe this will help you - I lost the whole morning by fixing an already fixed bug, because I didn't know this =)

Related

Interacting with HTML Page - Firefox: Content Not Defined

I have a script here, which is extracting the links within a web page. It is comming back with the error 'content is not defined'.
// extract the links
var links = new Array();
for (i = 0; i < content.document.links.length; i++) {
var thisLink = content.document.links[i].toString();
//links.push(content.document.links[i].toString());
console.log(thisLink);
}
In order to interact with the HTML documents within the Firefox SDK, do I need to import a library?
It depends on when the self executing anonymous function is running. It is possible that it is running before window.document is defined.
In that case, try adding a listener
window.addEventListener('load', yourFunction, false);
// ..... or
window.addEventListener('DOMContentLoaded', yourFunction, false);
yourFunction () {
// some ocde
}

Getting information about Uploaded files

I am trying to write an addon for Firefox which displays the current percentage of a file being uploaded to a website (similar to how chrome does it). The problem I am having is that I have never worked with Addons for Firefox so I'm a little confused.
I have looked at the source of this Addon which was released in 2011, and this developer is referencing the following files:
Components.utils.import("resource://gre/modules/DownloadUtils.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/PluralForm.jsm");
Another interesting piece of code I found when going through the source was:
Components.classes["#mozilla.org/network/http-activity-distributor;1"],
I've done a little research on these modules/classes, but I was wondering if in the last ~4 years there has been a change in the technology, and Firefox has made it a little easier to get file upload information.
I know from my experience in web development that you can use XMLHttpRequest() and addEventListener("progress", <function>, false); but is that possible with Firefox Addons? And would it work with any file uploaded to a site?
I'm pretty lost as you can see, any help would be greatly appreciated. Thank you so much!!
Actually it looks like all the code you need is right in that addon, i took this from that addon you posted from here: https://addons.mozilla.org/en-US/firefox/files/browse/125019/file/components/uploads.js#top
init: function() {
//dump(">>>>>>>>>>>>>>>>>>>>>> INITIALIZED\n");
// add observer
var hao = Ci.nsIHttpActivityObserver;
var _self = this;
this.observer = {
observeActivity: function(aHttpChannel, aActivityType,
aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData) {
if ((aActivityType == hao.ACTIVITY_TYPE_SOCKET_TRANSPORT) &&
(aActivitySubtype == 0x804b0005)) { // STATUS_SENDING_TO
//dump("UPDATE STATUS: ["+aTimestamp+"] *" + aHttpChannel + "*\n");
_self.updateStatus(aHttpChannel, aTimestamp, aExtraSizeData);
}
if (aActivityType == hao.ACTIVITY_TYPE_HTTP_TRANSACTION) {
switch (aActivitySubtype) {
//case hao.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
case hao.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE:
//dump("REMOVE: *" + aHttpChannel + "*\n");
_self.removeUpload(aHttpChannel);
break;
case hao.ACTIVITY_SUBTYPE_REQUEST_HEADER:
//dump("CREATE: *" + aHttpChannel + "*\n");
_self.createUpload(aHttpChannel);
break;
}
}
}
};
Cc["#mozilla.org/network/http-activity-distributor;1"]
.getService(Ci.nsIHttpActivityDistributor)
.addObserver(this.observer);
},
shutdown: function() {
Cc["#mozilla.org/network/http-activity-distributor;1"]
.getService(Ci.nsIHttpActivityDistributor)
.removeObserver(this.observer);
},

Ionic Prepopulated Database with Antair Cordova SQLitePlugin [help request]

____ INTRO
Hello everyone, first of all, three clarifications:
My english is not good, so I beg your pardon in advance for my mistakes,
I'm a newbie so forgive me for inaccuracies,
I have previously searched and tried the solutions I found on the internet but still I can not solve the problem of embedding a prepopulated database.
____ THE GOAL
I want to develop an app for iOS and Android with a prepopulated database.
Just for example, the database consists of 15.000 records each one made of three key-value pair (id, firstname and lastname).
___ WHAT I DID
Steps:
ionic start myapp blank
cd myapp
ionic platform add ios
ionic platform add android
Then I created an sqlite database for testing purpose, named mydb.sqlite, made of one table people containing two id, firstname, lastname records.
I decided to use the following plugin: https://github.com/Antair/Cordova-SQLitePlugin
That's because it can be installed with cordova tool.
ionic plugin add https://github.com/Antair/Cordova-SQLitePlugin
(Alert: I think that the instructions on the website show an incorrect reference - "cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin" - which refers to another plugin).
Then, following the instructions on the plugin website, I copied the database to myapp/www/db/ so that it can now be found at myapp/www/db/mydb.sqlite
I modified the index.html including the SQLite plugin just after the default app.js script:
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="SQLitePlugin.js"></script>
I also write some lines of code in index.html file to show a button:
<ion-content ng-controller="MyCtrl">
<button class="button" ng-click="all()">All</button>
</ion-content>
Finally I had modified ./js/app.js:
// Ionic Starter App
var db = null;
angular.module('starter', ['ionic' /* What goes here? */ ])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// some predefined code has been omitted
window.sqlitePlugin.importPrepopulatedDatabase({file: "mydb.sqlite", "importIfExists": true});
db = window.sqlitePlugin.openDatabase({name: "mydb.sqlite"});
}); // $ionicPlatform.ready
}) // .run
.controller('MyCtrl', function($scope){
$scope.all = function(){
var query = "SELECT * FROM people";
// I don't know how to proceed
}; // $scope.all
}); // .controller
___ THE PROBLEM
I don't know how to proceed in the controller section to query all the records (just an example of query) and show the results in the console.log.
I think that the following code must be completed in some way:
angular.module('starter', ['ionic' /* What goes here? */ ])
And also the code inside controller section must be completed:
$scope.all = function(){
var query = "SELECT * FROM people";
// I don't know how to proceed
}; // $scope.all
___ FINAL THANKS
Thank you in advance for the help you will give to me.
So this guy's code has helped a lot to encapsulate my DAL. I highly recommend that you use he's code pretty much verbatim.
https://gist.github.com/jgoux/10738978
You'll see he has the following method:
self.query = function(query, bindings) {
bindings = typeof bindings !== 'undefined' ? bindings : [];
var deferred = $q.defer();
self.db.transaction(function(transaction) {
transaction.executeSql(query, bindings, function(transaction, result) {
deferred.resolve(result);
}, function(transaction, error) {
deferred.reject(error);
});
});
return deferred.promise;
};
Let's break this down a bit. The query function takes a query string (the query param) and a list of possible bindings for ? in a query like "SELECT * FROM A_TABLE WHERE ID = ?". Because he's code is a service, the self value points to the service itself for all future invocations. The function will execute a transaction against the db, but it returns a promise that is only fulfilled once the db comes back.
His service provides a second helper function: fetchAll.
self.fetchAll = function(result) {
var output = [];
for (var i = 0; i < result.rows.length; i++) {
output.push(result.rows.item(i));
}
return output;
};
fetchAll will read the rows in their entirety into an array. The result param for fetchAll is the result variable passed in the query function's promise fulfillment.
If you copy and paste his code into your service file, you now have a bonafide DB service. You can wrap that service up in a DAL. Here's an example from my project.
.service('LocationService', function ($q, DB, Util) {
'use strict';
var self = this;
self.locations = [];
self.loadLocked = false;
self.pending = [];
self.findLocations = function () {
var d = $q.defer();
if (self.locations.length > 0) {
d.resolve(self.locations);
}
else if (self.locations.length === 0 && !self.loadLocked) {
self.loadLocked = true;
DB.query("SELECT * FROM locations WHERE kind = 'active'")
.then(function (resultSet) {
var locations = DB.fetchAll(resultSet);
self.locations.
push.apply(self.locations, locations);
self.loadLocked = false;
d.resolve(self.locations);
self.pending.forEach(function (d) {
d.resolve(self.locations);
});
}, Util.handleError);
} else {
self.pending.push(d);
}
return d.promise;
};
})
This example is a bit noisy since it has some "threading" code to make sure if the same promise is fired twice it only runs against the DB once. The general poin is to show that the DB.query returns a promise. The "then" following the query method uses the DB service to fetchAll the data and add it into my local memory space. All of this is coordinated by the self.findLocations returning the variable d.promise.
Yours would behalf similarly. The controller could have your DAL service, like my LocationService, injected into it by AngularJS. If you're using the AngularJS UI, you can have it resolve the data and pass it into the list.
Finally, the only issue I have with the guy's code is that the db should come from this code.
var dbMaker = ($window.sqlitePlugin || $window);
The reason for this is that the plugin does not work within Apache Ripple. Since the plugin does a fine job mirroring the Web SQL interface of the browser, this simple little change will enable Ripple to run your Ionic Apps while still allowing you to work your SQLite in a real device.
I hope this helps.

jquery triggering not working in firefox extension

Steps to reproduce:
i created a hai.html and using pagemod i injected scripts into that, here is the code and that hai.html https://github.com/suneeshtr/trigger-test.git
Actual results:
injection of scripts and everything works fine except triggering. when i tried to append a file it works..
here is a part of code:
alert("content");
$(document).ready(function() {
var values = [{val:'santiagotactivos', meta:'Santiago Montero'},
{val:'johnnyhalife', meta:'Johnny Halife'},
{val:'arielflesler', meta:'Ariel Flesler'},
{val:'rbajales', meta:'Raul Bajales'}];
var customItemTemplate = "<div><span /> <small /></div>";
function elementFactory(element, e) {
var template = $(customItemTemplate).find('span')
.text('#' + e.val).end()
.find('small')
.text("(" + e.meta + ")").end();
element.append(template);
};
alert(JSON.stringify($("textarea")));
// here is how we use it
$('textarea').sew({values: values, elementFactory: elementFactory});
});
your question is not clear you can try this example
var src = [{val:'santiagotactivos', meta:'Santiago Montero'},
{val:'johnnyhalife', meta:'Johnny Halife'},
{val:'arielflesler', meta:'Ariel Flesler'},
{val:'rbajales', meta:'Raul Bajales'}];
$("#auto").autocomplete({
source:src
});
try this one too:
http://www.hawkee.com/snippet/9391/
$('#inputbox').triggeredAutocomplete({
hidden: '#hidden_inputbox',
source: "/search.php",
trigger: "#"
});

Why JQueryUI does not work on salesforce standard input elements?

I am having trouble using JQueryUI with salesforce standard elements. Basically, I want to auto suggest the record names to the user, instead of the user clicking on the salesforce search button.
<apex:inputField value="{!MyRecord.ChildRecord__c}" id="inpId" required="true/>
<script>
jq$(document.getElementById('{!$Component.inpId}')).autocomplete( {
minLength: 2,
autoFocus: true,
source: mySource
});
</script>
Therefore, I want to know if anyone attempted to use JQueryUI with standard salesforce input elements. In my case, the JQueryUI events are not firing for salesforce elements.
{!$Component.[elementid]} doesn't always work for me; I'm not sure why. I prefer to use the Attribute Ends With Selector (http://api.jquery.com/attribute-ends-with-selector/).
Try something like this:
<apex:includeScript value="/soap/ajax/18.0/connection.js" />
<apex:includeScript value="/soap/ajax/18.0/apex.js" />
<script>
var j$ = jQuery.noConflict();
j$(document).ready(function(){init();});
function init()
{
var mySourceText = "ActionScript AppleScript Asp BASIC C "
+ "C++ Clojure COBOL ColdFusion Erlang Fortran Groovy "
+ "Haskell Java JavaScript Lisp Perl PHP Python Ruby "
+ "Scala Scheme";
var mySource = mySourceText.split(" ");
j$("[id$='myInput']").autocomplete({
minLength: 2,
autoFocus: true,
source: function(request, response){
response(GetSourceAjaxAPI(request.term)); }
});
}
function GetSourceAjaxAPI(s)
{
var result = sforce.apex.execute("TestAutocomplete",
"GetAutocompleteValuesAjaxAPI", {SearchTerm:s});
return result;
}
</script>
<apex:form >
<apex:pageblock >
<apex:pageblocksection >
<apex:pageblocksectionitem >
<apex:inputfield id="myInput" value="{!Contact.FirstName}" />
</apex:pageblocksectionitem>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
Controller:
global class TestAutocomplete
{
global TestAutocomplete(ApexPages.StandardController myStandardController) {}
webservice static List<String>
GetAutocompleteValuesAjaxAPI(String SearchTerm)
{
String mySourceText = 'ActionScript AppleScript Asp BASIC C '
+ 'C++ Clojure COBOL ColdFusion Erlang Fortran Groovy '
+ 'Haskell Java JavaScript Lisp Perl PHP Python Ruby '
+ 'Scala Scheme';
List<String> mySourceList = mySourceText.split(' ');
List<String> myReturnList = new List<String>();
for(String s : mySourceList)
{
if(s.contains(SearchTerm)){ myReturnList.add(s); }
}
return myReturnList;
}
}
Hope that helps,
Matt
I figured out the reason why JQeuryUI was not working on SalesForce standard input element. I was trying to use JQueryUI autocomplete on the input element. The action function that was supposed to be invoked was not called because I did not have
<apex:actionFunction immediate="true" />
That is we must have immediate=true attribute set so that action function is called immediately. If we do not have this attribute set, SalesForce tries to validate all the standard input elements and if the validation fails, action function is never called.

Resources