ajaxboy / cjax

Lightweight Ajax Framework built in PHP with no foot-print. Allows you to build ajax functionality with a single line of code & do so much more, right from the back-end!
http://cjax.sourceforge.net/
66 stars 27 forks source link

Developing CJAX 6.0 #19

Open HallofFamer opened 8 years ago

HallofFamer commented 8 years ago

I am actually developing a new branch/version of CJAX myself right now, since I want to introduce some changes to the script, add more features and modernize it to be compatible with later versions of PHP without having to turn off strict standard errors and etc. Is it allowed for me to share the file changes once I finish it? Or can I make a pull request after it is done? Can I call it CJAX 6.0 then?

ajaxboy commented 8 years ago

Yes, it is allowed

ajaxboy commented 8 years ago

I will have to review any changes, and audit the code before it can be merged.

HallofFamer commented 8 years ago

Sure, I understand. It will be very different though, but I will make sure I test it extensively before making a pull request. Or perhaps, we can just move the current CJAX master branch to a sub branch called CJAX 5.8, and make the new master branch to be CJAX 6.0? I know many github repositories keep different branches, and you have CJAX 5.5 and 5.6 branches already.

Anyway these are the changes I am working on:

  1. Rewrite the core PHP to match modern standard(ie. namespace usage, use of class autoloader, no static call to instance methods, etc).
  2. Allow PHP to acquire information of Javascript event, this is done by storing a json event object to cookie and have PHP read it once AJAX request is made. It will be useful for mouse events and future drag/drop event.
  3. Add support for Mouse Events and maybe Drag/Drop events. I will also update examples for each newly added events.
  4. Add docblock comments to PHPDocumentor standard, and generate documentation for the API used by CJAX. This will make it easier for advanced developers to dig into the core of CJAX.
ajaxboy commented 8 years ago
  1. I have tried to keep it simple and compact, if you follow that pattern it would be great, that is the only reason I haven't use namespaces. Namespaces are for big applications with chances of conflicting names in this case, I dont think it is needed, but I am open to see what you come up with. Cjax i is meant to be lightweight and that is one of the things I take pride on, rather see it lightweight and slim than thick and over complicated, The plugin system itself is pretty powerful although a little complex is does allow for alot complex customizations, give it a go and I will make a thoroughly audit of the code and make a decision on it or give you feedback.
  2. Cjax already does that, you pass php objects or arrays and they are easily and almost automatically converted into json objects or xml array (supports both), which are passed to the engine for processing, and also allows for js plugins, which can process these data (json/xml) to create customization. A cjax plugin can consist of a php class, which inherits the power of cjax itself, and a javascrpt file, which also inherits the power of Javascript engine, and they both automatically interact with each other, it is very a flexibly system
  3. That would be nice to see, you might be able to accomplish this with a cjax plugin
  4. That would be nice to see as well
HallofFamer commented 8 years ago

I see, I understand. I wont change the lightweight nature of CJAX, I will mostly fix issues such as strict standard errors on PHP 5.4, 5.5 and 5.6. I will use namespace too since its the current PHP standard, and I will let you see how it will turn out to be.

For feature 2, I think you misunderstand me. I was talking about sending javascript's event object to PHP via cookie, rather than a get/post request(since a get request has character length limit, post request isnt appropriate here). I use document.cookie javascript code to set a cookie that stores a serialized event object, and this event object will be unserialized in PHP when an ajax call is made. PHP will then create an instance of event class, and send it to controller for processing.

This will make it possible for PHP to access javascript event object, and it is powerful because for some events you need the javascript event properties. Take mouse event for example, you may want to use properties such as number of clicks, button pressed(left, middle or right clicks), x/y coordinate of the mouse cursor. Without event objects, this can be very difficult to achieve. Now it's a lot easier to do with what I've come out with.

If it still confuses you, I will show you by an example how the cookie-set javascript event object will be useful to send an entire javascript event object to PHP.

HallofFamer commented 8 years ago

Update: CJAX 6.0 is close to beta already, I have successfully added mouse and drag and drop events. I added an autoloader so there will be no need to manually require/include files anymore. CJAX 6.0 will not need you to disable strict standard errors, while PHP version requirement has been bumped to PHP 5.4+. I also upgraded third party libraries for CJAX, such as JQuery(now 2.2.2), Sizzle(now 2.3.1), JQuery Validation(now 1.15.0).

You can see how CJAX 6.0 works in action by visiting the following example pages: Mouse cursor/pointer: http://mysidiarpg.com/site/cjax/cjax600a3/examples/mousepointer.php Drag and Drop Items: http://mysidiarpg.com/site/cjax/cjax600a3/examples/dragdropmultiple.php ImageMap(Mouse Event): http://mysidiarpg.com/site/cjax/cjax600a3/examples/imagemap.php Captcha(Drag/Drop Event): http://mysidiarpg.com/site/cjax/cjax600a3/examples/captcha.php

Before CJAX 6.0 Beta 1 is available, I plan to further refactor the core PHP files for CJAX to make it more professional and clean(such as splitting long methods, and get rid of static methods). I am also considering adding one more example, and maybe even adding a new plugin for Dragula: http://bevacqua.github.io/dragula/

Thoughts?

mcascardi commented 8 years ago

I just want to say hi, and thank you for picking up development. I'm using CJAX in a prototype/beta web app. These UI features could be an interesting addition for us to use.

HallofFamer commented 8 years ago

@mcascardi You are very welcome, I am developing CJAX for my own personal reason too. I plan to add more and more features to it in future. You can help out by giving me your suggestions on what else you want CJAX to have. They have a chance to appear in CJAX 6.0 if your proposals are made prior to it going beta(a few days later), or there's always a chance it makes to CJAX 6.1 or future releases even if its too late for next version.

If you are interested, you may follow this fork I created for CJAX. The branch CJAX 6.0 Beta 1 is available and source files can be viewed. Note the beta is not ready yet and its still subject to changes, I will push it to master branch once CJAX 6.0 goes beta. https://github.com/HallofFamer/cjax/tree/Cjax-6.0-Beta-1

ajaxboy commented 8 years ago

@HallofFamer Thank You, good job.

For the mouse drag and drop one particularly I would most likely make it into a plugin, since the syntax requires multiple lines of code, I can probably do that myself if you are not up to it. Since the last release, plugins are automatically included in released package so there would be no noticeable difference when released. Another thing is that plugins automatically auto-loaded when used, also means that, the code would not be loaded if not needed otherwise. The idea is to keep the main code as lean as possible, while integrating really cool functionality in plugins format so that it encourages more changes and development without modifying the core

The documentation and options would have to look in this format:
http://mysidiarpg.com/site/cjax/cjax600a3/examples/plugin_uploader.php

Other than that, It looks so far so good

ajaxboy commented 8 years ago

In the other hand though, i can see how this could possibly become part of the core, we may leave this in, and in the future turn it into a plugin if needed, but I don't see why try as it is for now. This is actually how the upload plugin started, it was first part of the core before it became a plugin.

HallofFamer commented 8 years ago

@ajaxboy Thanks for your comment, glad you like it so far. Yeah the drag and drop API may as well be a plugin than part of the core. The reason why I add it to the core is that, in future I plan to add some plugins for jquery drag and drop, such as the dragula plugin mentioned earlier. In this case, it makes sense that we provide core API of drag/drop, while jquery libraries such as dragula will appear as plugins.

It can go either way of course, it will eventually come down to the performance impact resulted from adding drag/drop to the core. If it slows down CJAX considerably, I will remove it from the core and make it a plugin instead. What do you think? Plz lemme know if you have further comments and recommendations, I'd appreciate feedback very much.

HallofFamer commented 8 years ago

@ajaxboy

CJAX 6.0 Beta 1 is available now, and I wonder if you can add it to a branch on your own CJAX fork? What you will need is to create a branch for CJAX 6.0 Beta 1, and then I will make a pull request to that branch. There is no need to push it to master yet, at least until CJAX 6.0 is out of beta(working on Beta 2 right now).

ajaxboy commented 8 years ago

@HallofFamer have messenger or hangouts? We can discuss further release/deploy info on there.

HallofFamer commented 8 years ago

Sure I have it, I use AIM TheHOFamer, and my skype ID is mrhalloffamer.

HallofFamer commented 8 years ago

CJAX 6.0 Beta 2 is available now. It has several changes to the internal API(core API on CJAX class remains untouched). As you requested, I didnt remove ajax(), although it is not used in the internal API. CJAX 6.0 Beta 2 can be found within my own fork of CJAX:

https://github.com/HallofFamer/cjax/tree/Cjax-6.0-Beta-2

There also is an API documentation available on my demo site for CJAX development:

http://mysidiarpg.com/site/cjax/cjax600b2/api/

oniwo commented 8 years ago

The controllers in Beta 1 release of version 6.0 can not inherit the CI_Controller class of CodeIgniter.

I am developing an application using version 5.8, and this is possible there. In the process, I can therefore load models and libraries and reuse the code in them.

HallofFamer commented 8 years ago

Well CJAX by itself has nothing to do with CodeIgniter, so I think you may be talking about the wrong thing here. CJ has not made a CodeIgniter bridge/integration for CJAX 6.0 with CodeIngiter either, but its doable.

ajaxboy commented 8 years ago

I would probably go with a wrapper here... say - make Cjax work the same as before, but still be able to use namespaces and everything, if used a wrapper to access all the functions and properties. To me personally backward compatibility is a big thing, and is more important than other things, and it is kind of the point of many things, we do want Cjax to work for everyone that has worked for before without altering the work environment, that should be wrapper, to is not just a good principle to go by, but also responsible, that is the reason I wanted to keep ajax(); function callable. note that alot of the people that use Cjax also use CI, so this is really a big thing

HallofFamer commented 8 years ago

Its not a very hard issue anyway, all you need is to change AJAXController class into AJAXController trait, and then your CI controller classes will be able to use a trait rather than inherit from a superclass. This way your CI Controller can still extend from CI Base controller, and you get all the benefits from the new AJAXController class from CJAX 6 too.

So instead of defining your CJAX 6 controllers like the new documentation suggests:

class MyAJAXController extends AJAXController{

}

You will write it this way with a use statement for trait:

class MyAJAXController extends CI_Controller{
    use AJAXController;
}

If you are unfamiliar with traits, read this from PHP manual. Its a very powerful feature, and we may use it in CJAX 6.x future development too, now that CJAX 6 requires PHP 5.4+. http://php.net/manual/en/language.oop5.traits.php

HallofFamer commented 8 years ago

@ajaxboy Can you push CJAX 6.0 beta 2 to a branch on this repository too(like you did with CJAX 6.0 beta 1)? I think its better for users to download this updated version, rather than CJAX 6.0 beta 1. I am working on CJAX 6.0 beta 3 now, and after that it will be stable release of CJAX 6.0.

hycday commented 7 years ago

@HallofFamer how is this going on :) ? it's an amazing work you did here. I was exactly looking for such improvements and was wondering when would a stable release of CJAX 6.0 be approximatly (and/or if the beta 3 could be used in prod) ? btw, can you please open the "issues" in your repository ? I am getting an alert box with the message #process unabled to load function#1: _fn(); CJAX.lib.isFN is not a function

HallofFamer commented 7 years ago

@hycday

Hello there, I appreciate your interests and kind words regarding the new CJAX project. The fact is that CJAX was designed to be a framework by itself. To integrate it with existing frameworks such as Symfony, Zend and CodeIgniter, you need to write quite a bit of code to achieve that.

In CJAX 6.0 Beta 3 and future versions I plan to turn it into a library that you can include in composer and add to existing frameworks with ease. It turns out to be much more challenging than I originally thought, and adding on the fact that I've been very busy lately, I have not been able to achieve this.

The error you got was a typo from the old CJAX. To fix this, simply go to the cjax-6.0.js/cjax-6.0.min.js files, find by keyword 'isFN' and change it to 'isFn', and it will work normally again.